PHASESTREAM
AUTHOR: HYPERREALITY
The aliens are trying to build a secure cipher to encrypt all our games called “PhaseStream”. They’ve heard that stream ciphers are pretty good.
The aliens have learned of the XOR operation which is used to encrypt a plaintext with a key. They believe that XOR using a repeated 5-byte key is enough to build a strong stream cipher. Such silly aliens!
Here’s a flag they encrypted this way earlier. Can you decrypt it (hint: what’s the flag format?)
2e313f2702184c5a0b1e321205550e03261b094d5c171f56011904
Решение
И так, нам нужно расшифровать текст. По сути задание очень напоминает вот эту лабу. Только нужно найти не один бит ключа, а 5.
Нам известна длина ключа, так же нам известна часть открытого текста CHTB{. Используем ее, чтобы найти ключа. После чего расшифруем всю фразу.
Для удобства я буду писать код на Python:
def get_key(b: bytes) -> list[int]:
plaintext = 'CHTB{'
key = [ord(plaintext[i]) ^ b[i] for i in range(len(plaintext))]
return key
if __name__ == '__main__':
encoded = '2e313f2702184c5a0b1e321205550e03261b094d5c171f56011904'
raw = bytes.fromhex(encoded)
key = get_key(raw)
plaintext = []
for pos, byte in enumerate(raw):
plaintext.append(chr(byte ^ key[pos % len(key)]))
print(''.join(plaintext))
Вот полученный текст:
CHTB{u51ng_kn0wn_pl41nt3xt}