-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmp.py
48 lines (41 loc) · 1.05 KB
/
tmp.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
'''import socket
import time
import hashlib
import random
import sys
def exp(x, e, n):
ans = 1
for i in range(e):
ans = (ans * x) % n
return ans
msg = 111
RSAp = 6073 #PRIVATE
RSAq = 7727 #PRIVATE
RSAn = RSAp*RSAq #PUBLIC, WILL BE SHARED = 46926071
RSAe = 65537
RSAd = 35345441 #BOBS PRIVATE KEY. DO NOT SHARE
'''
RSAr = random.randint(1, RSAn)
randRSA = hashlib.new('sha1')
randRSA.update(str(RSAr).encode('utf-8'))
randRSAhash = int(randRSA.hexdigest(), 16)
RSAy1 = exp(RSAr, RSAe, RSAn)
RSAy2 = msg ^ randRSAhash
'''
sock.sendall(str(RSAy1).encode('utf-8'))
sock.sendall(str(RSAy2).encode('utf-8'))
'''
''''''
'''
RSAy1 = int(conn.recv(1024).decode('utf-8'))
RSAy2 = int(conn.recv(1024).decode('utf-8'))
'''
decrypted_r = exp(RSAy1, RSAd, RSAn)
msgrandRSA = hashlib.new('sha1')
msgrandRSA.update(str(decrypted_r).encode('utf-8'))
msgrandRSAhash = int(msgrandRSA.hexdigest(), 16)
'''
if(randRSAhash != msgrandRSAhash):
print("Error in hash values")
'''
decrypted_msg = RSAy2 ^ msgrandRSAhash