def runExaustiveSearch(plain_text, cipher_text): """ Run the exaustive search using the above keys """ max_cost = 0 presumed_keys = [] for key in keysFormation(): sdes_obj = main_sdes(plain_text, key[0], encrypt=True) cipher = sdes_obj.cipher_text cost = calculateCost(cipher, cipher_text) if cost > max_cost: presumed_keys = [key[0]] max_cost = cost elif cost == max_cost: presumed_keys.append(key[0]) return (presumed_keys, max_cost)
sdes_obj = main_sdes(plain_text, key[0], encrypt=True) cipher = sdes_obj.cipher_text cost = calculateCost(cipher, cipher_text) if cost > max_cost: presumed_keys = [key[0]] max_cost = cost elif cost == max_cost: presumed_keys.append(key[0]) return (presumed_keys, max_cost) if __name__ == "__main__": plain_text = '11001001' key = '1010101011' cipher_text = main_sdes(plain_text, key, True).cipher_text start = time.time() search, cost = runExaustiveSearch(plain_text, cipher_text) stop = time.time() total_time = stop - start print 'Cipher -> ', cipher_text print 'Time taken -> ', total_time print 'Key present in sol -> ', key in search print 'Presumed Cost -> ', cost print 'All matching keys -> ', search
for key in keysFormation(): sdes_obj = main_sdes(plain_text, key[0], encrypt=True) cipher = sdes_obj.cipher_text cost = calculateCost(cipher, cipher_text) if cost > max_cost: presumed_keys = [key[0]] max_cost = cost elif cost == max_cost: presumed_keys.append(key[0]) return (presumed_keys, max_cost) if __name__ == "__main__": plain_text = '11001001' key = '1010101011' cipher_text = main_sdes(plain_text, key, True).cipher_text start = time.time() search, cost = runExaustiveSearch(plain_text, cipher_text) stop = time.time() total_time = stop - start print 'Cipher -> ', cipher_text print 'Time taken -> ', total_time print 'Key present in sol -> ', key in search print 'Presumed Cost -> ', cost print 'All matching keys -> ', search