-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrypt0graphy.py
More file actions
35 lines (29 loc) · 911 Bytes
/
crypt0graphy.py
File metadata and controls
35 lines (29 loc) · 911 Bytes
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
import crypto
from crypto import *
class DS_Verification_Error(Exception):
pass
def DHs1():
p,g,a = diffie_hellman_0()
DHs1.p, DHs1.a = p, a
x = diffie_hellman_1(p,g,a)
data = str((p,g,x)).encode()
signer_ = signer(crypto.prirsakey)
return sign_with_data(signer_, data)
def DHc(sdata):
verifier = signer(crypto.pubrsakey)
ver, data = verify(verifier, sdata)
if not ver: raise DS_Verification_Error
p,g,x = eval(data.decode())
b = random.randrange(2,p)
rk = diffie_hellman_2(p,x,b)
y = diffie_hellman_1(p,g,b)
data = str(y).encode()
signer_ = signer(crypto.prirsakey)
return sign_with_data(signer_, data), rk
def DHs2(cdata):
verifier = signer(crypto.pubrsakey)
ver, data = verify(verifier, cdata)
if not ver: raise DS_Verification_Error
y = int(data.decode())
rk = diffie_hellman_2(DHs1.p,y,DHs1.a)
return rk