base64加密
用到的python模块:random、base64
1.txt:需要编码的内容
2.txt:编码后的内容
直接上代码
# -*- coding:utf-8 -*-
import random
from base64 import *
process = {
'16': lambda x: b16encode(x),
'32': lambda x: b32encode(x),
'64': lambda x: b64encode(x),
}
s = ""
with open('1.txt', 'r', encoding='UTF-8') as f: # 读取需要编码的内容
s = "".join(f.readlines()).encode('utf-8')
for i in range(random.randint(10, 20)): # 随机循环
s = process[random.choice(['16', '32', '64'])](s) # 随机编码
with open('2.txt', 'w', encoding='UTF-8') as f: # 保存编码后的结果
f.write(str(s, 'utf-8'))
base64 解密
代码如下:
#-*- coding:utf-8 -*-
import base64
s=''
with open('easybase-4-现代.txt', 'r', encoding='UTF-8') as f:
s="".join(f.readlines()).encode('utf-8')
src=s
while True:
try:
src=s
s=base64.b16decode(s)
str(s,'utf-8')
continue
except:
pass
try:
src=s
s=base64.b32decode(s)
str(s,'utf-8')
continue
except:
pass
try:
src=s
s=base64.b64decode(s)
str(s,'utf-8')
continue
except:
pass
break
with open('321.txt','w', encoding='utf-8') as file:
file.write(str(src,'utf-8'))
print("ok!")