Advertisement
nicoviale_

Untitled

Mar 20th, 2024 (edited)
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. from pwn import *
  2. from randcrack import RandCrack
  3.  
  4. io=remote("fixedmersenne.chall.srdnlen.it", 443, ssl=True)
  5.  
  6. io.recvuntil("try to break this by guessing the number I will generate after these ones:")
  7.  
  8. full_numbers=[]
  9.  
  10. for _ in range(4):
  11.     io.recvuntil("|  ")
  12.     full_numbers.append(int(io.recvline().strip()))
  13.  
  14.  
  15.  
  16. #convert said numbers in binary
  17. binary_numbers = [bin(number)[2:] for number in full_numbers]
  18.  
  19. strings_of_binaries_until_4991 = [number.zfill(4991) for number in binary_numbers]
  20.  
  21. for binary in strings_of_binaries_until_4991:
  22.     print(len(binary))
  23.  
  24. #split the binary strings in 32 bits chunks
  25. """  
  26. chunks = []
  27. for i in range (4):
  28.    for j in range(4960, 0 , -32):
  29.        chunks.append(strings_of_binaries_until_4991[i][j-32:j])
  30.    chunks.append(strings_of_binaries_until_4991[i][:31])
  31. """      
  32. #generate all combinations of 4 bits
  33. import itertools
  34. all_combinations = list(itertools.product([0, 1], repeat=4))
  35.  
  36. #make 16 new chunk_arrays adding one of every 4th bit to the left of the elements in positions multiple of 156 or 155 if starting from 0
  37. chunk_arrays = []
  38. for combination in all_combinations:
  39.     chunks = []
  40.     for i in range (4):
  41.         #print(combination[i])
  42.  
  43.        
  44.        
  45.         for j in range(0, 4960 , 32):
  46.             chunks.append(int(strings_of_binaries_until_4991[i][j:j+32], 2))
  47.  
  48.         #add the last one filling it
  49.         chunks.append( int((strings_of_binaries_until_4991[i][-31:])+str(combination[i]), 2))
  50.        
  51.  
  52.     chunk_arrays.append(chunks)
  53.  
  54. predictions = []
  55.  
  56. predictions = []
  57. for chunk_array in chunk_arrays:
  58.     rc = RandCrack()
  59.     for chunk in chunk_array:
  60.         rc.submit(chunk)
  61.     predictions.append(rc.predict_getrandbits(624 * 8 - 1))
  62.  
  63. print(predictions)
  64.  
  65.  
  66. i=0
  67. for prediction in predictions:
  68.     print(i)
  69.     i+=1
  70.     io.recvuntil(">>> ")
  71.     io.sendline(str(prediction))
  72.     risposta=io.recvline()
  73.     if(b"Nope" not in risposta):
  74.         print(risposta)
  75.         break
  76.  
  77. io.interactive()
  78.  
  79. io.close()
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement