Advertisement
DigitalMag

Simple Diffie_Hellman

Jul 4th, 2020
1,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import random
  2.  
  3. class Secure(object):
  4.  
  5.     def __init__(self, n, rest):
  6.         self.rest = rest
  7.         self.n = n
  8.  
  9.     statement = lambda self, x: (self.n**x) % self.rest
  10.     post_statement = lambda self, a, b: (a**b) % self.rest
  11.  
  12.  
  13. R_LIMIT = 100
  14.  
  15. def cry_test(secure):
  16.  
  17.     skey = random.randint(0 ,R_LIMIT)
  18.     open_skey = secure.statement(skey)
  19.  
  20.     # client:
  21.     rkey = random.randint(0, R_LIMIT)
  22.     r_open_key = secure.statement(rkey)
  23.  
  24.     psw = secure.post_statement(open_skey, rkey)
  25.  
  26.     # server
  27.     spsw = secure.post_statement(r_open_key, skey)
  28.     # print psw
  29.  
  30.     return psw, skey, rkey
  31.  
  32.  
  33. def test():
  34.  
  35.     secure = Secure(7,100)
  36.  
  37.     l = []; sk = []; rk = []
  38.     for i in range(100):
  39.         a,b,c = cry_test(secure)
  40.         l.append(a)
  41.         sk.append(b)
  42.         rk.append(c)
  43.  
  44.     print([l.count(c) for c in range(100)])
  45.     print [sk.count(c) for c in range(100)]
  46.     print [rk.count(c) for c in range(100)]
  47.  
  48. test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement