欢迎来到青少年CTF,领取你的题目,进行解答吧!这是一道数学题!! p = 70559223834693127821574754764487916409 q = 291568698992769291833060922537869705687 e = 65537 d = ?
1 2 3 4 5 6 7 8
import gmpy2 p = 70559223834693127821574754764487916409 q = 291568698992769291833060922537869705687 e = 65537
s = (p-1)*(q-1) d = gmpy2.invert(e,s) print ("dec: " + str(d))
ez_log
1 2 3 4 5 6 7 8 9 10
from Crypto.Util.number import * from random import * flag=b'key{xxxxxxx}' m=bytes_to_long(flag) p=3006156660704242356836102321001016782090189571028526298055526061772989406357037170723984497344618257575827271367883545096587962708266010793826346841303043716776726799898939374985320242033037 g=3 c=pow(g,m,p) print(f'c=',c)
from sympy import * from Crypto.Util.number import *
# 已知的参数 p = 3006156660704242356836102321001016782090189571028526298055526061772989406357037170723984497344618257575827271367883545096587962708266010793826346841303043716776726799898939374985320242033037 g = 3 c = 1409970374102613813154760568158003123875011225002977256272054381228289122265018484564640527366469489471011960208090567829620353663244080501413923713114331075726206212331906003182378049316620
# 计算离散对数 m = discrete_log(p, c, g) print("m =", long_to_bytes(m))
ezrsa
题干
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
from Crypto.Util.number import * flag = b'qsnctf{xxx-xxxx-xxxx-xxxx-xxxxxxxxx}' m = bytes_to_long(flag) p = getPrime(512) q = getPrime(512) r = getPrime(512) n = p * q * r leak = p * q e = 0x10001 c = pow(m, e, n) print(f'c = {c}') print(f'n = {n}') print(f'leak = {leak}') # c = 173595148273920891298949441727054328036798235134009407863895058729356993814829340513336567479145746034781201823694596731886346933549577879568197521436900228804336056005940048086898794965549472641334237175801757569154295743915744875800647234151498117718087319013271748204766997008772782882813572814296213516343420236873651060868227487925491016675461540894535563805130406391144077296854410932791530755245514034242725719196949258860635915202993968073392778882692892 # n = 1396260492498511956349135417172451037537784979103780135274615061278987700332528182553755818089525730969834188061440258058608031560916760566772742776224528590152873339613356858551518007022519033843622680128062108378429621960808412913676262141139805667510615660359775475558729686515755127570976326233255349428771437052206564497930971797497510539724340471032433502724390526210100979700467607197448780324427953582222885828678441579349835574787605145514115368144031247 # leak = 152254254502019783796170793516692965417859793325424454902983763285830332059600151137162944897787532369961875766745853731769162511788354655291037150251085942093411304833287510644995339391240164033052417935316876168953838783742499485868268986832640692657031861629721225482114382472324320636566226653243762620647
1 2 3 4 5 6
from sage.allimport * from Crypto.Util.number import * r=n//leak d=inverse_mod(65537,r-1) m=pow(c,d,r) print(long_to_bytes(m))
factor1
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import gmpy2 import hashlib from Crypto.Util.number import *
p = getPrime(512) q = getPrime(512) d = getPrime(256) e = gmpy2.invert(d, (p**2 - 1) * (q**2 - 1)) flag = "qsnctf{" + hashlib.md5(str(p + q).encode()).hexdigest() + "}" print(e) print(p * q) # 4602579741478096718172697218991734057017874575484294836043557658035277770732473025335441717904100009903832353915404911860888652406859201203199117870443451616457858224082143505393843596092945634675849883286107358454466242110831071552006337406116884147391687266536283395576632885877802269157970812862013700574069981471342712011889330292259696760297157958521276388120468220050600419562910879539594831789625596079773163447643235584124521162320450208920533174722239029506505492660271016917768383199286913178821124229554263149007237679675898370759082438533535303763664408320263258144488534391712835778283152436277295861859 # 78665180675705390001452176028555030916759695827388719494705803822699938653475348982551790040292552032924503104351703419136483078949363470430486531014134503794074329285351511023863461560882297331218446027873891885693166833003633460113924956936552466354566559741886902240131031116897293107970411780310764816053
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from sage.allimport * import hashlib from Crypto.Util.number import * A=matrix(ZZ,2) A[0,0]=2**1024 A[0,1]=e A[1,1]=n^2 res=A.LLL() print(res[0]) x=res[0,0] d=x//(2**1024) k=(e*d-1)//(n^2)+1 p2q2=1+n^2-(e*d-1)//k pq=isqrt(p2q2+2*n) flag = "qsnctf{" + hashlib.md5(str(pq).encode()).hexdigest() + "}"
defreverse_string(string): """Reverse the given string.""" return string[::-1]
defreverse_lines(input_file, output_file): """Read lines from input_file, remove first 9 characters, reverse each line, and write to output_file.""" withopen(input_file, "r") as fin, open(output_file, "w") as fout: lines = fin.readlines()
for line inreversed(lines): # Remove first 9 characters and reverse the line start_index = line.find("|") end_index = line.rfind("|") if start_index != -1and end_index != -1: # Remove content between '|' and reverse the line reversed_line = reverse_string( line[:start_index] + line[end_index + 1 :].strip() ) else: # If '|' is not found or only one '|' is found, reverse the entire line reversed_line = reverse_string(line.strip()) # Write reversed line to output file fout.write(reversed_line[9:] + "\n")
if __name__ == "__main__": input_file = "a.txt" output_file = "c.txt"
reverse_lines(input_file, output_file) print("Lines reversed and written to", output_file)