|
| 1 | +user_input = input("\tPress enter to start encrypting messages using a modified Caesar's Cipher. Enter 'quit' to exit the program\n>>> ") |
| 2 | + |
| 3 | +while user_input.lower() != "quit": |
| 4 | + encryption_key = int(input("\tEnter encryption key\n>>> ")) |
| 5 | + message_original = str(input("\tEnter your message\n>>> ")) |
| 6 | + |
| 7 | + message_encrypted = "" |
| 8 | + |
| 9 | + for char in message_original: |
| 10 | + char_unicode_old = ord(char) |
| 11 | + |
| 12 | + # checks if it is an uppercase letter or a lowercase letter or a number |
| 13 | + upper = char_unicode_old >= 65 and char_unicode_old <= 90 |
| 14 | + lower = char_unicode_old >= 95 and char_unicode_old <= 122 |
| 15 | + number = char_unicode_old >= 48 and char_unicode_old <= 57 |
| 16 | + |
| 17 | + # does nothing if it the character is not a letter or number |
| 18 | + char_unicode_new = char_unicode_old + (encryption_key * (upper or lower or number)) |
| 19 | + |
| 20 | + # makes unicode only be in between 65 - 90 (A - Z) if the original character was an uppercase letter |
| 21 | + char_unicode_new += upper * ((91 - ((65 - char_unicode_new) % 26) - char_unicode_new) * (char_unicode_new < 65)) |
| 22 | + char_unicode_new += upper * (65 + ((char_unicode_new - 65) % 26) - char_unicode_new) * (char_unicode_new > 90) |
| 23 | + |
| 24 | + # makes unicode only be in between 97 - 122 (a - z) if the original character was a lowercase letter |
| 25 | + char_unicode_new += lower * (123 - ((97 - char_unicode_new) % 26) - char_unicode_new) * (char_unicode_new < 97) |
| 26 | + char_unicode_new += lower * (97 + ((char_unicode_new - 97) % 26) - char_unicode_new) * (char_unicode_new > 122) |
| 27 | + |
| 28 | + # makes unicode only be in between 48 - 57 (0 - 9) if the original character was a number |
| 29 | + char_unicode_new += number * (58 - ((48 - char_unicode_new) % 10) - char_unicode_new) * (char_unicode_new < 48) |
| 30 | + char_unicode_new += number * (48 + ((char_unicode_new - 48) % 10) - char_unicode_new) * (char_unicode_new > 57) |
| 31 | + |
| 32 | + message_encrypted += chr(char_unicode_new) |
| 33 | + |
| 34 | + print("Encrypted message : " + message_encrypted) |
| 35 | + |
| 36 | + user_input = input("\tPress enter to continue encrypting messages. Enter 'quit' to exit the program\n>>> ") |
0 commit comments