For the Matasano CryptoPals Challenges Set 1 Problem 8, which states:
In this file are a bunch of hex-encoded ciphertexts.
One of them has been encrypted with ECB.
Remember that the problem with ECB is that it is stateless and deterministic; the same 16 byte plaintext block will always produce the same 16 byte ciphertext.
I have written the following Python Code. Since I'm a programmer coming from C++ to Python, some of it might be reminiscent of that transfer. Can I be more Pythonic than the code I've written? Any more suggestions?
#! /usr/bin/env python from binascii import a2b_hex def is_ECB_encoded(data, block_size): block_count = len(data)/block_size for i in range(block_count): for j in range(i+1,block_count): if data[i*block_size:(i+1)*block_size] == data[j*block_size:(j+1)*block_size]: return True return False filename = '8.txt' for line in open(filename): line = line.strip() if is_ECB_encoded(a2b_hex(line), 16): print line