-
Notifications
You must be signed in to change notification settings - Fork 0
/
polybius.py
62 lines (59 loc) · 1.5 KB
/
polybius.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
alpha=["a","b","c","d","e","f","g","h","i","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
key1=input("eneter the key word")
length1=len(key1)
rows,cols = (5,5)
list1= []
for i in range(0,length1):
if(key1[i] not in list1):
list1.append(key1[i])
length1=len(list1)
a = [[0 for i in range(cols)] for j in range(rows)]
b = [[0 for i in range(cols)] for j in range(rows)]
k=0
l=0
m=0
alpha11=[]
alpha12=[]
print(list1)
for n in range(0,25):
if(alpha[n] not in list1 ):
alpha11.append(alpha[n])
for i in range(0,5):
for j in range (0,5):
if(k < length1):
a[i][j]=list1[k]
k=k+1
else:
a[i][j]=alpha11[m]
m=m+1
for i in range(0,5):
for j in range(0,5):
print(a[i][j],end=" ")
print("\n")
f=open("words_twosquare.txt","r")
string=""
for each in f:
each=each.strip()
each=each.replace(" ","")
string=string+each
strlen=len(string)
string=string.lower()
print(string)
encryt=""
x=0
for k in range(0,strlen):
for i in range(0,5):
for j in range(0,5):
if(string[k]==a[i][j]):
posc,posr = j,i
encryt=encryt+str(j+1)+str(i+1)
print(a[i][j]+"->"+str(j+1)+str(i+1))
print(encryt)
decrypt=""
strlen=len(encryt)
for k in range(0,strlen,2):
if(k < strlen):
j,i = encryt[k],encryt[k+1]
j,i=int(j)-1,int(i)-1
decrypt=decrypt+a[i][j]
print(decrypt)