如何使用自定义字母集解码 base64 字符串?

How can I decode a base64 string using a custom letter set?

我知道 这个问题告诉我如何使用答案中提供的方法进行编码。

但是我不知道如何解码 运行 文件之后编码的内容以对一些文本进行编码。

这是我要加密的代码。

import base64

print("What would you like to encode? ")
data = input()

std_base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/="
custom = "abzdefghkjolsniprqmtuvwyxcDBCAEGFHJKILMNOPTRSQUVXWZY0629851743-&"

x = base64.b64encode(data.encode())
print('Here is your code!: ' + str(x)[2:-1].translate(str(x)[2:-1].maketrans(std_base64chars, custom)))

我将如何解码上述代码行的 output/encrypted 文本?

输出示例。

What would you like to encode? 
Hello World!
Here is your code!: mgvSBg4Fv23ZBgrH  <-- How do I decode that?

你只需要逆向操作即可。

转换正在交换您的字符集,因此请将它们交换回来。
现在你有了一个 base64 编码的字符串,它可以被解码成人类可读的东西。

data = input()
x = str(data).translate(str(data).maketrans(custom, std_base64chars))
print(base64.b64decode(x).decode())