Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pwn import *
- from randcrack import RandCrack
- io=remote("fixedmersenne.chall.srdnlen.it", 443, ssl=True)
- io.recvuntil("try to break this by guessing the number I will generate after these ones:")
- full_numbers=[]
- for _ in range(4):
- io.recvuntil("| ")
- full_numbers.append(int(io.recvline().strip()))
- #convert said numbers in binary
- binary_numbers = [bin(number)[2:] for number in full_numbers]
- strings_of_binaries_until_4991 = [number.zfill(4991) for number in binary_numbers]
- for binary in strings_of_binaries_until_4991:
- print(len(binary))
- #split the binary strings in 32 bits chunks
- """
- chunks = []
- for i in range (4):
- for j in range(4960, 0 , -32):
- chunks.append(strings_of_binaries_until_4991[i][j-32:j])
- chunks.append(strings_of_binaries_until_4991[i][:31])
- """
- #generate all combinations of 4 bits
- import itertools
- all_combinations = list(itertools.product([0, 1], repeat=4))
- #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
- chunk_arrays = []
- for combination in all_combinations:
- chunks = []
- for i in range (4):
- #print(combination[i])
- for j in range(0, 4960 , 32):
- chunks.append(int(strings_of_binaries_until_4991[i][j:j+32], 2))
- #add the last one filling it
- chunks.append( int((strings_of_binaries_until_4991[i][-31:])+str(combination[i]), 2))
- chunk_arrays.append(chunks)
- predictions = []
- predictions = []
- for chunk_array in chunk_arrays:
- rc = RandCrack()
- for chunk in chunk_array:
- rc.submit(chunk)
- predictions.append(rc.predict_getrandbits(624 * 8 - 1))
- print(predictions)
- i=0
- for prediction in predictions:
- print(i)
- i+=1
- io.recvuntil(">>> ")
- io.sendline(str(prediction))
- risposta=io.recvline()
- if(b"Nope" not in risposta):
- print(risposta)
- break
- io.interactive()
- io.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement