首页 > 其他分享 >青少年CTF平台练习密码学

青少年CTF平台练习密码学

时间:2024-03-04 18:33:06浏览次数:28  
标签:青少年 flag qsnctf cf CTF &# print import 密码学

凯撒大帝的征讨之路

题目

凯撒大帝在出征之路上留下了这样一串字符,你能通过这串字符得到FLAG并提交吗?

lnixoa{1x2azz7w8axyva7y1z2320vxy6v97v9a}

我的解答:

凯撒密码

qsnctf{1c2fee7b8fcdaf7d1e2320acd6a97a9f}

PigPig

题目

这是什么密码呢?得到的结果请加上qsnctf{}后提交。

我的解答:

猪圈密码:http://moersima.00cha.net/zhuquan.asp

在线解码即可。

解个方程

题目

用简单的数学知识来解个方程吧!

欢迎来到青少年CTF,领取你的题目,进行解答吧!这是一道数学题!!
    p = 289354660472309271657353248544706260479
    q = 57125200079323286870829810458555200169
    e = 65537
    d = ?
    

我的解答:

简单的求d

import gmpy2
from Crypto.Util.number import *

p = 289354660472309271657353248544706260479
q = 57125200079323286870829810458555200169
e = 65537
phi = (p-1)*(q-1)
d = gmpy2.invert(e,phi)
print(d)
#7367969462435284192140853832508961738271951882284082089327925279892469405169

qsnctf{e30479db5bcd4d6384722647fb42c886}

ez_log

题目

ez_log
注意:请将 key提交到页面内,flag提交到这里来!

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)

    c=1357929686817757691458037658075453080147729946004559669716645300464681796023905740479827097068963012085529251008676406361905862646171082203012568824221846102704498507134119427563694774055882

我的解答:

简单的离散,sage直接梭

from Crypto.Util.number import *
import gmpy2
p=3006156660704242356836102321001016782090189571028526298055526061772989406357037170723984497344618257575827271367883545096587962708266010793826346841303043716776726799898939374985320242033037
c=1357929686817757691458037658075453080147729946004559669716645300464681796023905740479827097068963012085529251008676406361905862646171082203012568824221846102704498507134119427563694774055882

g=3
flag = discrete_log(Mod(c,p),Mod(g,p))
print(long_to_bytes(flag))
#key{uDujFo}
#qsnctf{82bbfdce553f48eb936b3a6c2b3771b1}

ezrsa

题目

这个n怎么分解呢?

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

我的解答:

这题已经是老生常谈了。直接在模r下算即可。

from Crypto.Util.number import *
import gmpy2
c = 173595148273920891298949441727054328036798235134009407863895058729356993814829340513336567479145746034781201823694596731886346933549577879568197521436900228804336056005940048086898794965549472641334237175801757569154295743915744875800647234151498117718087319013271748204766997008772782882813572814296213516343420236873651060868227487925491016675461540894535563805130406391144077296854410932791530755245514034242725719196949258860635915202993968073392778882692892
n = 1396260492498511956349135417172451037537784979103780135274615061278987700332528182553755818089525730969834188061440258058608031560916760566772742776224528590152873339613356858551518007022519033843622680128062108378429621960808412913676262141139805667510615660359775475558729686515755127570976326233255349428771437052206564497930971797497510539724340471032433502724390526210100979700467607197448780324427953582222885828678441579349835574787605145514115368144031247
leak = 152254254502019783796170793516692965417859793325424454902983763285830332059600151137162944897787532369961875766745853731769162511788354655291037150251085942093411304833287510644995339391240164033052417935316876168953838783742499485868268986832640692657031861629721225482114382472324320636566226653243762620647
e=65537
r = n//leak

phi = r-1
d = gmpy2.invert(e,phi)
m = pow(c,d,r)
print(long_to_bytes(m))
#qsnctf{12ff81e0-7646-4a96-a7eb-6a509ec01c9e}

四重加密

题目

简单的加密相信大家都会,请将最后的答案格式改为:qsnctf{flag}

我的解答:

压缩包密码base解码:qsnctf

zcye{mxmemtxrzt_lzbha_kwmqzec}|key=hello

HTML解码

zcye{mxmemtxrzt_lzbha_kwmqzec}|key=hello

维吉尼亚解码

synt{yqitbfqnoi_xsxwp_wpifoqv}

ROT13解码

flag{ldvgosdabv_kfkjc_jcvsbdi}

factor1

题目

这个e咋比n还大啊

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

我的解答:

Wiener's Attack求d,然后根据n e d分解p q

import gmpy2
import libnum
import hashlib
import random

def continuedFra(x, y):
    cf = []
    while y:
        cf.append(x // y)
        x, y = y, x % y
    return cf
def gradualFra(cf):
    numerator = 0
    denominator = 1
    for x in cf[::-1]:
        numerator, denominator = denominator, x * denominator + numerator
    return numerator, denominator
def solve_pq(a, b, c):
    par = gmpy2.isqrt(b * b - 4 * a * c)
    return (-b + par) // (2 * a), (-b - par) // (2 * a)
def getGradualFra(cf):
    gf = []
    for i in range(1, len(cf) + 1):
        gf.append(gradualFra(cf[:i]))
    return gf

def wienerAttack(e, n):
    cf = continuedFra(e, n)
    gf = getGradualFra(cf)
    for d, k in gf:
        if k == 0: continue
        if (e * d - 1) % k != 0:
            continue
        phi = (e * d - 1) // k
        p, q = solve_pq(1, n - phi + 1, n)
        if p * q == n:
            return d

e=4602579741478096718172697218991734057017874575484294836043557658035277770732473025335441717904100009903832353915404911860888652406859201203199117870443451616457858224082143505393843596092945634675849883286107358454466242110831071552006337406116884147391687266536283395576632885877802269157970812862013700574069981471342712011889330292259696760297157958521276388120468220050600419562910879539594831789625596079773163447643235584124521162320450208920533174722239029506505492660271016917768383199286913178821124229554263149007237679675898370759082438533535303763664408320263258144488534391712835778283152436277295861859
n=78665180675705390001452176028555030916759695827388719494705803822699938653475348982551790040292552032924503104351703419136483078949363470430486531014134503794074329285351511023863461560882297331218446027873891885693166833003633460113924956936552466354566559741886902240131031116897293107970411780310764816053

d=wienerAttack(e, n**2)

print('d=',d)

k = e * d - 1

r = k
t = 0
while True:
    r = r // 2
    t += 1
    if r % 2 == 1:
        break
 
success = False
 
for i in range(1, 101):
    g = random.randint(0, n)
    y = pow(g, r, n)
    if y == 1 or y == n - 1:
        continue
 
    for j in range(1, t):
        x = pow(y, 2, n)
        if x == 1:
            success = True
            break
        elif x == n - 1:
            continue
        else:
            y = x
 
    if success:
        break
    else:
        continue
 
if success:
    p = libnum.gcd(y - 1, n)
    q = n // p
    print ('P: ' + '%s' % p)
    print ('Q: ' + '%s' % q)
    hash_result = hashlib.md5(str(p + q).encode()).hexdigest()

    print(b'qsnctf{' + hash_result.encode() + b'}')
else:
    print ('Cannot compute P and Q')
#qsnctf{8072e8b2982bc729cc74ef58f1abc862}
   

 

标签:青少年,flag,qsnctf,cf,CTF,&#,print,import,密码学
From: https://www.cnblogs.com/mumuhhh/p/18052397

相关文章

  • ctfshow刷题记录-社工篇-1
    0x00题目来源:ctfshow-网络谜踪(社工类)题目描述:flag格式为ctfshow{纬度(精确到小数点后四位,不用进位),经度(精确到小数点后四位,不用进位)}例如若找到的经纬度为(11.45149,19.19810)则flag为ctfshow{11.4514,19.1981}(附件地址:https://ctfshow.lanzoui.com/iRHlmtek0ra)......
  • ctfshow刷题记录-cry方向-1
    0x00题目来源:ctfshow菜狗杯crypto方向base47题目描述:神必字符:E9CVT+HT5#X36RF4@LAU703+F$E-0N$@68LMXCVDRJJD5@MP#7MUZDTE?WWLG1S#L@+66H@59KTWYK8TW0RV神必字典:0123456789ABCDEFGHJKLMNPQRSTUVWXYZ?!@#$%^&*-+0x01第一次做这种base换表的题目,在网上查了查相关wp,感觉自......
  • HNCTF 2022 WEEK1
    [HNCTF2022Week1]超级签到str2是编写脚本str2='{hello_world}'print(str2.replace(chr(111),chr(48)))#{hell0_w0rld}[HNCTF2022Week1]贝斯是什么乐器啊?enc为码表为脚本为a="NRQ@PAu;8j[+(R:2806.i"flag=""foriinrange(len(a)):fla......
  • [GWCTF 2019]pyre
    首先是简单的pyc-py这题唯一要注意的一个点就是遇到%务必进行爆破爆破exp`code=['\x1f','\x12','\x1d','(','0','4','\x01','\x06','\x14','4',',','\x1......
  • 杂七杂八wp(NewStar_Week1和BeginCTF2024的部分pwn)
    碎碎念咱就一纯小白,以为带了Begin这一单词的CTF能对我仁慈一点,结果吧,太喜欢了,被狠狠拷打,从头自闭到尾,属于是从这次比赛又狠狠学习到不少知识了废话不多说,上正文嘞BeginCTFOne_bytechecksec嗯,基本啥都开了,喜欢捏。但是尊贵的CTFer,该“源审,启动!”了可以看到两个read,一个是......
  • 青少年CTF擂台挑战赛 2024 #Round 1-MISC
    一、CTFerRevenge1.得到txt,一眼某个文件的十六进制,前部分字符串,中间十六进制,最后是行数标识,先提取出全部的十六进制defclean_remove_spaces_and_last_chars(input_file,output_file):withopen(input_file,'r')asf:lines=f.readlines()cleaned_lines=[]......
  • cyi青少年CTF擂台挑战赛 2024 #Round 1 wp
    WEBEasyMD5靶机真不敢恭维一个文件上传界面,得上传pdf传两个pdfhttps://www.cnblogs.com/wysngblogs/p/15905398.html这篇文章看到md5碰撞,找到个工具fastcoll_v1.0.0.5https://www.win.tue.nl/hashclash/后续写的wp,flag可能不同PHP的后门https://blog.csdn.net/Sha......
  • [SWPUCTF 2021 新生赛]PseudoProtocols
    [SWPUCTF2021新生赛]PseudoProtocols尝试直接访问hint.php,发现并没有效果联想到题目为PseudoProtocols(伪协议),尝试使用伪协议php://filter参数详解该协议的参数会在该协议路径上进行传递,多个参数都可以在一个路径上传递。具体参考如下:php://filter参数描述res......
  • ctfshow sql注入练习记录
    前言:继续做ctfshow的题了,本次为sql注入专题,从ctfshowweb177开始ctfshowweb177对空格,--+进行了过滤,注释符要换成#的url编码%23使用万能密码可以绕过1'or'1'='1';%23也可也使用/**/对空格进行绕过,进行联合查询-1'union/**/select/**/1,2,password/**/from/**/ctfshow_use......
  • CTFHUB-web-信息泄露-目录遍历
    开启靶场http://challenge-a4aa9ff53d890618.sandbox.ctfhub.com:10800/查看此处源代码,没有发现有用信息点击开始寻找flag挨个点几个目录寻找flag在目录1/2下发现了flag提交一手,直接成功。可以参考此链接(纯小白,无教程思路有限)https://www.cnblogs.com/quail2333/p/12......