ångstromCTF 2021: Follow the Currents

Follow the Currents

Category: Crypto

70 points

go with the flow… Source

Author: lamchcl

Source

import os
import zlib
def keystream():
	key = os.urandom(2)
	index = 0
	while 1:
		index+=1
		if index >= len(key):
			key += zlib.crc32(key).to_bytes(4,'big')
		yield key[index]
ciphertext = []
with open("plain","rb") as f:
	plain = f.read()
	assert b"actf{" in plain
	k = keystream()
	for i in plain:
		ciphertext.append(i ^ next(k))
with open("enc","wb") as g:
	g.write(bytes(ciphertext))

Solution

import zlib
def keystream(key):
    index = 0
    while 1:
        index+=1
        if index >= len(key):
            key += zlib.crc32(key).to_bytes(4,'big')
        yield key[index]

encrypted_flag = open("enc","rb").read()
for key in range(256*256):
    flag = ''
    k = keystream(key.to_bytes(2, 'big'))
    for i in encrypted_flag:
        flag += chr(i ^ next(k))
    if 'actf{' in flag:
        print('Flag: {}'.format(flag))

Output:

Flag: x''R@Åû/9çLÅÖ minutes left before the ctf starts so i have no idea what to put here other than the flag which is actf{low_entropy_keystream}
Flag: ˆ†‹ are like 30 minutes left before the ctf starts so i have no idea what to put here other than the flag which is actf{low_entropy_keystream}
Flag: uX€^ìà9çLÅÖ minutes left before the ctf starts so i have no idea what to put here other than the flag which is actf{low_entropy_keystream}
Flag: …ù"Ǖ	„—L like 30 minutes left before the ctf starts so i have no idea what to put here other than the flag which is actf{low_entropy_keystream}
Flag: there are like 30 minutes left before the ctf starts so i have no idea what to put here other than the flag which is actf{low_entropy_keystream}
Flag: „É@5®Åû/9çLÅÖ minutes left before the ctf starts so i have no idea what to put here other than the flag which is actf{low_entropy_keystream}
Flag: yE {	„—L like 30 minutes left before the ctf starts so i have no idea what to put here other than the flag which is actf{low_entropy_keystream}
Flag: ‰¶`ç°ìà9çLÅÖ minutes left before the ctf starts so i have no idea what to put here other than the flag which is actf{low_entropy_keystream}

Flag

actf{low_entropy_keystream}

Privacy Policy
luc © 2021