BUUCTF密碼學(crypto)第38~41題
RSAROLL,robomunication,Unencode,[AFCTF2018]Morse
RSAROLL
第一個附件:
RSA roll!roll!roll!
Only number and a-z
(don’t use editor
which MS provide)
第二個附件:
{920139713,19}
704796792
752211152
274704164
18414022
368270835
483295235
263072905
459788476
483295235
459788476
475206804
459788476
428313374
475206804
459788476
425392137
704796792
458265677
341524652
483295235
534149509
425392137
428313374
425392137
341524652
458265677
263072905
483295235
828509797
341524652
425392137
475206804
428313374
483295235
475206804
459788476
306220148
解:{920139713,19}是n和e,先分解n,得到p,q。
從大佬那裡找來的程式碼:
// #---------------------------------------------------------------
#分解大整數
import math
def moder(n):
base=2
while base <math.sqrt(n):
if(n%base==0):
fbase=base
print(base,int(n/base))
base+=1
pass
f=getEuler(fbase,int(n/fbase))
print('f(n)尤拉函式值:%d'%f)#
return f
#---------------------- ---------------
# 求尤拉函式f(n)
def getEuler(prime1, prime2):
return (prime1-1)*(prime2-1)
#---------------------------------------------------------------------------------------
# 19d - 920071380k= 1
# 求私鑰d
def getDkey(e, Eulervalue):#可以輾轉相除法
k = 1
while True:
if (((Eulervalue * k) + 1) % e) == 0:
(d,m)=divmod(Eulervalue * k + 1,e)
return d#避免科學計數法最後轉int失去精度
k += 1
#------------------------------------------------------
#求明文
def Ming(c,d,n):
return pow(c,d,n)
#---------------------------------------------------------------------------------------
if __name__=='__main__':
n=int(input('請輸入要分解的質數: '))#920139713
d =getDkey(19, moder(n))
print('私鑰為: %d'%d)
c=[704796792,752211152,274704164,18414022,368270835,483295235,263072905,459788476,483295235,459788476,663551792,475206804,
459788476,428313374,475206804,459788476,425392137,704796792,458265677,341524652,483295235,534149509,425392137,428313374,
425392137,341524652,458265677,263072905,483295235,828509797,341524652,425392137,475206804,428313374,483295235,475206804,459788476,306220148]
L=[]
for x in c:
L.append(Ming(x,d,n))
print(L)#明文ascii表
for x in L:
print(chr(x),end='')
flag{13212je2ue28fy71w8u87y31r78eu1e2}
參考:https://blog.csdn.net/dongyanwen6036/article/details/76582310?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161132445616780262567204%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=161132445616780262567204&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-76582310.first_rank_v2_pc_rank_v29&utm_term=RSAroll&spm=1018.2226.3001.4187
robomunication
解:
這題給了一個音訊檔案,一聽就知道是摩斯密碼
“bi"就是點(.),"bu"就是橫(-)
聽出來就是… . .-… .-… — .-- … .- - … … - … . -.- . -.-- … - … … -… — --- .–. -… . . .–.
然後線上摩斯密碼解密,即得flag
flag{BOOPBEEP}
Unencode
題目:89FQA9WMD<V1A<V1S83DY.#<W3$Q,2TM]
解:Uuencode編碼轉換,線上轉換即可
flag{dsdasdsa99877LLLKK}
[AFCTF2018]Morse
解:
題目給了一串摩斯密碼:-…/.----/-…/-…/-…/…–/--…/…-/-…/-…/–…/-…/…–/.----/–…/…–/…—/–…/–…/…-/…/…-./–…/…–/…–/-----/…/…-./…–/…–/…–/…-/…–/…/–…/----./–…/-…
線上摩斯密碼解密,得到61666374667B317327745F73305F333435797D。
這是一串十六進位制數,所以ASCII碼轉成字元
C程式程式碼:
// #include <stdio.h>
int main()
{
int a[19];
int i;
for(i=0;i<19;i++)
{
scanf("%x",&a[i]);
}
for(i=0;i<19;i++)
{
printf("%c",a[i]);
}
return 0;
}
執行即可
離譜的是,BUUCTF得提交:
flag{1s’t_s0_345y}