青少年CTF-Crypto(新手版本2.0)

宁睿  金牌会员 | 2024-5-13 02:23:41 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 949|帖子 949|积分 2857

凯撒大帝的征讨之路

题目:
lnixoa{1x2azz7w8axyva7y1z2320vxy6v97v9a}
知识点:凯撒加密
我的题解:
  1. import base64
  2. #shift得出移位多少,移位后的字母-移位前的字母
  3. def caesar_decrypt(ciphertext, shift=ord('l')-ord('q')):
  4.     str_list = list(ciphertext)
  5.     i = 0
  6.     while i < len(ciphertext):
  7.         if str_list[i].isalpha():
  8.             a = "A" if str_list[i].isupper() else "a"
  9.             str_list[i] = chr((ord(str_list[i]) - ord(a) - shift) % 26 + ord(a))
  10.         i += 1
  11.     return ''.join(str_list)
  12. str='lnixoa{1x2azz7w8axyva7y1z2320vxy6v97v9a}'
  13. #放入需要解密的凯撒加密过的flag
  14. kstr = caesar_decrypt(str)
  15. print("凯撒解密后的字符串:", kstr)
  16. #qsnctf{1c2fee7b8fcdaf7d1e2320acd6a97a9f}
复制代码
PigPig

题目:

知识点:猪圈密码
我的题解:

 解个方程

题目:
  1. 欢迎来到青少年CTF,领取你的题目,进行解答吧!这是一道数学题!!
  2.     p = 285938619572571413831422228101124163683
  3.     q = 105729283011633484980933962485160648857
  4.     e = 65537
  5.     d = ?
  6.    
复制代码
知识点:大素数分解中求d
我的题解:
  1. import gmpy2
  2. from Crypto.Util.number import *
  3. import math
  4. p = 285938619572571413831422228101124163683
  5. q = 105729283011633484980933962485160648857
  6. e = 65537
  7. n = p*q
  8. phi = (p-1) * (q-1)
  9. d = gmpy2.invert(e,phi)
  10. print(d)
  11. #5844184015344558481149339489808793528798898400213145852462349005651020126577
复制代码

ez_log

题目:
  1. from Crypto.Util.number import *
  2. from random import *
  3. flag=b'key{xxxxxxx}'
  4. m=bytes_to_long(flag)
  5. p=3006156660704242356836102321001016782090189571028526298055526061772989406357037170723984497344618257575827271367883545096587962708266010793826346841303043716776726799898939374985320242033037
  6. g=3
  7. c=pow(g,m,p)
  8. print(f'c=',c)
  9. c=2558016376919340744861283143131342116530097815936201928079539498968035304172458942066482394126279568644520885275321026125136755531717057526144375105028343943707485572136532741715583512444233
复制代码
我的题解:
 c = g^m mod p
g很小,m作为flag处于次方的位置
可以用sage
  1. from Crypto.Util.number import *
  2. import gmpy2
  3. c=2558016376919340744861283143131342116530097815936201928079539498968035304172458942066482394126279568644520885275321026125136755531717057526144375105028343943707485572136532741715583512444233
  4. p=3006156660704242356836102321001016782090189571028526298055526061772989406357037170723984497344618257575827271367883545096587962708266010793826346841303043716776726799898939374985320242033037
  5. e=3
  6. flag = discrete_log(Mod(c,p),Mod(g,p))
  7. print(long_to_bytes(flag))<br>#b'key{f73ra1}'
复制代码

 ezrsa

题目:
  1. from Crypto.Util.number import *
  2. flag = b'qsnctf{xxx-xxxx-xxxx-xxxx-xxxxxxxxx}'
  3. m = bytes_to_long(flag)
  4. p = getPrime(512)
  5. q = getPrime(512)
  6. r = getPrime(512)
  7. n = p * q * r
  8. leak = p * q
  9. e = 0x10001
  10. c = pow(m, e, n)
  11. print(f'c = {c}')
  12. print(f'n = {n}')
  13. print(f'leak = {leak}')
  14. # c = 173595148273920891298949441727054328036798235134009407863895058729356993814829340513336567479145746034781201823694596731886346933549577879568197521436900228804336056005940048086898794965549472641334237175801757569154295743915744875800647234151498117718087319013271748204766997008772782882813572814296213516343420236873651060868227487925491016675461540894535563805130406391144077296854410932791530755245514034242725719196949258860635915202993968073392778882692892
  15. # n = 1396260492498511956349135417172451037537784979103780135274615061278987700332528182553755818089525730969834188061440258058608031560916760566772742776224528590152873339613356858551518007022519033843622680128062108378429621960808412913676262141139805667510615660359775475558729686515755127570976326233255349428771437052206564497930971797497510539724340471032433502724390526210100979700467607197448780324427953582222885828678441579349835574787605145514115368144031247
  16. # leak = 152254254502019783796170793516692965417859793325424454902983763285830332059600151137162944897787532369961875766745853731769162511788354655291037150251085942093411304833287510644995339391240164033052417935316876168953838783742499485868268986832640692657031861629721225482114382472324320636566226653243762620647
复制代码
我的题解:
n分解出q、p、r,但是多因子解码不可信。
可以得出单个r,举行r的简单RSA计算
  1. from Crypto.Util.number import *
  2. import gmpy2
  3. c = 173595148273920891298949441727054328036798235134009407863895058729356993814829340513336567479145746034781201823694596731886346933549577879568197521436900228804336056005940048086898794965549472641334237175801757569154295743915744875800647234151498117718087319013271748204766997008772782882813572814296213516343420236873651060868227487925491016675461540894535563805130406391144077296854410932791530755245514034242725719196949258860635915202993968073392778882692892
  4. n = 1396260492498511956349135417172451037537784979103780135274615061278987700332528182553755818089525730969834188061440258058608031560916760566772742776224528590152873339613356858551518007022519033843622680128062108378429621960808412913676262141139805667510615660359775475558729686515755127570976326233255349428771437052206564497930971797497510539724340471032433502724390526210100979700467607197448780324427953582222885828678441579349835574787605145514115368144031247
  5. leak = 152254254502019783796170793516692965417859793325424454902983763285830332059600151137162944897787532369961875766745853731769162511788354655291037150251085942093411304833287510644995339391240164033052417935316876168953838783742499485868268986832640692657031861629721225482114382472324320636566226653243762620647
  6. e = 0x10001<br>
  7. r = n // leak
  8. r=9170584408726584113673965972648240491689635118606416619099032606248549219208315227501144611402976054161705877934617690915635968224924300539749199425819801
  9. phr = r - 1
  10. d = gmpy2.invert(e,phr)
  11. m = pow(c,d,r)
  12. print(long_to_bytes(m))
  13. #qsnctf{12ff81e0-7646-4a96-a7eb-6a509ec01c9e}
复制代码
四重加密

题目:

我的题解:
需要找出密码,在边上有

 CyberChef解码

 打开后出现编码
 
  1. zcye{mxmemtxrzt_lzbha_kwmqzec}|key=hello
复制代码
HTNL解码:http://www.hiencode.com/html_en.html

 zcye{mxmemtxrzt_lzbha_kwmqzec}|key=hello
然后举行维吉尼亚解密,我用了随波逐流
synt{yqitbfqnoixsxwpwpifoqv}
末了举行rot13解码
flag{ldvgosdabvkfkjcjcvsbdi}
(我末了两次解密使用了随波逐流暴力破解,嘻嘻#^.^#)
 factor1

题目:
  1. import gmpy2
  2. import hashlib
  3. from Crypto.Util.number import *
  4. p = getPrime(512)
  5. q = getPrime(512)
  6. d = getPrime(256)
  7. e = gmpy2.invert(d, (p**2 - 1) * (q**2 - 1))
  8. flag = "qsnctf{" + hashlib.md5(str(p + q).encode()).hexdigest() + "}"
  9. print(e)
  10. print(p * q)
  11. # 4602579741478096718172697218991734057017874575484294836043557658035277770732473025335441717904100009903832353915404911860888652406859201203199117870443451616457858224082143505393843596092945634675849883286107358454466242110831071552006337406116884147391687266536283395576632885877802269157970812862013700574069981471342712011889330292259696760297157958521276388120468220050600419562910879539594831789625596079773163447643235584124521162320450208920533174722239029506505492660271016917768383199286913178821124229554263149007237679675898370759082438533535303763664408320263258144488534391712835778283152436277295861859
  12. # 78665180675705390001452176028555030916759695827388719494705803822699938653475348982551790040292552032924503104351703419136483078949363470430486531014134503794074329285351511023863461560882297331218446027873891885693166833003633460113924956936552466354566559741886902240131031116897293107970411780310764816053
复制代码
知识点:维纳攻击
e超级大,先求出d,然后e,n,d已知,求p,q
  1. import gmpy2
  2. import libnum
  3. import hashlib
  4. import random
  5. def continuedFra(x, y):
  6.     cf = []
  7.     while y:
  8.         cf.append(x // y)
  9.         x, y = y, x % y
  10.     return cf
  11. def gradualFra(cf):
  12.     numerator = 0
  13.     denominator = 1
  14.     for x in cf[::-1]:
  15.         numerator, denominator = denominator, x * denominator + numerator
  16.     return numerator, denominator
  17. def solve_pq(a, b, c):
  18.     par = gmpy2.isqrt(b * b - 4 * a * c)
  19.     return (-b + par) // (2 * a), (-b - par) // (2 * a)
  20. def getGradualFra(cf):
  21.     gf = []
  22.     for i in range(1, len(cf) + 1):
  23.         gf.append(gradualFra(cf[:i]))
  24.     return gf
  25. def wienerAttack(e, n):
  26.     cf = continuedFra(e, n)
  27.     gf = getGradualFra(cf)
  28.     for d, k in gf:
  29.         if k == 0: continue
  30.         if (e * d - 1) % k != 0:
  31.             continue
  32.         phi = (e * d - 1) // k
  33.         p, q = solve_pq(1, n - phi + 1, n)
  34.         if p * q == n:
  35.             return d
  36. e=4602579741478096718172697218991734057017874575484294836043557658035277770732473025335441717904100009903832353915404911860888652406859201203199117870443451616457858224082143505393843596092945634675849883286107358454466242110831071552006337406116884147391687266536283395576632885877802269157970812862013700574069981471342712011889330292259696760297157958521276388120468220050600419562910879539594831789625596079773163447643235584124521162320450208920533174722239029506505492660271016917768383199286913178821124229554263149007237679675898370759082438533535303763664408320263258144488534391712835778283152436277295861859
  37. n=78665180675705390001452176028555030916759695827388719494705803822699938653475348982551790040292552032924503104351703419136483078949363470430486531014134503794074329285351511023863461560882297331218446027873891885693166833003633460113924956936552466354566559741886902240131031116897293107970411780310764816053
  38. d=wienerAttack(e, n**2)
  39. print('d=',d)
  40. #d= 63691166654760611586233830170653888570050734006064722630809918076234937115339
复制代码
  1. import gmpy2
  2. import libnum
  3. import hashlib
  4. import random
  5. e=4602579741478096718172697218991734057017874575484294836043557658035277770732473025335441717904100009903832353915404911860888652406859201203199117870443451616457858224082143505393843596092945634675849883286107358454466242110831071552006337406116884147391687266536283395576632885877802269157970812862013700574069981471342712011889330292259696760297157958521276388120468220050600419562910879539594831789625596079773163447643235584124521162320450208920533174722239029506505492660271016917768383199286913178821124229554263149007237679675898370759082438533535303763664408320263258144488534391712835778283152436277295861859
  6. n=78665180675705390001452176028555030916759695827388719494705803822699938653475348982551790040292552032924503104351703419136483078949363470430486531014134503794074329285351511023863461560882297331218446027873891885693166833003633460113924956936552466354566559741886902240131031116897293107970411780310764816053
  7. d= 63691166654760611586233830170653888570050734006064722630809918076234937115339
  8. k = e * d - 1
  9. r = k
  10. t = 0
  11. while True:
  12.     r = r // 2
  13.     t += 1
  14.     if r % 2 == 1:
  15.         break
  16. success = False
  17. for i in range(1, 101):
  18.     g = random.randint(0, n)
  19.     y = pow(g, r, n)
  20.     if y == 1 or y == n - 1:
  21.         continue
  22.     for j in range(1, t):
  23.         x = pow(y, 2, n)
  24.         if x == 1:
  25.             success = True
  26.             break
  27.         elif x == n - 1:
  28.             continue
  29.         else:
  30.             y = x
  31.     if success:
  32.         break
  33.     else:
  34.         continue
  35. if success:
  36.     p = libnum.gcd(y - 1, n)
  37.     q = n // p
  38.     print ('P: ' + '%s' % p)
  39.     print ('Q: ' + '%s' % q)
  40.     hash_result = hashlib.md5(str(p + q).encode()).hexdigest()
  41.     print(b'qsnctf{' + hash_result.encode() + b'}')
  42.     #qsnctf  注意格式问题
  43. else:
  44.     print ('Cannot compute P and Q')
  45. #qsnctf{8072e8b2982bc729cc74ef58f1abc862}
复制代码
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

宁睿

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表