Created
July 26, 2018 23:15
-
-
Save eeddaann/a080c5212e67085fde690c8c36e12a86 to your computer and use it in GitHub Desktop.
Revisions
-
eeddaann created this gist
Jul 26, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ 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<MAX_CIPHER: cipher = AES.new(str(j),AES.MODE_ECB) candidate_msg = cipher.decrypt(msg) # try to decrypt if hash(candidate_msg) == i: # if we found the right hash we can continue to the next hash msg = candidate_msg # print "hash found!" break j+=1 return msg ### main ### encrypted_msg,hashes = encrypt() print decrypt(encrypted_msg,hashes)