MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

src/gamesbyexample/vigenerecipher.py:17–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15
16
17def main():
18 print('''Vigenère Cipher, by Al Sweigart al@inventwithpython.com
19The Viegenère cipher is a polyalphabetic substitution cipher that was
20powerful 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
63def encryptMessage(message, key):

Callers 1

vigenerecipher.pyFile · 0.70

Calls 2

encryptMessageFunction · 0.70
decryptMessageFunction · 0.70

Tested by

no test coverage detected