import hashlib import random import string from Crypto.Util.number import bytes_to_long, getPrime from secret import flag
defproof_of_work(): s = "".join(random.sample(string.ascii_letters + string.digits, 20)) prefix = s[:4] print("sha256(xxxx + %s) == %s " % (s[4:], hashlib.sha256(s.encode()).hexdigest())) ans = input("Give me xxxx:").strip() iflen(ans) == 4and ans == prefix: returnTrue else: returnFalse
BITS = 512 UNKNOWN_BITS = 209
if __name__ == "__main__": ifnot proof_of_work(): exit(0)
m = bytes_to_long(flag.encode()) p = getPrime(BITS) q = getPrime(BITS) n = p*q e = 0x10001 c = pow(m, e, n)
print(n) print(c)
ans = input("Give me flag:").strip() if ans == flag: print('Cheater!') exit(0) print("Wrong!")
print("But can I help you with some part of p?") print("1. Yes, can, can, need!") print("2. No, thank you.") opt = input().strip() if opt == '1': print(p >> UNKNOWN_BITS) ans = input("Now give me flag:").strip() if ans == flag: print("Success!") else: print("Wrong!") else: print("Bye")
exp1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import hashlib import random import string from Crypto.Util.number import bytes_to_long, getPrime from secret import *
p = "".join(random.sample(string.ascii_letters + string.digits, 4)) p2=p+"pQCyZx63PwzAqvn1" s = hashlib.sha256(p2.encode()).hexdigest() while s!="c46336b53554bc39b3bc63aad4474a4ab714039dab35f77595e7f5e5060e6636": p = "".join(random.sample(string.ascii_letters + string.digits, 4)) p2=p+"pQCyZx63PwzAqvn1" s = hashlib.sha256(p2.encode()).hexdigest() # s = "".join(random.sample(string.ascii_letters + string.digits, 4)) # prefix = s[:4] # hashlib.sha256(s.encode()).hexdigest() print(s) print(p)
exp2:求p
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
from sage.allimport * n =82212254497904947665149102513251405705479967930009481859905256645581626201426522544604397443256577540757570698901154519712601424569578579724704032952003372427544379650204925510411735586757460620658423602786408830706374024321117921997478547757745751221661535934681818365428789289484990903284626922746096723797 p4=10345341890692903415019083428257191470120154024503374064162101187141047480401937826546305014 e = 0x10001 pbits = 512 kbits = pbits - p4.nbits() print(p4.nbits()) p4 = p4 << kbits PR.<x> = PolynomialRing(Zmod(n)) f = x + p4 roots = f.small_roots(X=2^kbits, beta=0.4) if roots: p = p4+int(roots[0]) print ("n: ", n) print ("p: ", p) print ("q: ", n/p)
exp3:解m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import hashlib import random import string from Crypto.Util.number import bytes_to_long, getPrime from secret import *
p = "".join(random.sample(string.ascii_letters + string.digits, 4)) p2=p+"rdPhgxVFpGKu3QWA" s = hashlib.sha256(p2.encode()).hexdigest() while s!="0e4f516f8b205ce622643b138465df283b873c5dd7e571e72782a3be3dfb113d": p = "".join(random.sample(string.ascii_letters + string.digits, 4)) p2=p+"rdPhgxVFpGKu3QWA" s = hashlib.sha256(p2.encode()).hexdigest() # s = "".join(random.sample(string.ascii_letters + string.digits, 4)) # prefix = s[:4] # hashlib.sha256(s.encode()).hexdigest() print(s) print(p)
from Crypto.Util.number import * from flag import flag
m = bytes_to_long(flag) p, q = getPrime(32), getPrime(1024) n = p * q e = 0x3
c = pow(m, e, n) print("c = %d" %c) print("n = %d" %n)
""" c = 165527641537962453158385346595580222293326378381594431827597366486166401160303849028319637296466564187067059992600278363170882182385646208386765262608536513136513222747556263528436428933807161852842186912918227517362704487324744539937359952905722677507738750871327455083935808647964763470500287612530277 n = 345675713266547546727997788631735009412387157990066144394619901220478972853548799919916572067895437774688186483367134372170356307628474622726432885853473078843359790348707975349499704660462018761449242448381765593725869513432095247724237852265875808599860098758473511684359800791176948572617684399894397044344654638787 """
exp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import gmpy2 import binascii
n = 345675713266547546727997788631735009412387157990066144394619901220478972853548799919916572067895437774688186483367134372170356307628474622726432885853473078843359790348707975349499704660462018761449242448381765593725869513432095247724237852265875808599860098758473511684359800791176948572617684399894397044344654638787 e = 0x3 c = 165527641537962453158385346595580222293326378381594431827597366486166401160303849028319637296466564187067059992600278363170882182385646208386765262608536513136513222747556263528436428933807161852842186912918227517362704487324744539937359952905722677507738750871327455083935808647964763470500287612530277
i = 0 whileTrue: if gmpy2.iroot((c+i*n),3)[1] == True: m = gmpy2.iroot((c+i*n),3)[0] break i += 1
""" c = 49390162755988534272839928189991825891307784475755681388594697611101453362175250775346123763727149792590904709709554866101928772410626273560395694701931925004491665335392802508387050154913787966731787005845054735401376590684545817872728193152896069447282539090781054295392440108754707061288239561284988053345 d = 596339328004701220895674615970487087143840236892412545268109179554413648178156984971303333524689454052342226732334953464364267428945022850108842486057591229295824078053706083822155009310809557722688312434219946602472705063768084789766044292413211122657306229335083834655999999554553242732078756654198918122 n = 77314125696229681333016473406246908467153031859976342194334463502388936222852372550077757802586691889670331381517380504834898109774025642982360455012376588512613635110670341910089851243026132252968232462722302427873254832544089214984924968229850007931672798652990253526875411677891469374519638759569863162731 """
exp
拼接两位
循环解出m遍历一下dino/flag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import gmpy2 from Crypto.Util.number import * c = 49390162755988534272839928189991825891307784475755681388594697611101453362175250775346123763727149792590904709709554866101928772410626273560395694701931925004491665335392802508387050154913787966731787005845054735401376590684545817872728193152896069447282539090781054295392440108754707061288239561284988053345 # d = "596339328004701220895674615970487087143840236892412545268109179554413648178156984971303333524689454052342226732334953464364267428945022850108842486057591229295824078053706083822155009310809557722688312434219946602472705063768084789766044292413211122657306229335083834655999999554553242732078756654198918122" n = 77314125696229681333016473406246908467153031859976342194334463502388936222852372550077757802586691889670331381517380504834898109774025642982360455012376588512613635110670341910089851243026132252968232462722302427873254832544089214984924968229850007931672798652990253526875411677891469374519638759569863162731 e = 0x10001 d = "596339328004701220895674615970487087143840236892412545268109179554413648178156984971303333524689454052342226732334953464364267428945022850108842486057591229295824078053706083822155009310809557722688312434219946602472705063768084789766044292413211122657306229335083834655999999554553242732078756654198918122" i=0 while(i<10): j=0 while(j<10): d1=int(d+str(i)+str(j)) m = gmpy2.powmod(c, d1, n) # 解密 m = long_to_bytes(m) j += 1 print(m) # print(d1) i+=1