cleanup and types correction

This commit is contained in:
Mateusz Piątkowski 2024-04-14 13:42:38 +02:00
parent 428d692283
commit f4affc480a
4 changed files with 21 additions and 26 deletions

Binary file not shown.

View File

@ -1,10 +0,0 @@
from utils import generate_secret
from utils import prime, FILE
from Crypto.Math.Numbers import Integer, from_bytes
g = Integer(2)
a = generate_secret()
A_secret = pow(g, Integer.from_bytes(a), prime)
with open(FILE, 'wb') as f:
f.write(A_secret.to_bytes())

16
bob.py
View File

@ -1,16 +0,0 @@
from utils import generate_secret, coin_toss
from utils import prime, FILE
from Crypto.Math.Numbers import Integer
g = Integer(2)
b = generate_secret()
B_secret = pow(g, Integer.from_bytes(b), prime)
if coin_toss():
with open(FILE, 'r') as f:
A_secret = f.read()
B_secret = A_secret * B_secret
print('siup')
print(B_secret)

21
main.py
View File

@ -0,0 +1,21 @@
from utils import generate_secret, coin_toss
from utils import prime, FILE
from Crypto.Math.Numbers import Integer
def alice_1():
g = Integer(2)
a = generate_secret()
A_secret = pow(g, Integer(int.from_bytes(a)), prime)
return A_secret
def bob_1(A_secret):
g = Integer(2)
b = generate_secret()
B_secret = pow(g, Integer.from_bytes(b), prime)
if coin_toss():
B_secret = A_secret * B_secret
return B_secret
a = alice_1()
b = bob_1(a)
print(b)