-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCiphersAIO.py
More file actions
224 lines (177 loc) · 5.26 KB
/
Copy pathCiphersAIO.py
File metadata and controls
224 lines (177 loc) · 5.26 KB
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
220
221
222
223
224
#!/usr/bin/python3
'''
@odin
'''
from random import randint as ri
_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def main():
while True:
print('\n\t\t\t|| Cipher Algorithms ||')
print('''\n1. Additive Cipher\n2. Ceaser Cipher\n3. One Time Pad Cipher\n4. AutoKey Cipher\n5. Exit\n''')
ch = int(input('Enter your choice : '))
if ch is 1:
additive()
elif ch is 2:
ceaser()
elif ch is 3:
otpc()
elif ch is 4:
AutoKey()
elif ch is 5:
exit(0)
else:
print('Invalid Choice')
pass
# end of main
def additive():
_plainText = ''
_cipherText = ''
print('\n\n\t\t|| Additive Cipher ||\n')
print('''\n1. Encrypt Message\n2. Decrypt Message\n3. Return to main\n''')
ch = int(input('Enter your choice : '))
if ch is 1:
_cipherText = ''
_plainText = str(input('\nEnter message to encrypt : ')).upper().replace(" ","")
key = int(input('Enter key in range[0-25] : '))
if key>25 and key < 0:
print("Invalid key value")
additive()
for index,i in enumerate(_plainText):
char = _charset.find(i) + key
if char > 25:
char = char%26
_cipherText += _charset[char]
print("\nYour message '{}' is Encrypted as '{}'\n".format(_plainText.lower(),_cipherText))
input('press ENTER to continue\n')
additive()
elif ch is 2:
_plainText = ''
_cipherText = str(input('\nEnter message to decrypt : ')).upper().replace(" ","")
key = int(input('Enter key in range[0-25] : '))
if key>25 and key < 0:
print("Invalid key value")
additive()
for index,i in enumerate(_cipherText):
char = _charset.find(i) - key
if char < 0:
char += 26
_plainText += _charset[char]
print("\nYour message '{}' is decrypted as '{}'\n".format(_cipherText,_plainText.lower()))
input('press ENTER to continue\n')
additive()
elif ch is 3:
pass
else:
print('Invalid Choice')
additive()
def ceaser():
_plainText = ''
_cipherText = ''
key = 3
print('\n\n\t\t|| Ceaser Cipher ||\n')
print('''\n1. Encrypt Message\n2. Decrypt Message\n3. Return to main\n''')
ch = int(input('Enter your choice : '))
if ch is 1:
_cipherText = ''
_plainText = str(input('\nEnter message to encrypt : ')).upper().replace(" ","")
for index,i in enumerate(_plainText):
char = _charset.find(i) + key
if char > 25:
char = char%26
_cipherText += _charset[char]
print("\nYour message '{}' is Encrypted as '{}'\n".format(_plainText.lower(),_cipherText))
input('press ENTER to continue\n')
ceaser()
elif ch is 2:
_plainText = ''
_cipherText = str(input('\nEnter message to decrypt : ')).upper().replace(" ","")
for index,i in enumerate(_cipherText):
char = _charset.find(i) - key
if char < 0:
char += 26
_plainText += _charset[char]
print("\nYour message '{}' is decrypted as '{}'\n".format(_cipherText,_plainText.lower()))
input('press ENTER to continue\n')
ceaser()
elif ch is 3:
pass
else:
print('Invalid Choice')
ceaser()
def otpc():
_plainText = ''
_cipherText = ''
key = ''
print('\n\n\t\t|| OneTimePad Cipher ||\n')
print('''\n1. Encrypt Message\n2. Return to main\n''')
ch = int(input('Enter your choice : '))
if ch is 1:
_cipherText = ''
_plainText = str(input('\nEnter message to encrypt : ')).upper().replace(" ","")
for char in range(len(_plainText)):
key += _charset[ri(0,25)]
for index,i in enumerate(_plainText):
char = _charset.find(i) + _charset.find(key[index])
if char > 25:
char -= 26
_cipherText += _charset[char]
print("\nYour message '{}' is Encrypted as '{}' using key {}\n".format(_plainText.lower(),_cipherText,key))
input('press ENTER to continue\n')
otpc()
elif ch is 2:
pass
else:
print('Invalid Choice')
otpc()
def AutoKey():
_plainText = ''
_cipherText = ''
print('\n\n\t\t|| AutoKey Cipher ||\n')
print('''\n1. Encrypt Message\n2. Decrypt Message\n3. Return to main\n''')
ch = int(input('Enter your choice : '))
if ch is 1:
_cipherText = ''
_plainText = str(input('\nEnter message to encrypt : ')).upper().replace(" ","")
key = int(input('Enter key in range[0-25] : '))
if key>25 and key < 0:
print("Invalid key value")
AutoKey()
for index,i in enumerate(_plainText):
if index is 0:
char = _charset.find(i) + key
else:
char = _charset.find(i) + _charset.find(_plainText[index - 1])
if char > 25:
char %= 26
_cipherText += _charset[char]
print("\nYour message '{}' is Encrypted as '{}'\n".format(_plainText.lower(),_cipherText))
input('press ENTER to continue\n')
AutoKey()
# Decryption main logic by keyser soze! Hail PappA
elif ch is 2:
_plainText = ''
_cipherText = str(input('\nEnter message to decrypt : ')).upper().replace(" ","")
key = int(input('Enter key in range[0-25] : '))
if key>25 and key < 0:
print("Invalid key value")
AutoKey()
for index,i in enumerate(_cipherText):
if index is 0:
char = _charset.find(i) - key
else:
char = _charset.find(i) - _charset.find(_plainText[index - 1])
if char < 0:
char += 26
print(char)
_plainText += _charset[char]
print("\nYour message '{}' is decrypted as '{}'\n".format(_cipherText,_plainText.lower()))
input('press ENTER to continue\n')
AutoKey()
elif ch is 3:
pass
else:
print('Invalid Choice')
AutoKey()
# Avoid exection of complete module while importing into other script
if __name__ == '__main__' :
main()