37 lines
942 B
Python
Executable File
37 lines
942 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
EXPECTED = [
|
|
0xF4, 0xC0, 0x97, 0xF0, 0x77, 0x97, 0xC0, 0xE4,
|
|
0xF0, 0x77, 0xA4, 0xD0, 0xC5, 0x77, 0xF4, 0x86,
|
|
0xD0, 0xA5, 0x45, 0x96, 0x27, 0xB5, 0x77, 0xC1,
|
|
0xC0, 0x95, 0x94, 0x94, 0xC1, 0xD1, 0xE1, 0xF1,
|
|
]
|
|
|
|
def switch_bits(c: int, p1: int, p2: int) -> int:
|
|
bits = list(bin(c)[2:].rjust(8, '0'))
|
|
bits[p1], bits[p2] = bits[p2], bits[p1]
|
|
return int(''.join(bits), 2)
|
|
|
|
def unscramble_char(c: int) -> int:
|
|
c = switch_bits(c, 7, 6)
|
|
c = switch_bits(c, 5, 2)
|
|
c = switch_bits(c, 4, 3)
|
|
c = switch_bits(c, 1, 0)
|
|
c = switch_bits(c, 7, 4)
|
|
c = switch_bits(c, 6, 5)
|
|
c = switch_bits(c, 3, 0)
|
|
c = switch_bits(c, 2, 1)
|
|
return c
|
|
|
|
def unscramble(xs: list[int]) -> str:
|
|
return ''.join(chr(unscramble_char(x)) for x in xs)
|
|
|
|
def main():
|
|
print('picoCTF{', end='')
|
|
print(unscramble(EXPECTED), end='')
|
|
print('}')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|