Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import OrderedDict
- import random
- import time
- # import secure
- # from secure import greet
- from numba import jit
- import numpy as np
- import numpy
- import os.path
- import pickle
- # print (greet("world"))
- isprime = lambda number: all(number % i for i in range(2, number))
- @jit(nopython=True)
- def issimple(n):# получаем число
- d=2 # олучить остаток от деления на 2, значит - простое
- while n % d!=0:# пока число mod 2<>0 переберем делители, так как , простое, делится неа 2 и на себя,
- d+=1# перебрасываем все, кроме 2
- return d==n # возвращаем результат
- ##@jit(nopython=True)
- ##def istatement(n,x,rest):
- ## return n**x % rest
- class Secure(object):
- def __init__(self, n, rest):
- self.rest = rest
- self.n = n
- # wrong reslts:
- @staticmethod
- @jit(nopython=True)
- def istatement(n,x,rest):
- return n**x % rest
- # statement = lambda self, x: secure.istatement(self.n, x, self.rest) # lambda self, x: self.n**x % self.rest
- statement = lambda self, x: (self.n**x) % self.rest
- post_statement = lambda self, a, b: (a**b) % self.rest
- R_LIMIT = 1864 # 9586 # 5864
- # # 199 == (37, 979999998077) => 1000000 итераций => 50сек = 50_000 мс
- def cry_test(secure):
- skey = random.randint(2 ,R_LIMIT)
- open_skey = secure.statement(skey)
- # client:
- rkey = random.randint(2, 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
- if psw != spsw: raise "not asset"
- return psw, skey, rkey
- def Cry_Test(clst,start,end):
- # def Cry_test(clst):
- if type(clst) is list: lst = clst
- else:
- lst = clst.get()
- for i in range(start,end):
- if i%100 == 0: print (i)
- a,b,c = cry_test(secure)
- lst.append(a)
- def creator(q,l):
- q.put(l)
- def test():
- # params = (17, 979999998077) # 764
- params = (17, 979998077)
- ## if (issimple(params[1]) == False):
- ## print('no prime')
- ## return
- secure = Secure(*params)
- """
- w scopes:
- 9586 # 5864 / (17, 979999998077), (5, 979999998077)==0.03%
- """
- """
- w/o scopes:
- '7%', (793, 83)
- '8%', (118, 97)
- Big Simple digits
- [97999807, 97999813, 97999823, 97999831, 97999859, 97999861, 97999877, 97999879, 97999919, 97999927, 97999943, 97999949]
- [979999817,979999849,979999883,979999903,979999907,979999913,979999957,979999973,979999981]
- # остаток до 100: (19, 89) - 7%, (145, 89) - 8%, ('9%', (14, 89)
- """
- from multiprocessing import Process, Queue
- t = time.clock()
- n = 1000000
- l = []; sk = []; rk = []
- def Cry_test(clst):
- if type(clst) is list: lst = clst
- else:
- lst = clst.get()
- for i in range(n):
- if i%1000 == 0: print (i)
- a,b,c = cry_test(secure)
- lst.append(a)
- ## sk.append(b)
- ## rk.append(c)
- Cry_test(l)
- print(time.clock() - t)
- na = numpy.array(l)
- unique, counts = numpy.unique(na, return_counts=True)
- print(l[:10])
- print('productive ', len(counts)/n*100,'%')
- print(len([i for i in counts if i>0]))
- print('efective: ', (n-max(counts))/n*100, ' %')
- data_rez = ({k:v for k,v in dict(zip(unique, counts)).items() if v>15})
- print(len(data_rez.keys()))
- print(data_rez)
- fl_name = 'last.data'
- if os.path.exists(fl_name):
- with open(fl_name, 'rb') as fl:
- data_last = pickle.load(fl)
- print('last data: ', data_last)
- keys = set(data_rez.keys()) & set(data_last.keys())
- rdata = { (data_last[k]+data_rez[k]):k for k in keys}
- od = OrderedDict()
- for k in sorted(rdata.keys()):
- od[k]=rdata[k]
- print(od)
- with open(fl_name, 'wb') as fl:
- pickle.dump(data_rez, fl)
- ## allotment = ([l.count(c) for c in range(n)]) #
- ##
- ## print(max(allotment))
- # print(l.count(1)) # params[1]
- # print [sk.count(c) for c in range(params[1])]
- # print [rk.count(c) for c in range(params[1])]
- print (time.clock() - t)
- test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement