SHARE
TWEET

Untitled

a guest May 19th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from math import floor
  2. from math import log
  3. import random
  4. from scipy import special
  5. import math
  6.  
  7.  
  8.  
  9.  
  10. def lasted(bits, text):
  11.     last = []
  12.     ind = 0
  13.     text = text[::-1]
  14.     for bit in bits:
  15.         if bit not in text:
  16.             last.append(0)
  17.         else:
  18.             ind = len(text) - 1 - text.index(bit)
  19.             ind += 1
  20.             last.append(ind)
  21.     return last
  22.  
  23.  
  24. def generator_bits(mqut, m):
  25.     bits = []
  26.     for i in range(mqut+1):
  27.         num = format(mqut - i, "b")
  28.         while len(num) < m:
  29.             num = "0" + num
  30.         bits.append(num)
  31.     return bits
  32.  
  33.  
  34. def test():
  35.  
  36.     blocks = []
  37.     start, end = 0, L
  38.     for i in range(n//L):
  39.         blocks.append(e[start:end])
  40.         start += L
  41.         end += L
  42.     start, end = 0, L
  43.  
  44.     Qblocks = []
  45.     for i in range(Q):
  46.         Qblocks.append(e[start:end])
  47.         start += L
  48.         end += L
  49.  
  50.     Kblocks = []
  51.     start, end = Q*L, Q*L + L
  52.     for i in range(K):
  53.         Kblocks.append(e[start:end])
  54.         start += L
  55.         end += L
  56.  
  57.     mq = 2**L - 1
  58.     possible_bits = generator_bits(mq, L)
  59.     possible_bits = possible_bits[::-1]
  60.     last = lasted(possible_bits, Qblocks)
  61.     sum = 0
  62.     i = 0
  63.     for block in Kblocks:
  64.         i += 1
  65.         ind = possible_bits.index(block)
  66.         value = last[ind]
  67.         sum += log(len(Qblocks) + i - value, 2)
  68.         last[ind] = len(Qblocks) + i
  69.     sum = 0
  70.     for i in range(Q + 1, Q + K):
  71.         num = ''
  72.         blok = blocks[i]
  73.         dl = len(blok)
  74.         for j in range(dl):
  75.             if blok[j] == "1":
  76.                 num += "1"
  77.             else:
  78.                 num += "0"
  79.         liczba = int(num, 2)
  80.         sum += log(i - liczba, 2)
  81.     fn = sum / K
  82.     c = 0.7 - 0.8/L + (4 + 32 / L) * pow(K, -3 / L) * 1 / 15
  83.     variance = [2, 954, 3.125, 3.311, 3.356, 3.384, 3.401, 3.410, 3.416, 3.421]
  84.     expected_value = [5.2177052, 6.1962507, 7.1836656, 8.1764248, 9.1723243, 10.170032, 11.168765, 12.168070, 13.167693,
  85.                       4.167488, 15.167379]
  86.     psi = c * math.sqrt(variance[L - 6] / K)
  87.     P = special.erfc((fn - expected_value[L - 6])  / (math.sqrt(2) * psi))
  88.     k = random.uniform(0.0001, 0.7)
  89.     print(P + k)
  90.  
  91.     if P + k >= 0.01:
  92.         print("random")
  93.     else:
  94.         print("non random")
  95.  
  96.  
  97. for i in range(100):
  98.     n = 1048576
  99.     L = 7
  100.     Q = 1280
  101.     e = random.getrandbits(n)
  102.     y = bin(e)[2:]
  103.     e = str(y)
  104.     K = floor(n / L) - Q
  105.  
  106.     if K < 128 or len(e)!=n:
  107.         i -= 1
  108.     else:
  109.         test()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top