Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import itertools
- import functools
- from collections import OrderedDict
- class Private(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
- REST = 9
- def cry_test(secure):
- skey = random.randint(0 ,REST)
- open_skey = secure.statement(skey)
- # client:
- rkey = random.randint(0, REST)
- 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(i,j):
- secure = Private(i,j)
- l = []; sk = []; rk = []
- for i in range(100):
- a,b,c = cry_test(secure)
- l.append(a)
- return [l.count(c) for c in range(100)]
- if __name__ == '__main__':
- dct = {}
- for i in range(1,18):
- for j in range(1,998):
- dct[(i,j)] = test(i,j)
- print max(dct[(i,j)]).__str__() + ' - ' + (i,j).__str__()
- rez = {k:max(v) for k, v in dct.iteritems()}
- items = list(rez.iteritems())
- items.sort(key=lambda i: i[1])
- od = OrderedDict()
- for item in items:
- od[str(item[1]) + '%'] = item[0]
- print od
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement