|
3 | 3 | Year 2017
|
4 | 4 |
|
5 | 5 | This is an symmetric encryption algorithm. It is a more glorified version of a
|
6 |
| -substitution cipher. However, some substitutions are added that do not |
| 6 | +substitution cipher. However, some substitutions are added that do not |
7 | 7 | correspond to a letter to try and confuse anyone trying to break the cipher
|
8 | 8 | """
|
9 | 9 |
|
10 | 10 | # ENCRYPTOR V2.2.2
|
11 | 11 | # Kieran (MIT License)
|
12 | 12 |
|
13 | 13 | """
|
14 |
| -Being pseudorandom, the random libary perhaps isn't the best for an encryption |
| 14 | +Being pseudorandom, the random library perhaps isn't the best for an encryption |
15 | 15 | machine but this is more proof of concept
|
16 | 16 | """
|
17 | 17 | import random
|
|
23 | 23 | uppercase. The only punctuation allowed is '.' and ' ' to improve readability of
|
24 | 24 | the output
|
25 | 25 | """
|
26 |
| -alphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q', |
27 |
| - 'R','S','T','U','V','W','X','Y','Z',' ','.','0','1','2','3','4','5', |
28 |
| - '6','7','8','9'] |
| 26 | +alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', |
| 27 | + 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '.', '0', '1', '2', '3', '4', '5', |
| 28 | + '6', '7', '8', '9'] |
29 | 29 |
|
30 | 30 | # THE ENCRYPTION KEYS
|
31 | 31 | encryptionKeyA = ['KYL', 'JTD', 'RXQ', 'WEF', 'BRG', 'AWS', 'LHM', 'KWK', 'UIK',
|
32 |
| - 'EHQ', 'GVT', 'UKE', 'WLV', 'HGI', 'KRI', 'PUE', 'HJB', 'FVL', |
33 |
| - 'ORQ', 'ROD', 'JKH', 'QOT', 'QLU', 'YSJ', 'JNT', 'PBC', 'HNC', |
34 |
| - 'YSG', 'NKI', 'SGU', 'OXG', 'WCG', 'HAB', 'GVC', 'UEJ', 'SGB', |
35 |
| - 'SWE', 'YKX'] |
| 32 | + 'EHQ', 'GVT', 'UKE', 'WLV', 'HGI', 'KRI', 'PUE', 'HJB', 'FVL', |
| 33 | + 'ORQ', 'ROD', 'JKH', 'QOT', 'QLU', 'YSJ', 'JNT', 'PBC', 'HNC', |
| 34 | + 'YSG', 'NKI', 'SGU', 'OXG', 'WCG', 'HAB', 'GVC', 'UEJ', 'SGB', |
| 35 | + 'SWE', 'YKX'] |
36 | 36 | encryptionKeyB = ['IDY', 'CBS', 'YSP', 'HTA', 'IGR', 'OBH', 'QEY', 'HCQ', 'RWB',
|
37 |
| - 'CJC', 'RRD', 'MDO', 'JIF', 'QHH', 'MYL', 'NLK', 'PIB', 'SMD', |
38 |
| - 'HNH', 'LBD', 'CIY', 'SXE', 'AEW', 'LFV', 'MVV', 'YQU', 'WUI', |
39 |
| - 'LRW', 'UYY', 'RUC', 'SUR', 'OOR', 'WQE', 'KAX', 'LFB', 'XBO', |
40 |
| - 'GWF', 'WSY'] |
| 37 | + 'CJC', 'RRD', 'MDO', 'JIF', 'QHH', 'MYL', 'NLK', 'PIB', 'SMD', |
| 38 | + 'HNH', 'LBD', 'CIY', 'SXE', 'AEW', 'LFV', 'MVV', 'YQU', 'WUI', |
| 39 | + 'LRW', 'UYY', 'RUC', 'SUR', 'OOR', 'WQE', 'KAX', 'LFB', 'XBO', |
| 40 | + 'GWF', 'WSY'] |
41 | 41 | falseEncryption = ['EQS', 'NPO', 'PKA', 'FGA', 'BWR', 'PIE', 'IFE', 'GUM', 'XIN',
|
42 |
| - 'EHT', 'MDU', 'CAX', 'OBY', 'MQP', 'PYF', 'PVI', 'GOS', 'YYG', |
43 |
| - 'FTQ', 'NDT', 'YHK', 'JVJ', 'NPV', 'BHE', 'JLJ', 'DUN', 'EPU', |
44 |
| - 'RKX', 'LOM', 'HVD', 'GIG', 'KRE', 'VVJ', 'HFY', 'QJU', 'VXB', |
45 |
| - 'OIF', 'XCE'] |
| 42 | + 'EHT', 'MDU', 'CAX', 'OBY', 'MQP', 'PYF', 'PVI', 'GOS', 'YYG', |
| 43 | + 'FTQ', 'NDT', 'YHK', 'JVJ', 'NPV', 'BHE', 'JLJ', 'DUN', 'EPU', |
| 44 | + 'RKX', 'LOM', 'HVD', 'GIG', 'KRE', 'VVJ', 'HFY', 'QJU', 'VXB', |
| 45 | + 'OIF', 'XCE'] |
46 | 46 |
|
47 | 47 | # RUN AGAIN - THE MODULAR FUNCTION TO ASK THE USER WHETHER THEY WOULD LIKE TO
|
48 | 48 | # RUN THE CODE AGAIN
|
49 |
| -def runAgain(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption): |
| 49 | +def runAgain(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption): |
50 | 50 |
|
51 |
| - try: |
52 |
| - play = str(input ("\nWould you like to run again? \n\n>>>")) |
53 |
| - play = play.lower() |
54 |
| - play = play[0] |
55 |
| - except: |
56 |
| - print ("\n!PLEASE TYPE 'YES' OR 'NO'!") |
57 |
| - runAgain(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
58 |
| - if play == "y": |
59 |
| - main(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
60 |
| - elif play == "n": |
61 |
| - print ("Ok") |
62 |
| - else: |
63 |
| - print ("\n!PLEASE TYPE 'YES' OR 'NO'!") |
64 |
| - runAgain(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
| 51 | + try: |
| 52 | + play = str(input("\nWould you like to run again? \n\n>>>")) |
| 53 | + play = play.lower() |
| 54 | + play = play[0] |
| 55 | + except: |
| 56 | + print("\n!PLEASE TYPE 'YES' OR 'NO'!") |
| 57 | + runAgain(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
| 58 | + if play == "y": |
| 59 | + main(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
| 60 | + elif play == "n": |
| 61 | + print("Ok") |
| 62 | + else: |
| 63 | + print("\n!PLEASE TYPE 'YES' OR 'NO'!") |
| 64 | + runAgain(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
65 | 65 |
|
66 | 66 | # THE ENCRYPTION PROCESS
|
67 |
| -def encrypt(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption): |
68 |
| - # Get user input |
69 |
| - string = input("\nPlease input the message to encrypt \n\n>>>") |
70 |
| - string = string.upper() |
71 |
| - # The encrypted text |
72 |
| - new = "" |
73 |
| - for x in range(len(string)): |
74 |
| - for i in range(38): |
75 |
| - # Text the charachter is in the allowed alphabet |
76 |
| - if string[x] == alphabet[i]: |
77 |
| - encryptChoice = systemRandom.randint(0,1) |
78 |
| - if encryptChoice == 0: |
79 |
| - new = new + encryptionKeyA[i] |
80 |
| - elif encryptChoice == 1: |
81 |
| - new = new + encryptionKeyB[i] |
82 |
| - # Add a random element from the false key |
83 |
| - new = new + falseEncryption[systemRandom.randint(0,26)] |
84 |
| - print ("\nHere is the new, encrypted message:\n\n"+new) |
85 |
| - runAgain(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
| 67 | +def encrypt(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption): |
| 68 | + # Get user input |
| 69 | + string = input("\nPlease input the message to encrypt \n\n>>>") |
| 70 | + string = string.upper() |
| 71 | + # The encrypted text |
| 72 | + new = "" |
| 73 | + for x in range(len(string)): |
| 74 | + for i in range(38): |
| 75 | + # Text the character is in the allowed alphabet |
| 76 | + if string[x] == alphabet[i]: |
| 77 | + encryptChoice = systemRandom.randint(0, 1) |
| 78 | + if encryptChoice == 0: |
| 79 | + new = new + encryptionKeyA[i] |
| 80 | + elif encryptChoice == 1: |
| 81 | + new = new + encryptionKeyB[i] |
| 82 | + # Add a random element from the false key |
| 83 | + new = new + falseEncryption[systemRandom.randint(0, 26)] |
| 84 | + print("\nHere is the new, encrypted message:\n\n"+new) |
| 85 | + runAgain(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
86 | 86 |
|
87 | 87 | # THE DECODING PROCESS
|
88 |
| -def decode(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption): |
89 |
| - # Get user input |
90 |
| - string = input("\nPlease input the message to decode as it was printed exactly \n\n>>>") |
91 |
| - string = string.upper() |
92 |
| - # The decoded text |
93 |
| - new = "" |
94 |
| - for x in range(int(len(string)/3)): |
95 |
| - for i in range(38): |
96 |
| - # Select the next 'chunk' of text and decrypt |
97 |
| - if string[x*3:(x*3)+3] == encryptionKeyA[i]: |
98 |
| - new = new + alphabet[i] |
99 |
| - elif string[x*3:(x*3)+3] == encryptionKeyB[i]: |
100 |
| - new = new + alphabet[i] |
101 |
| - print ("\nHere is the original, decoded message:\n\n"+new) |
102 |
| - runAgain(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
| 88 | +def decode(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption): |
| 89 | + # Get user input |
| 90 | + string = input("\nPlease input the message to decode as it was printed exactly \n\n>>>") |
| 91 | + string = string.upper() |
| 92 | + # The decoded text |
| 93 | + new = "" |
| 94 | + for x in range(int(len(string)/3)): |
| 95 | + for i in range(38): |
| 96 | + # Select the next 'chunk' of text and decrypt |
| 97 | + if string[x*3:(x*3)+3] == encryptionKeyA[i]: |
| 98 | + new = new + alphabet[i] |
| 99 | + elif string[x*3:(x*3)+3] == encryptionKeyB[i]: |
| 100 | + new = new + alphabet[i] |
| 101 | + print("\nHere is the original, decoded message:\n\n"+new) |
| 102 | + runAgain(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
103 | 103 |
|
104 | 104 | # THE MENU FOR THE PROGRAM
|
105 |
| -def main(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption): |
| 105 | +def main(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption): |
106 | 106 |
|
107 |
| - print ("\nMain Menu:") |
108 |
| - print("Enter the number represented in the brackets to use the function.") |
109 |
| - try: |
110 |
| - mode = int(input ("\nFunctions:\nEncrypt(0) \nDecode(1) \n\n>>>")) |
111 |
| - if mode == 0: |
112 |
| - encrypt(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
113 |
| - elif mode == 1: |
114 |
| - decode(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
115 |
| - except: |
116 |
| - print ("\n!PLEASE INPUT 0 TO ENCRYPT OR 1 TO DECODE!") |
117 |
| - main(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
| 107 | + print("\nMain Menu:") |
| 108 | + print("Enter the number represented in the brackets to use the function.") |
| 109 | + try: |
| 110 | + mode = int(input("\nFunctions:\nEncrypt(0) \nDecode(1) \n\n>>>")) |
| 111 | + if mode == 0: |
| 112 | + encrypt(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
| 113 | + elif mode == 1: |
| 114 | + decode(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
| 115 | + except: |
| 116 | + print("\n!PLEASE INPUT 0 TO ENCRYPT OR 1 TO DECODE!") |
| 117 | + main(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
118 | 118 |
|
119 |
| -# THE INITIAL STARTUP PROCESS, SEPERATE FROM THE MENU SO IT ONLY RUNS ONCE |
120 |
| -def preStart(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption): |
| 119 | +# THE INITIAL STARTUP PROCESS, SEPARATE FROM THE MENU SO IT ONLY RUNS ONCE |
| 120 | +def preStart(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption): |
121 | 121 |
|
122 |
| - print ("Welcome to the encryption machine version 2.2.2!") |
123 |
| - print ("Designed and developed by Kieran.") |
124 |
| - main(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
125 |
| - |
126 |
| -# THE COMMAND EXCECUTED TO START THE PROGRAM |
127 |
| -preStart(alphabet,encryptionKeyA,encryptionKeyB,falseEncryption) |
| 122 | + print("Welcome to the encryption machine version 2.2.2!") |
| 123 | + print("Designed and developed by Kieran.") |
| 124 | + main(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
128 | 125 |
|
| 126 | +# THE COMMAND EXECUTED TO START THE PROGRAM |
| 127 | +preStart(alphabet, encryptionKeyA, encryptionKeyB, falseEncryption) |
0 commit comments