from proj2_ex3 import * # This is not a simple problem ! # The solution requires a more elaborated analysis and # a use of the English dictionary # So you can skip the problem without losing anything # But here are some ideas on how to start: def find_closest(x, float_list): "Find the closest element in float_list which is closest to x" closest = 0 min_distance = float('Infinity') for f in float_list: if abs(f-x) < min_distance: closest = f min_distance = abs(f-x) return closest if __name__ == '__main__': d = letter_frequency("D:/workspace/jude.txt") float_list = d.values() e = dict() for letter,frequency in d.items(): e[frequency] = letter d = letter_frequency("D:/workspace/decrypt_me.txt") cipher = dict() for letter in d: x = find_closest(d[letter], e.keys()) cipher[letter] = e[x] print cipher file_encrypt("d:/workspace/decrypt_me.txt", "d:/workspace/decrypted.txt", cipher)