-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryption.py
74 lines (61 loc) · 1.81 KB
/
encryption.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
#Written for python2
import os
def encrypt(a, b):
alphaLibrary=list('abcdefghijklmnopqrstuvwxyz')
cipher = ''
while len(b) < len(a):
b=b*2
b = b[:len(a)]
for character,key in zip(a,b):
if character == ' ':
cipher = cipher+' '
elif character == '!':
cipher = cipher + '!'
elif character == '.':
cipher = cipher + '.'
else:
newIndex = alphaLibrary.index(character) + int(key)
if newIndex < 26:
cipher = cipher + alphaLibrary[newIndex]
else:
cipher = cipher + alphaLibrary[newIndex%26]
print cipher
def decrypt(a, b):
alphaLibrary=list('abcdefghijklmnopqrstuvwxyz')
decipher = ''
while len(b) < len(a):
b=b*2
b = b[:len(a)]
for character,key in zip(a,b):
if character == ' ':
decipher = decipher+' '
elif character == '!':
decipher = decipher + '!'
elif character == '.':
decipher = decipher + '.'
else:
newIndex = alphaLibrary.index(character) - int(key)
if newIndex < 26:
decipher = decipher + alphaLibrary[newIndex]
else:
decipher = decipher + alphaLibrary[newIndex%26]
print decipher
def main():
userSelection = raw_input("\n[*] What you want to do sir? \n[1] Encryt \n[2] Decrypt \n> ")
if userSelection== str(1):
os.system('clear')
print 'Welcome, You have selected Encryt!!'
plainTxt=list(raw_input('[*] Enter your text you want to convert \n >'))
key=list(raw_input('[*] Enter encryption key \n >'))
encrypt(plainTxt,key)
elif userSelection==str(2):
os.system('clear')
print 'Welcome, You have selected Decryt!!'
plainTxt=list(raw_input('[*] Enter your text you want to convert \n >'))
key=list(raw_input('[*] Enter decryption key \n >'))
decrypt(plainTxt,key)
else:
print '\tOops! wrong selection please select encrypt or decrypt.'
print '\t\t\tSelect "1" for Encrypt.'
print '\t\t\tSelect "2" for Decrypt.\n'
main()