攻防世界-Crypto详细完整writeup
每天努力一点点,会不一样 ------2024-01-02 12:22:33 PM
预计每天更新一道题
1.baigeiRSA
2.简单的LFSR
3.[简单]初识RSA
4.rsarsa
5.hidden key
原题
from Crypto.Util.number import *
from secret import flag
import random
import hashlib
import os
key=os.urandom(8)
def rand(rng):
return rng - random.randrange(rng)
m=[]
random.seed(int(hashlib.md5(key).hexdigest(), 16))
for i in range(len(flag)):
rand(256)
xor=flag[i]^rand(256)
m.append(xor)
print(m)
print(bytes_to_long(key)>>12)
# [140, 96, 112, 178, 38, 180, 158, 240, 179, 202, 251, 138, 188, 185, 23, 67, 163, 22, 150, 18, 143, 212, 93, 87, 209, 139, 92, 252, 55, 137, 6, 231, 105, 12, 65, 59, 223, 25, 179, 101, 19, 215]
# 2669175714787937
原题给出了key右移12位的数字,这个偏移不算太大,我们可以暴力破解,从1--2**12,依次去尝试。
一下给出解题代码
from Crypto.Util.number import *
import random
import hashlib
m=[140, 96, 112, 178, 38, 180, 158, 240, 179, 202, 251, 138, 188, 185, 23, 67, 163, 22, 150, 18, 143, 212, 93, 87, 209, 139, 92, 252, 55, 137, 6, 231, 105, 12, 65, 59, 223, 25, 179, 101, 19, 215]
key1=2669175714787937<<12
def rand(rng):
return rng - random.randrange(rng)
for i in range(1<<12):
key=key1+i
key=long_to_bytes(key)
random.seed(int(hashlib.md5(key).hexdigest(), 16))
flag = []
for k in range(len(m)):
rand(256)
xor=m[k]^rand(256)
flag.append(xor)
if all(ch<256 for ch in flag):
flag_=bytes(flag)
if flag_.startswith(b'flag'):
print(flag_)
得到flag:flag{e319a58c-4dd6-4e6a-a3fb-f4b0d339faba}
6.base64
原题:Y3liZXJwZWFjZXtXZWxjb21lX3RvX25ld19Xb3JsZCF9
如其名,直接base64。得到flag:cyberpeace{Welcome_to_new_World!}
7.caeser
原题:oknqdbqmoq{kag_tmhq_xqmdzqp_omqemd_qzodkbfuaz}
一看就是凯撒密码,直接暴力破解
alphabet='abcdefghijklmnopqrstuvwxyz'
itoc=lambda i:alphabet[i] #返回字母表中对应的字符
ctoi=lambda c:alphabet.index(c)
def Caesar_dec(ciphertext,k):
plaintext=''
for ch in ciphertext:
if ch not in alphabet:
plaintext+=ch
else:
plaintext+=itoc((ctoi(ch)-k)%len(alphabet))
return plaintext
s="oknqdbqmoq{kag_tmhq_xqmdzqp_omqemd_qzodkbfuaz}"
for i in range(1,27):
print(Caesar_dec(s, -i))
得到flag:cyberpeace{you_have_learned_caesar_encryption}