import re import random from secrets import flag print(f'Can you weight a 128 bits number in 21 steps') pattern = r'([AB]|\d+)=([AB]|\d+)(\+|\-|\*|//|<<|>>|&|\^|%)([AB]|\d+)'
command = input().strip() assert command[-1] == ';' assert all([re.fullmatch(pattern, i) for i in command[:-1].split(';')])
step = 21 for i in command[:-1].split(';'): t = i.translate(str.maketrans('', '', '=AB0123456789')) if t in ['>>', '<<', '+', '-', '&', '^']: step -= 1 elif t in ['*', '/', '%']: step -= 3 if step < 0:exit()
success = 0 w = lambda x: sum([int(i) for i in list(bin(x)[2:])]) for _ in range(100): A = random.randrange(0, 2**128) wa = w(A) B = 0 try : exec("global A; global B;" + command) except : exit() if A == wa: success += 1
from Crypto.Util.number import * from pwn import *
def popcountRE(A): B = 0 B = A >> 1 B = B & 113427455640312821154458202477256070485 A = A - B #x -= (x >> 1) & 0x55555555555555555555555555555555 B = A >> 2 B = B & 68056473384187692692674921486353642291 A = A & 68056473384187692692674921486353642291 A = A + B #x = (x & 0x33333333333333333333333333333333) + ((x >> 2) & 0x33333333333333333333333333333333) B = A >> 4 A = A + B A = A & 20016609818878733144904388672456953615 #x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f A = A * 1334440654591915542993625911497130241 A = A & 340282366920938463463374607431768211455 A = A >> 120 #return ((x * 0x01010101010101010101010101010101) & 0xffffffffffffffffffffffffffffffff) >> 120 return A
sh = remote("47.94.195.201", 38958) sh.recvuntil(b'Can you weight a 128bits number in 21 steps') sh.sendline(command.encode()) print(sh.recvline()) print(sh.recvline())