本文为看雪论坛优秀文章
看雪论坛作者ID:HU_Moon
一
信息搜集
二
函数功能猜测
三
解密密文数据
base64_table = 'ghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef'
def btoa(): # base64编码函数
s = input("input string to encode:\n")
n = len(s) % 3
x = ''
asc = []
for i in range(len(s)):
asc.append(ord(s[i])) # 取各字符ascii值
x += '{:08b}'.format(asc[i]) # 将各字符ascii值转为二进制
if n:
x += '0' * 2 * (3 - n) # 长度非3倍的结尾补零
i = 0
out = ''
while i < len(x):
out += base64_table[int(x[i:i + 6], 2)]
i += 6
if n:
out += '=' * (3 - n) # 补上'='使编码后长度为4倍
print(out)
def atob(): # base64解码函数
s = input("input string to decode:\n")
b64 = []
x = ''
for i in range(len(s)):
if s[i] == '=':
b64.append(0)
else:
for j in range(64):
if (s[i] == base64_table[j]):
b64.append(j)
break
x += '{:06b}'.format(b64[i])
print(x)
i = 0
out = ''
while i < len(x):
if int(x[i:i + 8], 2):
out += chr(int(x[i:i + 8], 2))
i += 8
print(out)
def main():
m = input('Input 1/2 to encode/decode:\n')
if m == '1':
btoa()
elif m == '2':
atob()
else:
print('Error! Please restart the process!')
main()
# RC4
from Crypto.Util.number import bytes_to_long, long_to_bytes
key = "szv~"
msg = "\x72\xA7\xE5\xB1\xBF\xD1\x3A\xC9\x7E\x5D\x83\xA8\x21\x4F\x70\x90"
key = list(key)
# KSA
S = [i for i in range(256)]
j = 0
for i in range(256):
j = (j + S[i] + ord(key[i % len(key)])) % 256
S[i], S[j] = S[j], S[i]
# PRGA
i = 0
j = 0
keystream = []
for k in range(len(msg)):
i = (i + 1) % 256
j = (j + S[i]) % 256
S[i], S[j] = S[j], S[i]
keystream.append(S[(S[i] + S[j]) % 256])
enc = "".join(map(chr, [(ord(msg[i]) ^ keystream[i]) for i in range(len(keystream))]))
print(enc)
看雪ID:HU_Moon
https://bbs.pediy.com/user-home-920107.htm
看雪CTF官网:https://ctf.pediy.com/
# 往期推荐
球分享
球点赞
球在看
点击“阅读原文”,了解更多!