from Crypto.Cipher import AES import random MIN_CIPHER = 1000000000000000 MAX_CIPHER = 1000000000010000 PLAIN_TEXT = 'test some plain text here'.rjust(32) ### encrypt ### def generate_ciphers(ciphers_len): return [str(random.randint(MIN_CIPHER, MAX_CIPHER)) for i in range(ciphers_len)] def encrypt(ciphers_len=100,plain_text=PLAIN_TEXT): ciphers = generate_ciphers(ciphers_len) hashes = [] msg = plain_text hashes.append(hash(msg)) for i in ciphers: cipher = AES.new(i,AES.MODE_ECB) msg = cipher.encrypt(msg) # encrypt the msg hashes.append(hash(msg)) # save the hash of the msg return msg, hashes # TODO: write to file for backup def get_bruteforce_rate(): ''' return decryptions per second on average, for tuning encryption's parameters ''' pass ### decrypt ### def decrypt(encrypted_msg,hashes): msg = encrypted_msg for i in hashes[::-1]: # iterates over hashes, reversed since the last hash should be decrypted first j=MIN_CIPHER while j