Implement Cipher and Decipher using Cesar Cipher.
Anonym
# Imported Libraries import string def cipher_file(location, shift): """Cipher file using the provided shift""" # Open File myfile = open(location, 'r') input_string = myfile.read() # Process File ascii_values = string.ascii_lowercase shifted = ascii_values[shift:] + ascii_values[:shift] table = string.maketrans(ascii_values, shifted) result = input_string.translate(table) # Return result return result def decipher_file(location, shift): """decipher file using the provided shift""" # Open File myfile = open(location, 'r') input_string = myfile.read() # Process File ascii_values = string.ascii_lowercase shifted = ascii_values[shift:] + ascii_values[:shift] table = string.maketrans(shifted, ascii_values) result = input_string.translate(table) # Return result return result def save_file(location, text): """Save a new file, overwrite if exist""" myfile = open(location, 'w') myfile.write(text) myfile.close() # Cipher and Save SECURE = cipher_file('Test.txt', 3) print SECURE save_file('SecureFile.txt', SECURE) # Decipher UNSECURE = decipher_file('SecureFile.txt', 3) print UNSECURE