Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for x in range (2):
- # the string to be encrypted/decrypted
- message =input( 'Enter a message')
- translated = ''
- # the encryption/decryption key
- key = int(input("Enter Key"))
- # tells the program to encrypt or decrypt
- mode = input('encrypt or decrypt') .lower()# set to 'encrypt' or 'decrypt'
- # every possible symbol that can be encrypted
- LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- # capitalize the string in message
- message = message.upper()
- # run the encryption/decryption code on each symbol in the message string
- for symbol in message:
- if symbol in LETTERS:
- # get the encrypted (or decrypted) number for this symbol
- num = LETTERS.find(symbol) # get the number of the symbol
- if mode == 'encrypt':
- num = num + key
- elif mode == 'decrypt':
- num = num - key
- # add encrypted/decrypted number's symbol at the end of translated
- translated = translated + LETTERS[num]
- else:
- # just add the symbol without encrypting/decrypting
- translated = translated + symbol
- # print the encrypted/decrypted string to the screen
- print(translated)
Advertisement
Add Comment
Please, Sign In to add comment