Virtua1's blog

两道用到异或的题目-Writeup

字数统计: 298阅读时长: 1 min
2018/11/10 Share

1、省赛初赛 签到题

解压文件得到一张图片但是打不开,放进winhex里,发现文件格式错误,将文件与正常png文件异或发现正好得到kelaibei,得到异或的key,然后用key将整个文件进行异或
#coding:utf-8
b = 0xE235222664687F636B656C6C202A213B
c = 0x89504E470D0A1A0A0000000D49484452
key = hex(b ^ c)
print key
#0x6b656c61696265696b656c6169626569L
#kelaibeikelaibei
#key = kelaibei

plaintext = ‘’
key = ‘kelaibei’
i = 0
l = 7
with open(‘encode.png’,’rb’) as f:
while True:
if i >= len(key):
i = 0
a = f.read(1)
if not a:
break
middle = hex(ord(key[i])^ord(a))[2:]
if len(middle) == 1:
middle = ‘0’+ middle
plaintext += middle
plaintext += ‘ ‘
i+=1

print plaintext


得到hex放进winhex保存为图片文件打开,把图片放进stegosolve查看最低色道发现二维码,保存图片扫描二维码得到flag

 

2、省赛 misc--神秘的代码

比赛的时候没做出来 官方wp:
import base64
import hashlib
from Crypto.Cipher import AES
def readfile(path):
    with open(path, 'r') as f:
        return f.read()
def xor(s1, s2):
    return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2))

read the files

clear = readfile(‘info_clear.txt’)
crypt = readfile(‘info_crypt.txt’)
superhero = readfile(‘true_crypto.txt’)
superhero = base64.b64decode(superhero)

get the key

dec = xor(clear,crypt).rstrip(‘\n’).encode(‘utf-8’)
print(dec)
key = hashlib.md5(dec).hexdigest().encode()
print(key)

decrypt aes-ecb

cipher = AES.new(key, AES.MODE_ECB)
msg = cipher.decrypt(superhero)
print(msg)


 

 

 

CATALOG
  1. 1. 1、省赛初赛 签到题
  2. 2. 2、省赛 misc--神秘的代码
  • read the files
  • get the key
  • decrypt aes-ecb