withopen(filename, 'rb') as plaintext: raw = plaintext.read() print(len(raw)) withopen(filename + '.out', 'wb') as ciphertext: for l, r inzip(raw, itertools.cycle(key)): ciphertext.write( (l ^ ord(r)).to_bytes(1, byteorder='big') )
Let's xortool show us some probability:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ xortool encryptme.txt.out The most probable key lengths: 1: 8.2% 3: 11.0% 6: 10.0% 9: 21.0% 12: 7.7% 15: 6.9% 18: 13.7% 27: 9.4% 36: 6.8% 45: 5.3% Key-length can be 3*n Most possible char is needed to guess the key!
xortool tell us there is 21% chances of a 9 bytes length key. So let's try it:
1 2 3 4 5 6 7 8 9 10
$ xortool encryptme.txt.out -l 9 -o 200 possible key(s) of length 9: \x04EYS[\x06Q^T \x04EYS[CQ^T \x05DXRZ\x07P_U \x05DXRZBP_U \x06G[QY\x04S\\V ... Found 89 plaintexts with 95.0%+ printable characters See files filename-key.csv, filename-char_used-perc_printable.csv
$ xortool-xor -f encryptme.txt.out -s QUICKSAND RSA and DSA can fail catastrophically when used with malfunctioning random number generators, but the extent to which these problems arise in practice has never been comprehensively studied at Internet scale. We perform the largest ever network survey of TLS and SSH servers and present evidence that vulnerable keys are surprisingly widespread. We find that 0.75% of TLS certificates share keys due to insufficient entropy during key generation,
[...]
The output is 100% printable text, we have the good key, now I need to find the flag: