[WUSTCTF2020]情书
题目
Premise: Enumerate the alphabet by 0、1、2、..... 、25
Using the RSA system
Encryption:0156 0821 1616 0041 0140 2130 1616 0793
Public Key:2537 and 13
Private Key:2537 and 937
flag: wctf2020{Decryption}
解题
前提:用0、1、2、……枚举字母表25
使用RSA系统
加密:0156 0821 1616 0041 0140 2130 1616 0793
公钥:2537和13
私钥:2537和937
import gmpy2
from Crypto.Cipher import PKCS1_OAEP
from Crypto.PublicKey import RSA
from Crypto.Util.number import long_to_bytes
n = 2537
e = 13
d = 937
c = '0156 0821 1616 0041 0140 2130 1616 0793'.split(' ')
p = 43
q = 59
phi = (q-1) * (p-1)
m=[]
for x in c:
m.append(chr(int(gmpy2.powmod(int(x),d,n))+ord('a')))
print(''.join(m))
运行得到结果:iloveyou
答案
flag{iloveyou}
[UTCTF2020]basic-crypto
题目
一串二进制文本
解题
二进制转ASCII码为
Uh-oh, looks like we have another block of text, with some sort of special encoding. Can you figure out what this encoding is? (hint: if you look carefully, you'll notice that there only characters present are A-Z, a-z, 0-9, and sometimes / and +. See if you can find an encoding that looks like this one.)
TmV3IGNoYWxsZW5nZSEgQ2FuIHlvdSBmaWd1cmUgb3V0IHdoYXQncyBnb2luZyBvbiBoZXJlPyBJdCBsb29rcyBsaWtlIHRoZSBsZXR0ZXJzIGFyZSBzaGlmdGVkIGJ5IHNvbWUgY29uc3RhbnQuIChoaW50OiB5b3UgbWlnaHQgd2FudCB0byBzdGFydCBsb29raW5nIHVwIFJvbWFuIHBlb3BsZSkuCmt2YnNxcmQsIGl5ZSdibyBrdnd5Y2QgZHJvYm8hIFh5ZyBweWIgZHJvIHBzeGt2IChreG4gd2tpbG8gZHJvIHJrYm5vY2QuLi4pIHprYmQ6IGsgY2VsY2RzZGVkc3l4IG1zenJvYi4gU3ggZHJvIHB5dnZ5Z3N4cSBkb2hkLCBTJ2ZvIGRrdW94IHdpIHdvY2NrcW8ga3huIGJvenZrbW9uIG9mb2JpIGt2enJrbG9kc20gbXJrYmttZG9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IGNneCBzeXkgcWdmeCBpc3hlIGtjY2d4ZHU6IGZkY3lzbntoMHZfZGk0ZHVfdmk0ZF90X3I0eXlfcnhxbGQwfS4gcWdmIHZ0eXkgY3RoZSBkaXNkIHMgeWdkIGdjIHJ4cWxkZ254c2xpcSB0dSBwZnVkIHpmdHlldGhuIGdjYyBkaXR1IHVneGQgZ2MgenN1dHIgYmhndnlrZW5rLCBzaGUgdGQgeGtzeXlxIHR1IGhnZCB1ZyB6c2Ugc2Nka3ggc3l5LiBpZ2xrIHFnZiBraHBncWtlIGRpayByaXN5eWtobmsh
哦,看起来我们有另一个文本块,有某种特殊的编码。你能搞清楚这个编码是什么吗(提示:如果你仔细看,你会发现只有A-Z,A-Z,0-9,有时还有/和+。看看你能不能找到这样的编码。)
比较明显是base64
解码后得到:
New challenge! Can you figure out what's going on here? It looks like the letters are shifted by some constant. (hint: you might want to start looking up Roman people).
kvbsqrd, iye'bo kvwycd drobo! Xyg pyb dro psxkv (kxn wkilo dro rkbnocd...) zkbd: k celcdsdedsyx mszrob. Sx dro pyvvygsxq dohd, S'fo dkuox wi wocckqo kxn bozvkmon ofobi kvzrklodsm mrkbkmdob gsdr k mybboczyxnoxmo dy k nsppoboxd mrkbkmdob - uxygx kc k celcdsdedsyx mszrob. Mkx iye psxn dro psxkv pvkq? rsxd: Go uxyg drkd dro pvkq sc qysxq dy lo yp dro pybwkd edpvkq{...} - grsmr wokxc drkd sp iye coo drkd zkddobx, iye uxyg grkd dro mybboczyxnoxmoc pyb e, d, p, v k, kxn q kbo. Iye mkx zbylklvi gybu yed dro bowksxsxq mrkbkmdobc li bozvkmsxq drow kxn sxpobbsxq mywwyx gybnc sx dro Oxqvscr vkxqekqo. Kxydrob qbokd wodryn sc dy eco pboaeoxmi kxkvicsc: go uxyg drkd 'o' crygc ez wycd ypdox sx dro kvzrklod, cy drkd'c zbylklvi dro wycd mywwyx mrkbkmdob sx dro dohd, pyvvygon li 'd', kxn cy yx. Yxmo iye uxyg k pog mrkbkmdobc, iye mkx sxpob dro bocd yp dro gybnc lkcon yx mywwyx gybnc drkd cryg ez sx dro Oxqvscr vkxqekqo.
rghnxsdfysdtghu! qgf isak cthtuike dik zknthhkx rxqldgnxsliq risyykhnk. ikxk tu s cysn cgx syy qgfx isxe kccgxdu: fdcysn{h0v_di4du_vi4d_t_r4yy_rxqld0}. qgf vtyy cthe disd s ygd gc rxqldgnxsliq tu pfud zftyethn gcc ditu ugxd gc zsutr bhgvykenk, she td xksyyq tu hgd ug zse scdkx syy. iglk qgf khpgqke dik risyykhnk!
新的挑战!你能搞清楚这是怎么回事吗?看起来这些字母好像被常数移动了(提示:你可能想开始查罗马人)。
在线替换解密得到:
alright, you're almost there! Now for the final (and maybe the hardest...) part: a substitution cipher. In the following tezt, I've taken my message and replaced every alphabetic character with a correspondence to a different character - known as a substitution cipher. Can you find the final flag? hint: We know that the flag is going to be of the format utflag{...} - which means that if you see that pattern, you know what the correspondences for u, t, f, l a, and g are. You can probably work out the remaining characters by replacing them and inferring common words in the English language. Another great method is to use frequency analysis: we know that 'e' shows up most often in the alphabet, so that's probably the most common character in the tezt, followed by 't', and so on. Once you know a few characters, you can infer the rest of the words based on common words that show up in the English language. hwzdnitvoitjwzk! gwv yiqa sjzjkyau tya padjzzan hngbtwdnibyg hyiooazda. yana jk i soid swn ioo gwvn yinu asswntk: vtsoid{z0l_ty4tk_ly4t_j_h4oo_hngbt0}. gwv ljoo sjzu tyit i owt ws hngbtwdnibyg jk fvkt pvjoujzd wss tyjk kwnt ws pikjh rzwloauda, izu jt naioog jk zwt kw piu istan ioo. ywba gwv azfwgau tya hyiooazda!
好吧,你就快到了!现在是最后一部分(也许是最难的部分):替换密码。在下面的tezt中,我接收了我的消息,并将每个字母字符替换为与另一个字符对应的字符,称为替换密码。你能找到最后的flag吗?提示:我们知道这个标志的格式是utflag{…},这意味着如果你看到这个模式,你就知道u,t,f,la,和g的对应关系是什么。你可以通过替换它们并推断出英语中的常用词来找出剩下的字符。另一个很好的方法是使用频率分析:我们知道“e”在字母表中出现的频率最高,所以这可能是tezt中最常见的字符,其次是“t”,以此类推。一旦你知道了几个字符,你就可以根据英语中常见的单词推断出其余的单词。
hwzdnitvoitjwzk! gwv yiqa sjzjkyau tya padjzzan hngbtwdnibyg hyiooazda. yana jk i soid swn ioo gwvn yinu asswntk: vtsoid{z0l_ty4tk_ly4t_j_h4oo_hngbt0}. gwv ljoo sjzu tyit i owt ws hngbtwdnibyg jk fvkt pvjoujzd wss tyjk kwnt ws pikjh rzwloauda, izu jt naioog jk zwt kw piu istan ioo. ywba gwv azfwgau tya hyiooazda!
仍旧使用在线替换解密
congratulations! you have finished the beginner cryptography challenge. here is a flag for all your hard efforts: utflag{n0w_th4ts_wh4t_i_c4ll_crypt0}. you will find that a lot of cryptography is just building off this sort of basic knowledge, and it really is not so bad after all. hope you enjoyed the challenge!
祝贺 你!你已经完成了初级密码学挑战。这里有一个flag代表你所有的努力:utflag{n0w_th4ts_wh4t_i_c4ll_crypt0}。你会发现很多密码学只是建立在这类基本知识的基础上,而且它真的没有那么糟糕。希望你喜欢这个挑战!
答案
flag{n0w_th4ts_wh4t_i_c4ll_crypt0}
[BJDCTF2020]编码与调制
题目
密文:2559659965656A9A65656996696965A6695669A9695A699569666A5A6A6569666A59695A69AA696569666AA6
解题
根据图片提示NRZ、Manchester
NRZ 编码(Non-return-to-zero Code),也叫不归零编码。是我们最常见的一种编码,即正电平表示1,低电平表示0。
曼彻斯特编码(Manchester)又称裂相码、同步码、相位编码,是一种用电平跳变来表示1或0的编码方法,其变化规则很简单,即每个码元均用两个不同相位的电平信号表示,也就是一个周期的方波,但0码和1码的相位正好相反。
在曼彻斯特编码中,每一位的中间有一跳变,位中间的跳变既作时钟信号,又作数据信号。
曼彻斯特编码是将时钟和数据包含在信号流中,在传输代码信息的同时,也将时钟同步信号一起传输到对方。曼彻斯特编码的每一个码元都被调制成两个电平,所以数据传输速率只有调制速率的1/2。
解码:有保证的跳变的存在使信号可以自计时,也可以使接收器正确对准。接收器可以识别它是否在半个比特周期内未对齐,因为在每个比特周期内将不再总是存在过渡。与更简单的NRZ编码方案相比,这些好处的代价是带宽需求增加了一倍。
差分曼彻斯特编码数字信号编码是要解决数字数据的数字信号表示问题,即通过对数字信号进行编码来表示数据。数字信号编码的工作一般由硬件完成,常用的编码方法有以下三种:不归零码、曼彻斯特编码、差分曼彻斯特编码。
差分曼彻斯特编码是一种使用中位转变来计时的编码方案。数据通过在数据位开始处加一转变来表示。令牌环局域网就利用差分曼彻斯特编码方案。差分曼彻斯特编码在 每个时钟周期的中间都有一次电平跳变,这个跳变做同步之用。 在每个时钟周期的起始处:跳变则说明该比特是0,不跳变则说明该比特是1。
差分曼彻斯特编码的优点为:收发双方可以根据编码自带的时钟信号来保持同步,无需专门传递同步信号的线路,因此成本低;缺点为:实现技术复杂。
。。。。。。依旧懵逼🙂
使用16进制2进制转换with曼彻斯特编码 v1.3,按步骤解码得到:
024A447B4469664D616E63686573746572636F64657D
十六进制转ASCII码得到JD{DifManchestercode}
答案
flag{DifManchestercode}
[WUSTCTF2020]dp_leaking_1s_very_d@angerous
题目
e = 65537
n = 156808343598578774957375696815188980682166740609302831099696492068246337198792510898818496239166339015207305102101431634283168544492984586566799996471150252382144148257236707247267506165670877506370253127695314163987084076462560095456635833650720606337852199362362120808707925913897956527780930423574343287847
c = 108542078809057774666748066235473292495343753790443966020636060807418393737258696352569345621488958094856305865603100885838672591764072157183336139243588435583104423268921439473113244493821692560960443688048994557463526099985303667243623711454841573922233051289561865599722004107134302070301237345400354257869
dp = 734763139918837027274765680404546851353356952885439663987181004382601658386317353877499122276686150509151221546249750373865024485652349719427182780275825
解题
很明显的dp泄露
跟题目RSA2一样
先求出p、q,再求出e就能解密了
from Crypto.Util.number import *
import gmpy2
#记得导入数据
#先爆破K得到p、q
temp=dp*e
for i in range(1,e) :
if (temp-1)%i==0:
x=(temp-1)//i+1
y=n%x
if y==0:
p=x
break
q = n // p
phi = (q-1) * (p-1)
d = gmpy2.invert(e,phi)
m = pow(c,d,n)
print(long_to_bytes(m))
运行得到:b’wctf2020{dp_leaking_1s_very_d@angerous}’
答案
flag{dp_leaking_1s_very_d@angerous}