Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. from chacha20 import *
  2. from os import urandom
  3. from math import log
  4.  
  5. for rounds in range(0,21,2):
  6.     count = 0
  7.     for _ in range(0xffff):
  8.         key = urandom(32)
  9.         key1 = bytes([rot_left(key[i],1) % 0xff for i in range(len(key))])
  10.         nonce = urandom(8)
  11.         chacha1 = ChaCha20(key,nonce,rounds = rounds)
  12.         chacha2 = ChaCha20(key1,nonce,rounds = rounds)
  13.         s1, s2 = chacha1.retrieve_stream(), chacha2.retrieve_stream()
  14.         if rot_left(s1[0],1) == s2[0]:
  15.             count = count + 1
  16.     try:
  17.         print("With {} rounds: 2^({}), {} positive".format(str(rounds),str(log(count/0xffff)),str(count)))
  18.     except:
  19.         continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement