base64位加解密专题研究

实现破解自定义加解密的破解方法
复制代码
 1 import base64
 2 
 3 def custom_base64_encode(data, custom_charset):
 4     encoded_chars = []
 5     for byte in data:
 6         encoded_chars.append(custom_charset[byte >> 2 & 0x3F])
 7         encoded_chars.append(custom_charset[(byte & 0x03) << 4])
 8     return ''.join(encoded_chars)
 9 
10 def custom_base64_decode(data, custom_charset):
11     decoded_chars = []
12     for i in range(0, len(data), 2):
13         char1 = custom_charset.index(data[i])
14         char2 = custom_charset.index(data[i+1])
15         byte = (char1 << 2) | (char2 >> 4)
16         decoded_chars.append(byte)
17     return bytes(decoded_chars)
18 
19 # 自定义base64字符集
20 custom_charset = "123456ertyuytdf456ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+"
21 
22 # 原始数据
23 original_data = b"Hello, World!"
24 
25 # 标准base64编码
26 standard_encoded_data = base64.b64encode(original_data).decode()
27 
28 # 自定义base64编码
29 custom_encoded_data = custom_base64_encode(original_data, custom_charset)
30 
31 # 标准base64解码
32 standard_decoded_data = base64.b64decode(standard_encoded_data)
33 
34 # 自定义base64解码
35 custom_decoded_data = custom_base64_decode(custom_encoded_data, custom_charset)
36 
37 print("原始数据:", original_data)
38 print("标准base64编码:", standard_encoded_data)
39 print("自定义base64编码:", custom_encoded_data)
40 print("标准base64解码:", standard_decoded_data)
复制代码

 

posted on   jiapengchu  阅读(14)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示