()
| 11 | |
| 12 | |
| 13 | def main(): |
| 14 | print('Rail Fence Cipher, by Al Sweigart al@inventwithpython.com') |
| 15 | |
| 16 | # Ask the user if they want to encrypt or decrypt: |
| 17 | while True: |
| 18 | print('Do you want to (E)ncrypt or (D)ecrypt?') |
| 19 | mode = input('> ').upper() |
| 20 | if mode == 'E' or mode == 'D': |
| 21 | break |
| 22 | |
| 23 | # Ask the user for the message to encrypt or decrypt: |
| 24 | while True: |
| 25 | print('Enter a message up to 75 characters long:') |
| 26 | print('|' + ('-' * 73) + '|') |
| 27 | message = input('> ') |
| 28 | if 0 < len(message) <= 75: |
| 29 | break |
| 30 | |
| 31 | # Ask the user for the key number. |
| 32 | while True: |
| 33 | print('Enter the key number 2 to 12:') |
| 34 | response = input('> ') |
| 35 | try: |
| 36 | key = int(response) |
| 37 | except: |
| 38 | print('You must enter a number.') |
| 39 | if 2 <= key <= 12: |
| 40 | break |
| 41 | |
| 42 | # Encrypt or decrypt the message: |
| 43 | if mode == 'E': |
| 44 | encryptMessage(message, key) |
| 45 | elif mode == 'D': |
| 46 | decryptMessage(message, key) |
| 47 | |
| 48 | |
| 49 | def getBlankRails(message, key): |
no test coverage detected