From 4f28892d581e5feefbb1037d602366c50c34b2d4 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 8 Oct 2019 11:53:46 +0200 Subject: [PATCH] Week7 init --- week7.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 week7.py diff --git a/week7.py b/week7.py new file mode 100644 index 0000000..c8551e1 --- /dev/null +++ b/week7.py @@ -0,0 +1,75 @@ +from secrets import SystemRandom + +random = SystemRandom() + +''' +def find_big_odd(k): + + num = random.getrandbits(k) + while num % 2 == 0: + num = +''' + + +def enc(m, pk): + S = 1000 + c = m + sum(random.sample(pk, S)) + return c + + +class Alice: + def __init__(self, ya, yb, yr): + self.ya = ya + self.yb = yb + self.yr = yr + # p is the secret key + self.p = random.getrandbits(2000)*2 + 1 # odd integer + n = 2000 + bigInts = [random.getrandbits(10**7) for _ in range(n)] + smallInts = [random.getrandbits(60) for _ in range(n)] + + self.pk = [self.p*bigInts[i] + 2*smallInts[i] for i in range(n)] + self.cya = enc(ya, self.pk) + self.cyb = enc(yb, self.pk) + self.cyr = enc(yr, self.pk) + + def send(self): + return self.cya, self.cyb, self.cyr, self.pk + + def dec(self, c): + m = (c % self.p) % 2 + return m + + +class Bob: + def __init__(self, xa, xb, xr): + self.xa = xa + self.xb = xb + self.xr = xr + + def receive(self, cya, cyb, cyr, pk): + self.pk = pk + + # these are ciphered values from alice + self.cya = cya + self.cyb = cyb + self.cyr = cyr + + # these are ciphered values from bob + self.cxa = enc(self.xa, pk) + self.cxb = enc(self.xb, pk) + self.cxr = enc(self.xr, pk) + + def compute_bloodcompatiblity(self): + + + #f = (1 ^ (self.xa & (1 ^ self.cya))) & (1 ^ (self.xb & (1 ^ self.cyb))) & (1 ^ (self.xr & (1 ^ self.cyr))) + #z = enc(f, self.pk) + #return z + pass + +def protocol(donor, recipient): + # Alice is recipient + alice = Alice(0,1,1) + bob = Bob(1,0,0) + pass \ No newline at end of file