-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpt2client.py
More file actions
81 lines (69 loc) · 1.45 KB
/
Expt2client.py
File metadata and controls
81 lines (69 loc) · 1.45 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
import socket
import math
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 9999
s.connect((host, port))
listofprimes=[0]*26
smalllistofprimes=[0]*26
smalllistofnos=[0]*10
listofalphabets=[None]*62
for i in range(26):
listofalphabets[i] = chr(65+i)
j=0
for i in range(26,52,1):
listofalphabets[i] = chr(97+j)
j=j+1
j=0
for i in range(52,62,1):
listofalphabets[i] = chr(48+j)
j=j+1
z=0
j=1
count = 23
i=6
listofprimes[0]=102
listofprimes[1]=103
listofprimes[2]=105
while(count!=0):
flag = 0
for j in range(1, int(math.sqrt(i))+1, 1):
if i%j ==0:
flag = flag+1
if flag ==1:
if int(len(str(i)))==2 or int(len(str(i)))==1 :
x = i+100
else:
x=i
listofprimes[z+3]=x
z=z+1
count = count-1
i=i+1
listofprimes.reverse()
countdown=26
i=0
while(countdown!=0):
smalllistofprimes[i]=listofprimes[i]+100
countdown = countdown-1
i= i+1
for i in range(10):
smalllistofnos[i]=chr(65+i)+chr(65+i)+chr(65+i)
keys=listofprimes+smalllistofprimes+smalllistofnos
sbox=dict(zip(listofalphabets, keys))
print(sbox)
#Sbox created.
PT=[]
RevPT=[]
CT=[]
PT=input("Enter the Plaintext here:")
RevPT=PT[::-1]
for i in RevPT:
for j in sbox.keys():
if i==j:
CT.append(str(sbox[j]))
print("The Cipher Text is:")
print(CT)
#Encryption Completed
list_str="|".join(CT)
s.send(list_str.encode('ascii'))
s.close()