def bruteForce( dictionary = {}):
key = 0
for i in range(len(dictionary)):
keyRank = 0
for k in range(68719476736):
attempt = decrypt(dictionary[i], k)
if(i != attempt):
keyRank = 0
break
else:
keyRank += 1
key = k
print 'key attempt: {0:b}'.format(key)
if(keyRank == len(dictionary)):
print 'found key: {0:b}'.format(key)
break
- The key is 36 bits
- I get a memory error on the
for k in range()
line of code
- Why is this a memory issue? Does python build an actual list of ints before running this line? Is there a better way to write this loop?
- I'm brand new to Python and this wouldn't be a problem in C or Java.
- This is a known-plaintext/ciphertext attack. dictionary is a mapping of P:C pairs.
- Its on a VM, I can up the memory if needed, but want to know both why its failing and a code-based workaround or better idiomatic approach.