from Crypto.Util.number import * import random flag=b'BaseCTF{}' m=bytes_to_long(flag) bin_m=bin(m)[2:] length=len(bin_m)
a=[1] sum=1 for i inrange(length-1): temp=random.randint(2*sum+1,4*sum) sum=sum+temp a.append(temp)
a=a[::-1] c=0 for i inrange(length): if bin_m[i]=='1': c=c+a[i] print("a=",a) print("c=",c)
简单的超递增序列(不懂的可以简单了解一下背包密码)
从尾开始遍历列表a,大于c就为0,小于等于c就为1,并且c要减去这个值
(数据太多我就不贴了)
1 2 3 4 5 6 7 8 9 10 11 12 13
#BaseCTF{2c4b0c15-3bee-4e4a-be6e-0f21e44bd4c9} from Crypto.Util.number import * a= c=2488656295807929935404316556194747314175977860755594014838879551525915558042003735363919054632036359039039831854134957725034750353847782168033537523854288427613513938991943920607437000388885418821419115067060003426834 bin_m="" for i in a: if c>=i: bin_m+="1" c=c-i else: bin_m+="0" m=int(bin_m,2) print(long_to_bytes(m))
babyrsa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
from Crypto.Util.number import *
flag=b'BaseCTF{}' m=bytes_to_long(flag)
n=getPrime(1024) e=65537 c=pow(m,e,n)
print("n =",n) print("e =",e) print("c =",c) """ n = 104183228088542215832586853960545770129432455017084922666863784677429101830081296092160577385504119992684465370064078111180392569428724567004127219404823572026223436862745730173139986492602477713885542326870467400963852118869315846751389455454901156056052615838896369328997848311481063843872424140860836988323 e = 65537 c = 82196463059676486575535008370915456813185183463924294571176174789532397479953946434034716719910791511862636560490018194366403813871056990901867869218620209108897605739690399997114809024111921392073218916312505618204406951839504667533298180440796183056408632017397568390899568498216649685642586091862054119832 """
from Crypto.Util.number import * import gmpy2 n = 104183228088542215832586853960545770129432455017084922666863784677429101830081296092160577385504119992684465370064078111180392569428724567004127219404823572026223436862745730173139986492602477713885542326870467400963852118869315846751389455454901156056052615838896369328997848311481063843872424140860836988323 e = 65537 c = 82196463059676486575535008370915456813185183463924294571176174789532397479953946434034716719910791511862636560490018194366403813871056990901867869218620209108897605739690399997114809024111921392073218916312505618204406951839504667533298180440796183056408632017397568390899568498216649685642586091862054119832
""" e = 65537 c = 42330675787206041757903427737108553993012805007294570657461042152628982126538 x = 209479773119142584969854470862023704936857416491817498021871883305658177375498 """
from Crypto.Util.number import * import random defgen_n(): primes=[getPrime(128) for _ inrange(256)] n = 1 for i inrange(100): n *= primes[random.randint(0,127)] return primes,n
from Crypto.Util.number import * from gmpy2 import * # n = # e = # c = # primes = for i in primes: for j in primes: for k in primes: tn=i*j*k phi=(i-1)*(j-1)*(k-1) m=long_to_bytes(pow(c,invert(e,phi),tn)) ifb'BaseCTF'in m: print(m) exit()
""" N = 162692163428762295773992659007654377270271126313772302197255271375236131917158614424426498628778734679898165422129699410934825650141972454562350664161510689489443251515884304101827584411577749250383438126881931889798597627663578045519256806107514170414321556291545302688028088470848270636776466672843710163017531472049823632822203461654253767303314505996071453898533003519236112138591066133289040889933161978131399309340741554076140734156174295730180874473301361701867633594222054688204666518058106672165786417002466165926062199279674267145233283545524775943767021416906072142236079753359492846480515376121887507681663761713445807717270089017438999615422884163666812016989696908657065537508715229685120221307021151610089917537155165897740417480127289719971512938348936259 c = 113962118676826667648935023618252851875440854724310328843964819392166304653581141146631375503931008732348730639629174670963727399860571217264854300057305570824097216782800531930906801885967717639795643406206813677461127762087560021634738167845077869308515223303820469892552545806179267969169748886980836435095 gift = 863514692222931709925579242743251211976114217396765747601042357918763818732391790491059528595917786523674732369068315533549380754409535403506339052401422249684188032949680148055803474336983973622610403448963752802490806614810077181934627694570685722842963961551889267501616799757825675192653489096007790143775773378495299981666657347802233798206597104474595281241837323214457344961462510183726339545608046357281265026013496037522835659867389206279894057481600882665189079672009577651494435000349624334685832217586703242422260870866432379257259316411280539845741932725104662417642890238587876489774492067722351467773093391502588019563488688309892102039611978767690653206664257400163618467825666105966072942726011447079204869750153256054140924951306811971422635104088608275908232688385437145325481792836532453258784103533536292492138405929815964841772656055397705840797739586953744563989819811944946916720655079908564653686456283647030055622241840292127096994325415897266379446446435164189216562921252341705747891518007710533906231225283309180960546212899099652226954393826875 """
from random import randrange from gmpy2 import * from Crypto.Util.number import * import itertools defmy_factors(N, gift): ans=[] factors=[N] whilelen(factors)>0: N=factors[0] w = randrange(2, N - 1)
s = 0 a_1 = pow(w, gift * pow(2,s), N) while a_1!=1: s=s+1 a_1 = pow(w, gift * pow(2,s), N)
if s!=0: a_2 = pow(w, gift * pow(2,s-1), N) if a_2!=N-1: p = gcd(N, a_2 + 1) if p!=1: q=N//p factors=factors[1:] if isPrime(p): ans.append(p) else: factors.append(p) if isPrime(q): ans.append(q) else: factors.append(q) return ans N = 162692163428762295773992659007654377270271126313772302197255271375236131917158614424426498628778734679898165422129699410934825650141972454562350664161510689489443251515884304101827584411577749250383438126881931889798597627663578045519256806107514170414321556291545302688028088470848270636776466672843710163017531472049823632822203461654253767303314505996071453898533003519236112138591066133289040889933161978131399309340741554076140734156174295730180874473301361701867633594222054688204666518058106672165786417002466165926062199279674267145233283545524775943767021416906072142236079753359492846480515376121887507681663761713445807717270089017438999615422884163666812016989696908657065537508715229685120221307021151610089917537155165897740417480127289719971512938348936259 c = 113962118676826667648935023618252851875440854724310328843964819392166304653581141146631375503931008732348730639629174670963727399860571217264854300057305570824097216782800531930906801885967717639795643406206813677461127762087560021634738167845077869308515223303820469892552545806179267969169748886980836435095 gift = 863514692222931709925579242743251211976114217396765747601042357918763818732391790491059528595917786523674732369068315533549380754409535403506339052401422249684188032949680148055803474336983973622610403448963752802490806614810077181934627694570685722842963961551889267501616799757825675192653489096007790143775773378495299981666657347802233798206597104474595281241837323214457344961462510183726339545608046357281265026013496037522835659867389206279894057481600882665189079672009577651494435000349624334685832217586703242422260870866432379257259316411280539845741932725104662417642890238587876489774492067722351467773093391502588019563488688309892102039611978767690653206664257400163618467825666105966072942726011447079204869750153256054140924951306811971422635104088608275908232688385437145325481792836532453258784103533536292492138405929815964841772656055397705840797739586953744563989819811944946916720655079908564653686456283647030055622241840292127096994325415897266379446446435164189216562921252341705747891518007710533906231225283309180960546212899099652226954393826875
primes=my_factors(N,gift) print(primes) permutation=itertools.combinations(primes,2) for i in permutation: p,q=i p,q=int(p),int(q) flag=long_to_bytes(pow(c,inverse(65537,(p-1)*(q-1)),p*q)) ifb'BaseCTF'in flag: print(flag) break #b'BaseCTF{ed4bff90-d1f4-4f0f-a3bd-999c54d9eeb7};\xef\xd7"X\xceglz\xc2l\xc3\xf0\x04\n$I\x00\xda\rT\xc5\xef\xc9t]\x0c\xae@\xdcO5\x02\xa8\xd6/{5\xacD5\xda\x11{\x80\x80\xa3\t#\x97\x871L\x10\r\x122z\xe1\x89%\x85\xdb\x94'
c = 52453423663797600504896811946820841317615798875871627840172711423749946998217916744135290476795328543876098295227017753117609268701786914053599060330837226980969490439739651088710549890669593587642238827462108900683237797139569260570711611781514337884756698142193277516649805710242748531658979160170193283558 e = 65537 d = 54297831548863701092644190086258072883163378307246681513317422545902442650340916001357605211715836911877651782099787873046987096258918495734824011752504203578982947618784736181975847356304742402103468329660346526185908618978851982007496096394151821403282347897417590596861323293706611997134962231129075032641 x = 40635864473997460751766935373772107585133301579524000836637683731949939348171187931595274511243052505604832873086269554842194695737052043633079044688826020656068356561856848814530947955429343483847291398607359454851926470168457852479044154798114087493843073091985855839008222762224952503563764527380033064437
#sage from Crypto.Util.number import * import itertools c = 78919950899709764543039048006935881842075789773495004639436106636461009323420 e = 65537 d = 13002488326322253055272696035053386340217207134816593767440035447757509399233 p_bits=128 q_bits=128 defget_phi(e, d): k_phi = e*d -1 result = [] for k inrange(e,2,-1): if k_phi % k == 0: tmp = k_phi // k ifint(tmp).bit_length()==p_bits+q_bits: result.append(tmp) return result defmain(): phi_list = get_phi(e,d) #获得可能的phi_n列表 count = len(phi_list) print(f'一共有{count}个可能的phi') count = 0 for phi in phi_list: count += 1 print(f'{count} 正在尝试爆破 {phi}') factors = factor(phi) # 分解phi_n得到质因子列表 result = [] for i in factors: num, times = int(i[0]), i[1] result += [num] * times
iflen(factors)>1: s = set() for r inrange(1, len(result) + 1): combination = list(itertools.combinations(result, r)) for i in combination: s.add(i) ans=[] for i in s: tmp=1 for j in i: tmp=tmp*j ans.append(tmp) for num in ans: ifint(num+1).bit_length()==p_bits and is_prime(num+1): p = num+1 q = phi // num + 1 if is_prime(q): n = p * q flag=long_to_bytes(int(pow(c,d,n))) ifb'BaseCTF'in flag: print(flag) return
if __name__ == '__main__': main() #b'BaseCTF{3e226a94-babb27696416}'
cs = [c] lge=math.log(e,2) for i inrange(int(lge)): #range里放log2e t = set() for c2 in cs: x = rabin(c2) for j in x: t.add(j) cs = list(t) for i in cs: flag=long_to_bytes(i) ifb'BaseCTF'in flag: print(flag) #BaseCTF{01c28b9c-7924-4c04-b71d-1cca15342618}
# 计算填充数据后的有几个分组,需要跳过计算 skip = (i + len(payload) - 4) // 64 A, B, C, D = iv message = b'a' * (64 * skip) + b'naby' res = my_md5(message, A, B, C, D, skip) rem.recvuntil(b"Please input your md5:") rem.sendline(res.encode()) rem.recvline() m = rem.recvline() ifb'correct'in m: print(_, want_md5, i, m) break
from Crypto.Util.number import * import socketserver import numpy as np import random import ast import os flag = os.getenv('GZCTF_FLAG').encode() classTask(socketserver.BaseRequestHandler): def_recvall(self): BUFF_SIZE = 2048 data = b'' whileTrue: part = self.request.recv(BUFF_SIZE) data += part iflen(part) < BUFF_SIZE: break return data.strip()
import numpy as np from Crypto.Util.number import * from pwn import * p=remote() p.recvline() flag=eval(p.recvline()) length=45*8-1 T=[] for i inrange(length): x=[0]*i+[1]+[0]*(length-1-i) p.sendline(str(x).encode()) T.append(eval(p.recvline())) T=np.array(T) t_ni=np.linalg.inv(T)
m=np.dot(flag,t_ni) m=np.round(m) flag="" for i in m: if i==1: flag+='1' else: flag+='0' print(long_to_bytes(int(flag,2)))
from Crypto.Util.number import * from Crypto.Util.Padding import * from Crypto.Cipher import AES import socketserver import os import base64 flag = os.getenv('GZCTF_FLAG').encode() classTask(socketserver.BaseRequestHandler): def_recvall(self): BUFF_SIZE = 2048 data = b'' whileTrue: part = self.request.recv(BUFF_SIZE) data += part iflen(part) < BUFF_SIZE: break return data.strip()
self.send(b"the server will connect you entered to the front of flag.") self.send(b"then you will receive ciphertext(b64encode) encrypted by AES-ECB.")
from Crypto.Util.number import * from gmpy2 import * import random import math
p = 17363249226879909675667629533972233798566313669420563155296918020175446973456428454735263489044575257132690882883587342817653451483222705760704890265900885255972067349104579938808591608382992680533327518070878297438339884996059309549300942570104747348751766711833983705979880714174709047335147739991850385244159235504375559144283494800573079055547597410783559965162216203307100248001158445665271438067670522510991047688414176659907164436539491205637933681658814267567385232097679554282863595183422504494357205180093828786415060565003183966959273253039416986816444073158723191290806413175478175738266995214965220231649 e = 32 c = 6840453756562205147103219479843999687625029691496635689045074720240615321966887831642035124198445485320265097191334720798522097422084141332044111764558336174743819347952914775206809737198058220362381349481027893609144697054465070779290329222696236671374412706789862193871687821041053566873553189148668599841084370137084893575567622972476409755187388121177923217208552049876944055745912987536390075417261016809335539362984984190264791744790640858201038207982043569204062714722892105134794280417020318408200038144689432974312283915592134911446185412636709207566063730723406969727969141426530341540330398465744403597273 defonemod(e, q): p = random.randint(1, q-1) while(powmod(p, (q-1)//e, q) == 1): # (r,s)=1 p = random.randint(1, q) return p
defAMM_rth(o, r, q): # r|(q-1 assert((q-1) % r == 0) p = onemod(r, q)
t = 0 s = q-1 while(s % r == 0): s = s//r t += 1 k = 1 while((s*k+1) % r != 0): k += 1 alp = (s*k+1)//r
a = powmod(p, r**(t-1)*s, q) b = powmod(o, r*a-1, q) c = powmod(p, s, q) h = 1
for i inrange(1, t-1): d = powmod(int(b), r**(t-1-i), q) if d == 1: j = 0 else: j = (-math.log(d, a)) % r b = (b*(c**(r*j))) % q h = (h*c**j) % q c = (c*r) % q result = (powmod(o, alp, q)*h) return result
defALL_Solution(m, q, rt, cq, e): mp = [] for pr in rt: r = (pr*m) % q # assert(pow(r, e, q) == cq) mp.append(r) return mp
defcalc(mp, mq, e, p, q): i = 1 j = 1 t1 = invert(q, p) t2 = invert(p, q) for mp1 in mp: for mq1 in mq: j += 1 if j % 100000 == 0: print(j) ans = (mp1*t1*q+mq1*t2*p) % (p*q) if check(ans): return return
defALL_ROOT2(r, q): # use function set() and .add() ensure that the generated elements are not repeated li = set() while(len(li) < r): p = powmod(random.randint(1, q-1), (q-1)//r, q) li.add(p) return li
from Crypto.Util.number import * import decimal from pwn import * from time import * rem=remote() rem.recvuntil(b'n = ') n=int(rem.recvline().decode().strip())
from Crypto.Util.number import * from gmpy2 import * import hashlib import hmac from Crypto.Cipher import AES from Crypto.Util.Padding import pad from random import *
if judge: listF=list(F) X=[] for i inrange(len(F)//100): x=randint(0,len(F)-1) while listF[x]==0: x=randint(0,len(F)-1) X.append(x) listF[x]=0 F=b'' for i in listF: F+=long_to_bytes(i)
from Crypto.Util.number import * from gmpy2 import * import hashlib import hmac from Crypto.Cipher import AES from Crypto.Util.Padding import pad from random import *
defCheckProff(n,e,W,c,k1,k2,s,T): tau=pow(T,e,n) block_count=len(W) for j inrange(c): my_aes=AES.new(long_to_bytes(k1),mode=AES.MODE_ECB) i=my_aes.encrypt(pad(long_to_bytes(j),AES.block_size)) i=bytes_to_long(i)%block_count