Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Secure(object):
- def __init__(self, n, rest):
- self.rest = rest
- self.n = n
- statement = lambda self, x: (self.n**x) % self.rest
- post_statement = lambda self, a, b: (a**b) % self.rest
- R_LIMIT = 100
- def cry_test(secure):
- skey = random.randint(0 ,R_LIMIT)
- open_skey = secure.statement(skey)
- # client:
- rkey = random.randint(0, R_LIMIT)
- r_open_key = secure.statement(rkey)
- psw = secure.post_statement(open_skey, rkey)
- # server
- spsw = secure.post_statement(r_open_key, skey)
- # print psw
- return psw, skey, rkey
- def test():
- secure = Secure(7,100)
- l = []; sk = []; rk = []
- for i in range(100):
- a,b,c = cry_test(secure)
- l.append(a)
- sk.append(b)
- rk.append(c)
- print([l.count(c) for c in range(100)])
- print [sk.count(c) for c in range(100)]
- print [rk.count(c) for c in range(100)]
- test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement