-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
219 lines (178 loc) · 7.72 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from TranspositionCiphers.TranspositionCipher import Cipher
def _performColumnarTransposition(): # OMAR's Task
columnar_transpose=Cipher.ColumnarTransposition() # Create an object of the TranspositionCipher class
print("You've Three Options:")
print("\t1. Uniqueness of the or key Handling repeating characters in the key")
print("\t2. An integer key in the range of 1 t 9")
print("\t3. A uniqueness integer key such as 123456789 or 987654321 the length of the key must be in the range of 0 to 9")
print("\t4. Main Menu")
print("\t5. Exit")
choice = int(input("Enter the option you want to use: "))
if choice == 1:
print("Option 1: Uniqueness of the key")
print("\t1. Encryption")
print("\t2. Decryption")
print("\t3. Previous Menu")
print("\t4. Main Menu")
print("\t5. Exit")
_op = input("Enter your choice: ")
if _op == '1':
print("Option 1: Encryption")
plain_text = input("Enter the plain text: ")
key = input("Enter the key: ")
print(f"Encrypted Message: {columnar_transpose._encryption(plain_text, key)}")
elif _op == '2':
print("Option 2: Decryption")
cipher_text = input("Enter the cipher text: ")
key = input("Enter the key: ")
print(f"Decrypted Message: {columnar_transpose._decryption(cipher_text, key)}")
elif _op == '3':
print("Returning to the previous menu...")
_performColumnarTransposition()
elif _op == '4':
print("Returning to the main menu...")
main()
elif _op == '5':
print("Exiting the program...")
exit()
elif choice == 2:
# Option 2: An integer key in the range of 1 to 9
def key_checker():
try:
_key = int(input("Enter the key: "))
if _key<0 or _key > 9:
print("You have entered wrong key.")
print("The key must be an integer from 1 to 9.")
_key = key_checker()
else:
_key = ''.join([str(i) for i in range(_key+1)])
except ValueError:
print("Invalid input.")
print("Please enter an integer (0:9).")
_key = key_checker()
return _key
print("Option 2: An integer key in the range of 1 to 9")
print("\t1. Encryption")
print("\t2. Decryption")
print("\t3. Previous Menu")
print("\t4. Main Menu")
print("\t5. Exit")
_op = input("Enter your choice: ")
if _op == '1':
print("Encryption Selected: Columnar Transposition Cipher")
plain_text = input("Enter the plain text: ")
key = key_checker ()
print(f"Encrypted Message: {columnar_transpose._encryption(plain_text, key)}")
elif _op == '2':
print("Decryption Selected: Columnar Transposition Cipher")
cipher_text = input("Enter the cipher text: ")
key = key_checker ()
print(f"Decrypted Message: {columnar_transpose._decryption(cipher_text, key)}")
elif _op == '3':
print("Returning to the previous menu...")
_performColumnarTransposition()
elif _op == '4':
print("Returning to the main menu...")
main()
elif _op == '5':
print("Exiting the program...")
exit()
elif choice == 3:
def _key_checker():
try:
_key = int(input("Enter the key: "))
if len(str(_key)) != len(list(dict.fromkeys(str(_key)))):
print("Invalid input. The key should be unique.")
_key=_key_checker()
else:
return str(_key)
except ValueError:
print("Invalid input. Please enter an integer.")
_key=_key_checker()
return _key
print("Option 3: A uniqueness integer key in the range of 0 to 9")
print("\t1. Encryption")
print("\t2. Decryption")
print("\t3. Previous Menu")
print("\t4. Main Menu")
print("\t5. Exit")
_op = input("Enter your choice: ")
if _op == '1':
print("Encryption Selected: Columnar Transposition Cipher")
plain_text = input("Enter the plain text: ")
key = _key_checker()
print(f"Encrypted Message: {columnar_transpose._encryption(plain_text, key)}")
elif _op == '2':
print("Decryption Selected: Columnar Transposition Cipher")
cipher_text = input("Enter the cipher text: ")
key = _key_checker()
print(f"Decrypted Message: {columnar_transpose._decryption(cipher_text, key)}")
elif _op == '3':
print("Returning to the previous menu...")
_performColumnarTransposition()
elif _op == '4':
print("Returning to the main menu...")
main()
elif _op == '5':
print("Exiting the program...")
exit()
elif choice == 4:
print("Returning to the main menu...")
main()
elif choice == 5:
print("Exiting the program...")
exit()
else:
print("Invalid choice")
print("Please enter a valid choice.")
_performColumnarTransposition()
def _performRailFenceTransposition(): # MALAK's Task
rail_fence=Cipher.RailFenceTransposition() # Create an object of the RailFenceTransposition class
print("You've four Options:")
print("\t1:Rail Fence Encryption\n\t2:Rail Fence Decryption\n\t3:Main Menu\n\t4:Exit")
choice =input("Enter your choice: ")
if choice == '1':
print("Encryption Selected: Rail Fence Cipher")
plain_text = input("Enter your message: ")
depth = int(input("Enter The Depth (a single number): "))
print(f"Encrypted Message: {rail_fence._encryption(plain_text, depth)}")
exit()
elif choice == '2':
print("Decryption Selected: Rail Fence Cipher")
cipher_text = input("Enter your Cipher Text: ")
depth = int(input("Enter The Depth (a single number): "))
print(f"Decrypted Message: {rail_fence._decryption(cipher_text, depth)}")
exit()
elif choice == '3':
print("Returning to the main menu...")
main()
elif choice == '4':
print("Exiting the program...")
exit()
else:
print("Invalid Choice")
print("Please enter a valid choice.")
_performRailFenceTransposition()
def main():
print("Only Columnar Transposition, and Rail Fence Transposition are available now.")
print("\t1. Columnar Transposition\n\t2. Rail Fence Transposition\n\t3. Exit")
try:
choice = int(input("Enter the cipher technique you want to use: "))
if choice == 1:
print("-------Columnar Transposition Cipher Technique-------")
_performColumnarTransposition()
elif choice == 2:
print("-------------Rail Fence Cipher Technique-------------")
_performRailFenceTransposition()
elif choice == 3:
print("Exiting the program...")
exit()
else:
print("Invalid choice")
print("Please enter a valid choice.")
main()
except ValueError:
print("Invalid input. Please enter an integer.")
main()
if __name__ == "__main__": # main
main()