whileTrue: a = getRandomNBitInteger(dbits) b = getRandomNBitInteger(bbits) c = getRandomNBitInteger(bbits) p1 = a * b * c + 1 if isPrime(p1): # print("p1 =", p1) break
whileTrue: d = getRandomNBitInteger(dbits) p2 = b * c * d + 1 if isPrime(p2): # print("p2 =", p2) break
whileTrue: e = getRandomNBitInteger(bbits) f = getRandomNBitInteger(bbits) q1 = e * d * f + 1 p3 = a * e * f + 1 if isPrime(q1) and isPrime(p3): # print("p3 =", p3) # print("q1 =", q1) break
whileTrue: d_ = getRandomNBitInteger(dbits) if GCD(a * b * c * d * e * f, d_) != 1: continue e_ = inverse(d_, a * b * c * d * e * f) k1 = (e_ * d_ - 1) // (a * b * c * d * e * f) assert e_ * d_ == (a * b * c * d * e * f) * k1 + 1 q2 = k1 * e * f + 1 q3 = k1 * b * c + 1 if isPrime(q2) and isPrime(q3): # print("q2 =", q2) # print("q3 =", q3) # print("e =", e_) # print("d =", d_) break
from hashlib import sha256 from Crypto.Util.number import *
p = 308955606868885551120230861462612873078105583047156930179459717798715109629 c = 8308943029741424587523612386337754255889681699670071706719724435165094611096603769021839263 A = B =
A = matrix(GF(p),A) B = matrix(GF(p),B) A = A.transpose()
shared = (A*B).trace() m = c ^^ int(sha256(str(int(shared)).encode()).hexdigest(), 16) print(long_to_bytes(m))
#!/usr/bin/env python3 from Crypto.Util.number import ( bytes_to_long, long_to_bytes ) from hashlib import md5 import os, signal import sys import random
BITS = 128
classClawCrane(object): def__init__(self) -> None: self.seed = bytes_to_long(os.urandom(BITS//8)) self.bless = 0 self.score = 0 defget_input(self, prompt="> "): print(prompt, end="") sys.stdout.flush() returninput() defcheck_pos(self, pos, moves): col, row = 0, 0 for move in moves: if move == "W": if row < 15: row += 1 elif move == "S": if row > 0: row -= 1 elif move == "A": if col > 0: col -= 1 elif move == "D": if col < 15: col += 1 else: return -1 print(col, row) return pos == [col, row] defgen_chaos(self, inp): defmapping(x): if x=='W': return"0" if x=='S': return"1" if x=='A': return"2" if x=='D': return"3" vs = int("".join(map(mapping, inp)), 4) chaos = bytes_to_long(md5( long_to_bytes((self.seed + vs) % pow(2,BITS)) ).digest()) self.seed = (self.seed + chaos + 1) % pow(2,BITS) return chaos defdestiny_claw(self, delta): bits = bin(delta)[2:] iflen(bits) < 128+self.bless: bits += "0"*(128+self.bless - len(bits)) c = random.choice(bits) if c=='0': returnTrue else: returnFalse defrun(self): pos = [random.randrange(1,16), random.randrange(1,16)] moves = self.get_input(f"i am at {pos}, claw me.\nYour moves: ") iflen(moves) > 100: print("too many steps") return ifnot self.check_pos(pos, moves): print("sorry, clawed nothing") return r = self.gen_chaos(moves[:64]) print(f"choas: {r}") p, q = map(int, self.get_input(f"give me your claw using p,q and p,q in [0, 18446744073709551615] (e.g.: 1,1): ").split(",")) ifnot (p>0and p<pow(2,BITS//2) and q>0and q<pow(2,BITS//2)): print("not in range") return delta = abs(r*q - p*pow(2,BITS)) if self.destiny_claw(delta): self.score += 10 self.bless = 0 print("you clawed it") else: self.bless += 16 print("sorry, clawed nothing")
from Crypto.Util.number import * from pwn import * from tqdm import * from hashlib import sha1
#context.log_level = 'debug'
defproof_of_work(): table = "0123456789abcdef" temp = sh.recvuntil(b"sha1(prefix+") temp = sh.recvline().strip().decode() suffix = temp[1:59] hex1 = temp[-40:] for i in tqdm(table): for j in table: for k in table: for m in table: for o in table: for p in table: temp1 = i+j+k+m+o+p if(sha1((temp1+suffix).encode()).hexdigest() == hex1): sh.sendline(temp1.encode()) return average = 0 count = 0 while(1): count += 1 K = 2**128 #sh = remote("120.46.65.156",19991) sh = remote("152.136.172.227",22222) proof_of_work()
for i in trange(256): sh.recvuntil(b" am at ") pos = eval(sh.recvline().strip().decode().split("]")[0][1:]) move = b"W" * 15 + b"S" * 15 + b"W" * pos[1] + b"D" * pos[0] sh.sendline(move) sh.recvuntil(b"choas: ") r = int(sh.recvline().strip().decode()) q = 2**63 shift = len(bin(r)[2:]) - 65 - 1 p = (r >> 65) &((1<<shift)-1) sh.recvuntil(b"(e.g.: 1,1):") sh.sendline(str(p).encode() + b"," + str(q).encode()) sh.recvline() temp = sh.recvline().strip().decode() average += int(temp[-4:]) print(temp,"average =",average // count) if("22"in temp): print(sh.recvline().strip().decode()) break sh.close()
whileTrue: a = getRandomNBitInteger(dbits) b = getRandomNBitInteger(bbits) c = getRandomNBitInteger(bbits) p1 = a * b * c + 1 if isPrime(p1): # print("p1 =", p1) break
whileTrue: d = getRandomNBitInteger(dbits) p2 = b * c * d + 1 if isPrime(p2): # print("p2 =", p2) break
whileTrue: e = getRandomNBitInteger(bbits) f = getRandomNBitInteger(bbits) q1 = e * d * f + 1 p3 = a * e * f + 1 if isPrime(q1) and isPrime(p3): # print("p3 =", p3) # print("q1 =", q1) break
whileTrue: d_ = getRandomNBitInteger(dbits) if GCD(a * b * c * d * e * f, d_) != 1: continue e_ = inverse(d_, a * b * c * d * e * f) k1 = (e_ * d_ - 1) // (a * b * c * d * e * f) assert e_ * d_ == (a * b * c * d * e * f) * k1 + 1 q2 = k1 * e * f + 1 q3 = k1 * b * c + 1 if isPrime(q2) and isPrime(q3): # print("q2 =", q2) # print("q3 =", q3) # print("e =", e_) print("d =", d_) break
assertlen(YourDecode) <= 127and YourDecode.startswith(b'Dear guest, welcome to CRCRC Magic House, If you input ') and YourDecode.endswith(b", you will get 0x9c6a11fbc0e97b1fff5844fa88b1ee2d")
#Basic Matrix Affine_Matrix = [] for i inrange(target_bits): v = vector(GF(2), (j == i for j inrange(target_bits))) value = crc_func(long_to_bytes(v2n(v),bytes_num)) ^^ zero_crc Affine_Matrix.append(n2v(value)) Affine_Matrix=matrix(GF(2),Affine_Matrix).transpose()
#Add constraints for i inrange(bytes_num): v,w = [0]*target_bits,[0]*target_bits v[i*8],w[i*8+1]=1,1 v = vector(GF(2), v) w = vector(GF(2), w) Affine_Matrix = Affine_Matrix.stack(v) Affine_Matrix = Affine_Matrix.stack(w) return Affine_Matrix, n2v(zero_crc)
defcrc_128_reverse(crc_value,bytes_num): M , C = equivalent_affine_crc(crc128_,128,bytes_num) v2n = lambda v: int(''.join(map(str, v)), 2) n2v = lambda n: vector(GF(2), bin(n)[2:].zfill(128)) x = list(n2v(crc_value) + C) + [0,1]*bytes_num x = vector(GF(2),x) res = M.solve_right(x) bas = M.right_kernel()
#Find solution for i in trange(len(bas)): tr = res+bas[i] s = long_to_bytes(v2n(tr)) if re.fullmatch(b'[A-Za-z0-9+/]*', s): if(check(s)): print(c1 + s + c2)