Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=====================================#
- #==============MODULES================#
- #=====================================#
- #=====================================#
- #==============VARIABLES==============#
- #=====================================#
- menus = ["(1) Encrypt", "(2) Decrypt", "(3) Exit "]
- #=====================================#
- #==============FUNCTIONS==============#
- #=====================================#
- #defines menu
- def menu(parameter):
- print " +===========+"
- print " | MENU |"
- print " |===========|"
- for word in parameter:
- print " |%s|" % word
- print " |-----------|"
- #defines encryption algorithm
- def enc(data, key):
- output = ""
- for char in data:
- nums = ord(char) #convert ascii
- nums = (nums + key) #add ascii value and key value to create constant shift
- output = (output + chr(nums)) #create output string with all 'new' characters
- print "The encrypted message is: ", output
- #defines decryption algorithm
- def dec(data, key):
- output = ""
- for char in data:
- nums = ord(char)
- nums = (nums - key)
- output = (output + chr(nums))
- print "The decrypted message is: ", output
- #=====================================#
- #===========MAIN PROGRAM==============#
- #=====================================#
- def main():
- menu(menus)
- choice = input("Please make a selection(1-3): ")
- #Encryption
- if choice == 1:
- key = input("Please enter numerical key: ")
- data = raw_input("Please enter a message to encrypt: ")
- enc(data, key)
- #Decryption
- elif choice == 2:
- key = input("Please enter numerical key: ")
- data = raw_input("Please enter a message to decrypt: ")
- dec(data, key)
- #Exit
- elif choice == 3:
- print "Exiting Program. Goodbye."
- #Fault
- else:
- print "Invalid Selection."
- return main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement