from Crypto.Util.number import * from secret import flag
deffakeN_list(): puzzle_list = []
for i inrange(15): r = getPrime(32) puzzle_list.append(r)
p = getPrime(32) q = getPrime(32) com = p*q puzzle_list.append(com)
return puzzle_list
defencrypt(m, e, fake_n_list): fake_n = 1 for i inrange(len(fake_n_list)): fake_n *= fake_n_list[i] really_n = 1 for i inrange(len(fake_n_list)-1): really_n *= fake_n_list[i]
c = pow(m, e, really_n) print("c =", c) print("fake_n =", fake_n)
if __name__ == '__main__': m = bytes_to_long(flag) e = 65537 fake_n_list = fakeN_list() encrypt(m, e, fake_n_list)
''' c = 6451324417011540096371899193595274967584961629958072589442231753539333785715373417620914700292158431998640787575661170945478654203892533418902 fake_n = 178981104694777551556050210788105224912858808489844293395656882292972328450647023459180992923023126555636398409062602947287270007964052060975137318172446309766581 '''
for primes in combinations(fake_n_list, len(fake_n_list)-2): n = 1 for p in primes: n *= p phi = 1 for p in primes: phi *= p-1 d = inverse(e, phi) m = pow(c, d, n) try: print(long_to_bytes(m).decode()) except: pass
from string import ascii_uppercase from itertools import product from tqdm import tqdm import numpy as np
ls = ascii_uppercase + '_.*'
defstr2mat(s): res = np.zeros((len(s) // 6, 6), dtype=int) for i inrange(0, len(s)): res[i // 6, i % 6] = ls.index(s[i]) return res
deflinedot(a, b): return [sum([a[j][i] * b[i] for i inrange(len(b))]) % 29for j inrange(len(a))]
if __name__ == "__main__": m = str2mat("VOWAS*TED.AE_UMLVFV*W*HSSSTZIZZZDAKCLXZKM_E*VR*Y") c = str2mat("QLOKQGUWMUTGZSDINCQVIVOLISFB_FC.IC_OSPLOBGOVSCZY")
for x in tqdm(range(6)): for key in tqdm(product(range(29), repeat=6), total=len(ls)**6, leave=False): a = linedot(m, key) s = [(a[i] - c[i][x]) % 29for i inrange(8)] iflen(set(s)) == 1: print('', x, key, sep="\n") break
for x in tqdm(range(12)): c = list(ciphertext[x, :]) repeat = 6 for plain in tqdm(product(range(29), repeat=repeat), total=len(ls)**repeat): # plain = (,) + plain r = linedot(plain, k1, k2) ifsum([r[i] == c[i] for i inrange(6)]) == 6: print(x, list2str(plain), plain) break
classPAD(): def__init__(self, m: int, e): self.e, self.m, self.mbits = e, m, m.bit_length() if e == 0: self.e = getRandomRange(1, 9) defPAD(self): self.M = pow(self.e, self.mbits) + pow(self.m, self.e)
GIFT = bytes_to_long(flag) withopen("GIFT.txt", "w") as f: for i inrange(100): rsa = RSA(m=GIFT) rsa.Encrypt() data = rsa.Publickey() if data[1]*data[2][0] <= 2: continue f.write(str(data) + "\n")
from Crypto.Util.number import long_to_bytes from functools import reduce import gmpy2
defCRT(mi: list, ai: list) -> int: M = reduce(lambda x, y: x * y, mi) ai_ti_Mi = [a * (M // m) * gmpy2.invert(M // m, m) for (m, a) inzip(mi, ai)] return reduce(lambda x, y: x + y, ai_ti_Mi) % M
e = 3 ns=[4205338792881421548510609645647062608905484696099258750943039118994520455106270839395319116980996505132271552239717225130972438536887110724158402296232289, 7050174313884434729593139368893291621548368062755985279847850232740992709140864927641348128276777490337461431355020263819014375471971053422267553276559149, 7695312868320303154724182556869744062740975850081486948529306458791551745279043014584922518803724721857725624240269226703220670466322322864253572576548333] cs=[590242556810530557883636062945321456666605165279521102134969558150863508014273375308372904949297413593224978273122299933502842450872249868557340596692448, 2893746834891731849952475353675823291920101887211621827992533553019484178344684430992593454765874180526901317935813716254980891868014768672217101779002964, 4853546005581242275031566639028865993927807758919394191424484984623935750674499388240409403735193793296025751636464209778684176500380928091202873126090673]
m = gmpy2.iroot(CRT(ns, cs), e)[0] print(long_to_bytes(m))
plain = '' for i inrange(len(enc)): if key[i % len(key)] != 0x00: c = chr(enc[i] ^ key[i % len(key)]) plain += c.upper() if c.islower() else c.lower() else: plain += ' ' + hex(enc[i])[2:].rjust(2, '0') + ' ' if i % len(key) == len(key)-1: plain += '\n'
print(base64.b64decode(plain).decode())
我玩青水的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from Crypto.Util.number import * from secret import flag
m = bytes_to_long(flag) e = 2 p = getPrime(512) c = pow(m, e, p)
print(f"p = {p}") print(f"c = {c}")
''' p = 7709388356791362098686964537734555579863438117190798798028727762878684782880904322549856912344789781854618283939002621383390230228555920884200579836394161 c = 5573755468949553624452023926839820294500672937008992680281196534187840615851844091682946567434189657243627735469507175898662317628420037437385814152733456 '''
二次剩余定理。没事,我也还没学过,现学的:
1 2 3 4 5 6 7 8 9 10
from Crypto.Util.number import long_to_bytes from sympy import legendre_symbol, sqrt_mod
p = 7709388356791362098686964537734555579863438117190798798028727762878684782880904322549856912344789781854618283939002621383390230228555920884200579836394161 c = 5573755468949553624452023926839820294500672937008992680281196534187840615851844091682946567434189657243627735469507175898662317628420037437385814152733456
assert legendre_symbol(c, p) == 1
m = sqrt_mod(c, p) print(long_to_bytes(m).decode())