-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_ceaser_cipher_method.py
70 lines (67 loc) · 2.12 KB
/
python_ceaser_cipher_method.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
'''nn=input(' ENTER S TO RUN , N TO STOP: ')
while nn=='s':
ans=input('enter the massage to encrypt: ')
anss=ans.replace(' ','')
newmsg=''
al= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z']
code=int(input('enter the code to run: '))
for i in anss:
s=al.index(i)
encodeno=s+code
#print(s,encodeno)
if encodeno>26:
encodeno=encodeno%26
else:
encodeno=encodeno
typee=type(encodeno)
if type(encodeno)==int:
newmsg+=al[encodeno]
else:
newmsg+=ans.replace(' ','_')
print(newmsg)
nn=input(' ENTER S TO RUN , N TO STOP: ')'''
ans=input('enter s to run and n to stop : ')
while ans=='s':
x=int(input('''1.ENTER 1 TO CONVERT PLAIN TO CIPHER TEXT
2.ENTERT 2 TO CONVERT CIPHER TO PLAIN TEXT'''))
if x==1:
n=input('enter msg to encrypt : ')
newmsg=''
al= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z']
code=int(input('enter code to encrypt : '))
for i in n:
if type(i)==str and i!=' ':
encode=code+al.index(i)
if encode<26:
encode=encode
else:
encode=encode%26
newmsg+=al[encode]
else:
newmsg+='_'
print(newmsg)
elif x==2:
n=input('enter msg to decrypt : ')
newmsg=''
al= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z']
code=int(input('enter code to decrypt : '))
for i in n:
if i!=' ':
encode=al.index(i)+code
encode=encode%26
newmsg+=al[encode]
elif i==' ':
newmsg+=' '
print(newmsg)
else:
pass
ans=input('enter s to run and n to stop : ')