buuctf-异性相吸

buuctf-异性相吸_第1张图片

下载文件后解压得到

得到一个密文文件和密钥文件

buuctf-异性相吸_第2张图片
buuctf-异性相吸_第3张图片

但是根本没有这个方式去解密

经过查看得到异性相吸,指的的二进制的异或运算

将得到的密钥和密文用010打开,以二进制形式编译

buuctf-异性相吸_第4张图片

选中全部,复制使用Ctrl+shift+c,表示仅复制左边的数据,但是复制出来还是十六进制形式

自己编写一个Python脚本,先将十六进制转换为二进制,然后用二进制进行异或运算

但是如果对比的010里的话,整个二进制前的0会被省略掉,记得对照一下

#十六进制转二进制
def hex_bin(n):
    hex_str = n  # 十六进制字符串
    bin_str = bin(int(hex_str, 16)).replace('0b','') # 将十六进制字符串转换为二进制字符串
    #因为bin转换来的二进制带有0b前缀,所以给他替换为空
    print(bin_str)
hex_bin('6173616473617364617364617364617364617364617364617364617364617364717765737166')
n = '0000011100011111000000000000001100001000000001000001001001010101000000110001000001010100010110000100101101011100010110000100101001010110010100110100010001010010000000110100010000000010010110000100011000000110010101000100011100000101010101100100011101010111010001000001001001011101010010100001010000011011'
m = '0110000101110011011000010110010001110011011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011100010111011101100101011100110111000101100110'
a = ''
x = ''
for i in range(len(n)):
    if n[i] == m[i]:
        x += '0'
    else:
        x += '1'
    if len(x) % 8 == 0:
        a += chr(int(x,2))
        x = ''
print(a)
buuctf-异性相吸_第5张图片

你可能感兴趣的:(Crypto,数学建模,python)