from Crypto.Util.number import getPrime, bytes_to_long from random import randint import os
FLAG = os.getenv("FLAG").encode() flag1 = FLAG[:15] flag2 = FLAG[15:]
defcrypto1(): p = getPrime(1024) q = getPrime(1024) n = p * q e = 0x10001 x1=randint(0,2**11) y1=randint(0,2**114) x2=randint(0,2**11) y2=randint(0,2**514) hint1=x1*p+y1*q-0x114 hint2=x2*p+y2*q-0x514 c = pow(bytes_to_long(flag1), e, n) print(n) print(c) print(hint1) print(hint2)
defcrypto2(): p = getPrime(1024) q = getPrime(1024) n = p * q e = 0x10001 hint = pow(514*p - 114*q, n - p - q, n) c = pow(bytes_to_long(flag2),e,n) print(n) print(c) print(hint) print("==================================================================") crypto1() print("==================================================================") crypto2() print("==================================================================")
import os from Crypto.Util.number import * defgiaogiao(hex_string): base_num = 0x6c62272e07bb014262b821756295c58d x = 0x0000000001000000000000000000013b MOD = 2**128 for i in hex_string: base_num = (base_num * x) & (MOD - 1) base_num ^= i return base_num
giao=201431453607244229943761366749810895688
print("1geiwoligiaogiao") hex_string = int(input(),16) s = long_to_bytes(hex_string)
if giaogiao(s) == giao: print(os.getenv('FLAG')) else: print("error")
from Crypto.Util.number import bytes_to_long, long_to_bytes, inverse, isPrime from gmpy2 import iroot, gcd from tqdm import trange import itertools import sys
b0 = 0x6c62272e07bb014262b821756295c58d x = 0x0000000001000000000000000000013b giao=201431453607244229943761366749810895688 MOD = 2**128
for num in trange(1, 50): #num为可能的明文长度 B = [giao] tmp, S = [], [] for i inrange(num - 1, -1, -1): tmp.append(x ^ i) tmp.append(b0 * x ^ num - giao) L = block_matrix([[identity_matrix(num + 1), Matrix(ZZ, num + 1, 1, tmp)], [Matrix(ZZ, 1, num + 1), MOD]]) Q = diagonal_matrix(ZZ, [1] * num + [128] + [2 ^ 128]) L = L * Q res = L.BKZ() for j in res: ifabs(j[-2]) == 128and j[-1] == 0: if j[-2] == 128: my = j[:-2:] for w inrange(len(my) - 1, -1, -1): tmp_b = (B[-1] - my[w]) * inverse(x, MOD) % MOD B.append(tmp_b) S.append(((tmp_b * x) ^^ B[-2]) % MOD) #这个注意还是要限制在模的意义下,比赛那时候就是忘记了导致格一直打不出来 ifall(0 <= w <= 256for w in S): print(bytes(S[::-1]).hex()) # sys.exit() elif j[-2] == -128: my = [-lll for lll in j[:-2:]] for w inrange(len(my) - 1, -1, -1): tmp_b = (B[-1] - my[w]) * inverse(x, MOD) % MOD B.append(tmp_b) S.append(((tmp_b * x) ^^ B[-2]) % MOD) #这个注意还是要限制在模的意义下,比赛那时候就是忘记了导致格一直打不出来 ifall(0 <= w <= 256for w in S): print(bytes(S[::-1]).hex()) # sys.exit()