()
| 15 | |
| 16 | |
| 17 | def main(): |
| 18 | print('''Vigenère Cipher, by Al Sweigart al@inventwithpython.com |
| 19 | The Viegenère cipher is a polyalphabetic substitution cipher that was |
| 20 | powerful enough to remain unbroken for centuries.''') |
| 21 | |
| 22 | # Let the user specify if they are encrypting or decrypting: |
| 23 | while True: # Keep asking until the user enters e or d. |
| 24 | print('Do you want to (e)ncrypt or (d)ecrypt?') |
| 25 | response = input('> ').lower() |
| 26 | if response.startswith('e'): |
| 27 | myMode = 'encrypt' |
| 28 | break |
| 29 | elif response.startswith('d'): |
| 30 | myMode = 'decrypt' |
| 31 | break |
| 32 | print('Please enter the letter e or d.') |
| 33 | |
| 34 | # Let the user specify the key to use: |
| 35 | while True: # Keep asking until the user enters a valid key. |
| 36 | print('Please specify the key to use.') |
| 37 | print('It can be a word or any combination of letters:') |
| 38 | response = input('> ').upper() |
| 39 | if response.isalpha(): |
| 40 | myKey = response |
| 41 | break |
| 42 | |
| 43 | # Let the user specify the message to encrypt/decrypt: |
| 44 | print('Enter the message to {}.'.format(myMode)) |
| 45 | myMessage = input('> ') |
| 46 | |
| 47 | # Perform the encryption/decryption: |
| 48 | if myMode == 'encrypt': |
| 49 | translated = encryptMessage(myMessage, myKey) |
| 50 | elif myMode == 'decrypt': |
| 51 | translated = decryptMessage(myMessage, myKey) |
| 52 | |
| 53 | print('%sed message:' % (myMode.title())) |
| 54 | print(translated) |
| 55 | |
| 56 | try: |
| 57 | pyperclip.copy(translated) |
| 58 | print('Full %sed text copied to clipboard.' % (myMode)) |
| 59 | except: |
| 60 | pass # Do nothing if pyperclip wasn't installed. |
| 61 | |
| 62 | |
| 63 | def encryptMessage(message, key): |
no test coverage detected