for i1 in table: print i1 for i2 in table: for i3 in table: for i4 in table: for i5 in table: for i6 in table: key = encode(i1+i2+i3+i4+i5+i6) des = DES.new(key, DES.MODE_ECB) flag = des.decrypt(cip2.decode('hex')) if'DASCTF{'in flag: print flag print key raw_input()
for i in range(len(md5s)): for x in range(32, 128): m = hashlib.md5(chr(x)) tmp = m.hexdigest() m = hashlib.md5(tmp) tmp = m.hexdigest() #print tmp,chr(x) if tmp == md5s[i]: plaintext += chr(x)
import tarfile from flask import Flask, render_template, request, redirect from hashlib import md5 import yaml import os import re
app = Flask(__name__)
defwaf(s): flag = True blacklist = ['bytes','eval','map','frozenset','popen','tuple','exec','\\','object','listitems','subprocess','object','apply'] for no in blacklist: if no.lower() in str(s).lower(): flag= False print(no) break return flag defextractFile(filepath, type):
defget_key(a, nbit): assert a >= 2 whileTrue: X = getRandomInteger(nbit // a) s = getRandomRange(pow(2, a ** 2 - a + 4), pow(2, a ** 2 - a + 5)) p = X ** a + s if isPrime(p): return (p, s)
a=5 p, s = get_key(a, 1024) q, t = get_key(a, 1024)
print(p,q,s,t) N = p * q e = s * t #c = pow(m, e, N) print("N =", N) print("e =", e) #print("c =", c) # N = 20289788565671012003324307131062103060859990244423187333725116068731043744218295859587498278382150779775620675092152011336913225797849717782573829179765649320271927359983554162082141908877255319715400550981462988869084618816967398571437725114356308935833701495015311197958172878812521403732038749414005661189594761246154666465178024563227666440066723650451362032162000998737626370987794816660694178305939474922064726534186386488052827919792122844587807300048430756990391177266977583227470089929347969731703368720788359127837289988944365786283419724178187242169399457608505627145016468888402441344333481249304670223 # e = 11079917583 # c = 13354219204055754230025847310134936965811370208880054443449019813095522768684299807719787421318648141224402269593016895821181312342830493800652737679627324687428327297369122017160142465940412477792023917546122283870042482432790385644640286392037986185997262289003477817675380787176650410819568815448960281666117602590863047680652856789877783422272330706693947399620261349458556870056095723068536573904350085124198592111773470010262148170379730937529246069218004969402885134027857991552224816835834207152308645148250837667184968030600819179396545349582556181916861808402629154688779221034610013350165801919342549766
from gmpy2 import * from sympy import isprime n=20289788565671012003324307131062103060859990244423187333725116068731043744218295859587498278382150779775620675092152011336913225797849717782573829179765649320271927359983554162082141908877255319715400550981462988869084618816967398571437725114356308935833701495015311197958172878812521403732038749414005661189594761246154666465178024563227666440066723650451362032162000998737626370987794816660694178305939474922064726534186386488052827919792122844587807300048430756990391177266977583227470089929347969731703368720788359127837289988944365786283419724178187242169399457608505627145016468888402441344333481249304670223
ab = int(iroot(n,4)[0]) ab4 = ab^4
rs = 11079917583 for r in rs.divisors(): s = rs//r c = n-ab4-rs delta = c^2-4*rs*ab4 sdelta = int(iroot(delta,2)[0]) a4 = (c+sdelta)//(2*s) if iroot(a4,4)[1]: a = int(iroot(a4,4)[0]) b = int(iroot(ab4,4)[0]//a) if isprime(a^4+r): print("[+] p=",a^4+r) print("[+] q=",n//(a^4+r)) elif isprime(a^4+s): print("[+] p=",a^4+s) print("[+] q=",n//(a^4+s)) [+] p= 5213351003420231819415242686664610206224730148063270274863722096379841592931572096469136339538500817713355302889731144789372844731378975059329731297860686270736540109105854515590165681366189003405833252270606896051264517339339578167231093908235856718285980689179840159807651185918046198419707669304960745217 [+] q= 3891889986375336330559716098591764128742918441309724777337583126578227827768865619689858547513951476952436981068109005313431255086775128227872912287517417948310766208005723508039484956447166240210962374423348694952997002274647622939970550008327647559433222317977926773242269276334110863262269534189811138319
import random import time from tqdm import tqdm from Crypto.Util.number import * # About 3 seconds to run defAMM(o, r, q): start = time.time() print('\n----------------------------------------------------------------------------------') print('Start to run Adleman-Manders-Miller Root Extraction Method') print('Try to find one {:#x}th root of {} modulo {}'.format(r, o, q)) g = GF(q) o = g(o) p = g(random.randint(1, q)) while p ^ ((q-1) // r) == 1: p = g(random.randint(1, q)) print('[+] Find p:{}'.format(p)) t = 0 s = q - 1 while s % r == 0: t += 1 s = s // r print('[+] Find s:{}, t:{}'.format(s, t)) k = 1 while (k * s + 1) % r != 0: k += 1 alp = (k * s + 1) // r print('[+] Find alp:{}'.format(alp)) a = p ^ (r**(t-1) * s) b = o ^ (r*alp - 1) c = p ^ s h = 1 for i in range(1, t): d = b ^ (r^(t-1-i)) if d == 1: j = 0 else: print('[+] Calculating DLP...') j = - discrete_log(d, a) print('[+] Finish DLP...') b = b * (c^r)^j h = h * c^j c = c^r result = o^alp * h end = time.time() print("Finished in {} seconds.".format(end - start)) print('Find one solution: {}'.format(result)) return result
defonemod(p,r): t=random.randint(2,p) while pow(t,(p-1)//r,p)==1: t=random.randint(2,p) return pow(t,(p-1)//r,p) defsolution(p,root,e): whileTrue: g=onemod(p,e) may=[] for i in tqdm(range(e)): may.append(root*pow(g,i,p)%p) if len(may) == len(set(may)): return may
defsolve_in_subset(ep,p): cp = int(pow(c,inverse(int(e//ep),p-1),p)) com_factors = [] while GCD(ep,p-1) !=1: com_factors.append(GCD(ep,p-1)) ep //= GCD(ep,p-1) com_factors.sort()
cps = [cp] for factor in com_factors: mps = [] for cp in cps: mp = AMM(cp, factor, p) mps += solution(p,mp,factor) cps = mps for each in cps: assert pow(each,e,p)==c%p return cps
p= 5213351003420231819415242686664610206224730148063270274863722096379841592931572096469136339538500817713355302889731144789372844731378975059329731297860686270736540109105854515590165681366189003405833252270606896051264517339339578167231093908235856718285980689179840159807651185918046198419707669304960745217 q = 3891889986375336330559716098591764128742918441309724777337583126578227827768865619689858547513951476952436981068109005313431255086775128227872912287517417948310766208005723508039484956447166240210962374423348694952997002274647622939970550008327647559433222317977926773242269276334110863262269534189811138319 e = 11079917583 c = 13354219204055754230025847310134936965811370208880054443449019813095522768684299807719787421318648141224402269593016895821181312342830493800652737679627324687428327297369122017160142465940412477792023917546122283870042482432790385644640286392037986185997262289003477817675380787176650410819568815448960281666117602590863047680652856789877783422272330706693947399620261349458556870056095723068536573904350085124198592111773470010262148170379730937529246069218004969402885134027857991552224816835834207152308645148250837667184968030600819179396545349582556181916861808402629154688779221034610013350165801919342549766
start = time.time() print('Start CRT...') for mpp in m_p: for mqq in m_q: solution = CRT_list([int(mpp), int(mqq)], [p, q]) if solution < 2^800 : # Always the bit_length of flag is less than 800 print(long_to_bytes(solution))
end = time.time() print("Finished in {} seconds.".format(end - start))
from random import * from Crypto.Util.number import * from Crypto.Cipher import DES3 from flag import flag from key import key from iv import iv import os import hashlib import secrets
defRand(): rseed = secrets.randbits(1024) List1 = [] List2 = [] seed(rseed) for i in range(624): rand16 = getrandbits(16) List1.append(rand16) seed(rseed) for i in range(312): rand64 = getrandbits(64) List2.append(rand64) with open("task.txt", "w") as file: for rand16 in List1: file.write(hex(rand16)+ "\n") for rand64 in List2: file.write(hex((rand64 & 0xffff) | ((rand64 >> 32) & 0xffff) << 16) + "\n") Rand()
with open("task.txt") as f: data = f.read().split("\n")
data = [int(i[2:],16) for i in data] #print(data)
rand = data[:624]
index = 0 for each in data[624:]: rand[index] = (rand[index]<<16)+ (each & 0xffff) each2 = each >> 16 rand[index+1] = (rand[index+1]<<16)+ (each2 & 0xffff) index+=2
print(rand)
K3:一个字节爆破,K3 = b’DASCTF{‘+chr(j).encode()
IV:IV是8字节的。所以 hint2 泄露了 IV 的高四字节,通过看哈希,高四字节和低四字节是一样的,IV 是 ‘GWHTGWHT’
from random import * from Crypto.Util.number import * from Crypto.Cipher import DES3 # from flag import flag # from key import key # from iv import iv import os import hashlib import secrets
hint1 = b'\xfb\xc2' for j in range(128): xor = 334648638865560142973669981316964458403 K1 = long_to_bytes(bytes_to_long(hint1*8)^xor) #print(K1)
from Crypto.Util.number import * from secret import flag
defpubkey(list, m, w): pubkey_list = [] for i in range(len(e_bin)): pubkey_list.append(w * list[i] % m) return pubkey_list
defe_cry(e, pubkey): pubkey_list = pubkey encode = 0 for i in range(len(e)): encode += pubkey_list[i] * int(e[i]) % m return encode
p = getPrime(1024) q = getPrime(1024) n = p * q e = getPrime(64) m = bytes_to_long(flag) c = pow(m, e, n)
e_bin = (bin(e))[2:] list = [pow(3, i) for i in range(len(e_bin))] m = getPrime(len(bin(sum(list))) - 1) w = getPrime(64) pubkey = pubkey(list, m, w) en_e = e_cry(e_bin, pubkey)
for i in range(len(a)): b=[] for j in range(len(a)): if i == j: b.append(2) else: b.append(0) m.append(b) b=[] for i in range(len(m)): m[i].append(a[i]) b.append(1)
b.append(s) m.append(b) #print(len(m[0])) M = matrix(ZZ, m) print("Start LLL") ML = M.LLL() for each in ML: for i in each: if i == 1or i == -1or i==0: pass else: break else: v = each print(v) flag='' for i in v[:-1]: if i < 0: flag+='1' else: flag+='0'
sage: flag '1101110101111111101010101111101101001110100000010000100001010011' sage: int(flag,2) 15960663600754919507
1 2 3 4 5 6 7 8 9 10 11 12
p = 139540788452365306201344680691061363403552933527922544113532931871057569249632300961012384092481349965600565669315386312075890938848151802133991344036696488204791984307057923179655351110456639347861739783538289295071556484465877192913103980697449775104351723521120185802327587352171892429135110880845830815744 n = 22687275367292715121023165106670108853938361902298846206862771935407158965874027802803638281495587478289987884478175402963651345721058971675312390474130344896656045501040131613951749912121302307319667377206302623735461295814304029815569792081676250351680394603150988291840152045153821466137945680377288968814340125983972875343193067740301088120701811835603840224481300390881804176310419837493233326574694092344562954466888826931087463507145512465506577802975542167456635224555763956520133324723112741833090389521889638959417580386320644108693480886579608925996338215190459826993010122431767343984393826487197759618771 c = 156879727064293983713540449709354153986555741467040286464656817265584766312996642691830194777204718013294370729900795379967954637233360644687807499775502507899321601376211142933572536311131955278039722631021587570212889988642265055045777870448827343999745781892044969377246509539272350727171791700388478710290244365826497917791913803035343900620641430005143841479362493138179077146820182826098057144121231954895739989984846588790277051812053349488382941698352320246217038444944941841831556417341663611407424355426767987304941762716818718024107781873815837487744195004393262412593608463400216124753724777502286239464 R.<x> = Zmod(n)[] f = p+x x = f.small_roots(X=2^235,beta=0.49,epsilon=0.02)[0] p = int(f(x)) q = int(n//p) phi=(p-1)*(q-1) e=15960663600754919507 d=inverse(e,phi) long_to_bytes(pow(c,d,n))
from gmpy2 import * from Crypto.Util.number import * from secret import flag
m = bytes_to_long(flag)
defget_key(): p = getPrime(1400) f = getRandomNBitInteger(1024) whileTrue: q = getPrime(512) if gcd(f, q) != 1: continue else: break h = (invert(f, p) * q) % p return p, h
defencrypt1(m): a = getPrime(250) b = getRandomNBitInteger(240) n = getPrime(512) seed = m s = [0] * 6 s[0] = seed for i in range(1, 6): s[i] = (s[i - 1] * a + b) % n return s
defencrypt2(msg, p, h): s = getRandomNBitInteger(512) c = (s * h + msg) % p return c
defdecrypt(q, h, f, g, e): a = (f*e) % q m = (a*inverse(f, g)) % g return (m)
q,h = (25886434964719448194352673440525701654705794467884891063997131230558866479588298264578120588832128279435501897537203249743883076992668855905005985050222145380285378634993563571078034923112985724204131887907198503097115380966366598622251191576354831935118147880783949022370177789175320661630501595157946150891275992785113199863734714343650596491139321990230671901990010723398037081693145723605154355325074739107535905777351, 2332673914418001018316159191702497430320194762477685969994411366563846498561222483921873160125818295447435796015251682805613716554577537183122368080760105458908517619529332931042168173262127728892648742025494771751133664547888267249802368767396121189473647263861691578834674578112521646941677994097088669110583465311980605508259404858000937372665500663077299603396786862387710064061811000146453852819607311367850587534711) e = 20329058681057003355767546524327270876901063126285410163862577312957425318547938475645814390088863577141554443432653658287774537679738768993301095388221262144278253212238975358868925761055407920504398004143126310247822585095611305912801250788531962681592054588938446210412897150782558115114462054815460318533279921722893020563472010279486838372516063331845966834180751724227249589463408168677246991839581459878242111459287 M = matrix(ZZ,[[1,h],[0,q]]) ML = M.LLL() f,g = ML[0] f = abs(f) g = abs(g)
print(decrypt(q, h, f, g, e))
m = 10700695166096094995375972320865971168959897437299342068124161538902514000691034236758289037664275323635047529647532200693311709347984126070052011571264606
from gmpy2 import gcd from Crypto.Util.number import getPrime from secret import enflag
p = getPrime(512) q = getPrime(512) n = q * p phi = (p - 1) * (q - 1) e = getPrime(17) assert gcd(e, phi) == 1 # 以上信息生成了私钥文件,但文件被损坏了你能提取有用信息吗
c = pow(enflag, e, n) print('c = ' + str(c))
''' c = 91817924748361493215143897386603397612753451291462468066632608541316135642691873237492166541761504834463859351830616117238028454453831120079998631107520871612398404926417683282285787231775479511469825932022611941912754602165499500350038397852503264709127650106856760043956604644700201911063515109074933378818 '''
得到 d 0x974ebb2da0bb0afb3603970c3e17d8b044af22070a3750b05b849ddeef1d4a986182eed3832cc8bafc316eea36835042e96c0a85a23abc637e72c7f0ea787df06127fe9dc3d21b8dae8018bdffc345107d5271ddb6d5fbc01f8cbf73f44410d61e006208356f1c5b85515efc708b34b676e78f18d4d3b68f5765d10b701f0361
from gmpy2 import invert from hashlib import md5 from secret import p, q
e = ????? n = p*q phi = (p-1)*(q-1) d = invert(e, phi) ans = gcd(e,phi)
print n, e, d print"Flag: DASCTF{%s}" %md5(str(p + q)).hexdigest()
""" n = 8064259277274639864655809758868795854117113170423331934498023294296505063511386001711751916634810056911517464467899780578338013011453082479880809823762824723657495915284790349150975180933698827382368698861967973964030509129133021116919437755292590841218316278732797712538885232908975173746394816520256585937380642592772746398646558097588687958541171131704233319344980232942965050635113860017117519166348100569115174644678997805783380130114530824798808098237628247236574959152847903491509751809336988273823686988619679739640305091291330211169194377552925908412183162787327977125388852329089751737463948165202565859373 d = 14218766449983537783699024084862960813708451888387858392014856544340557703876299258990323621963898510226357248200187173211121827541826897886277531706124228848229095880229718049075745233893843373402201077890407507625110061976931591596708901741146750809962128820611844426759462132623616118530705745098783140913 """
这题无力吐槽了,代码写的稀巴烂,n还给错了
这里的n复制了两次,原来的 n 是 80642592772746398646558097588687958541171131704233319344980232942965050635113860017117519166348100569115174644678997805783380130114530824798808098237628247236574959152847903491509751809336988273823686988619679739640305091291330211169194377552925908412183162787327977125388852329089751737463948165202565859373
然后 e 给了五个问号,所以不大,直接维纳攻击或者 boneh_durfee 就可以解得 13521
e = 13521 n = 80642592772746398646558097588687958541171131704233319344980232942965050635113860017117519166348100569115174644678997805783380130114530824798808098237628247236574959152847903491509751809336988273823686988619679739640305091291330211169194377552925908412183162787327977125388852329089751737463948165202565859373 d = 14218766449983537783699024084862960813708451888387858392014856544340557703876299258990323621963898510226357248200187173211121827541826897886277531706124228848229095880229718049075745233893843373402201077890407507625110061976931591596708901741146750809962128820611844426759462132623616118530705745098783140913
from gmpy2 import gcd from random import * deffactor_n_with_ed(n,e,d): p = 1 q = 1 while p==1and q==1: k = d * e - 1 g = -randint(0,n) while p==1and q==1and k % 2 == 0: k //= 2 y = pow(g,k,n) if y!=1and gcd(y-1,n)>1: p = gcd(y-1,n) q = n//p return p,q print(factor_n_with_ed(n,e,d)) p = 10181341212828413853336916619161138854377885230386496425058202154486415709366161346816273366144505351043947477469664133317598479763451392984403646602585037 q = 7920625690369490250766357750388349704260128405941822835255851274284409978206593795103040446837018619894098452542488850045009467407103749792461438242280929