编译和评估 base64 字符串

Ale*_*dre 3 python base64 eval python-3.x

这是我最近看到的一些代码:

import base64

code="CmltcG9ydCBweW1vbmdvCmltcQ" #very long
eval(compile(base64.b64decode(code), "<string>", 'exec'))
Run Code Online (Sandbox Code Playgroud)

我知道它的作用,解码它非常重要。但我很好奇如何自己做。因此,如果我有一个应用程序并且我想对其进行编码并使其通过代码运行,我应该如何对其进行编码以获取它的 base64 字符串?

Mar*_*ers 5

您对包含在字符串中的有效 python 源代码进行编码:

import base64

source = '''\
print('Hello World!')
print('Not sure why you'd ever do this though..')
'''
code = base64.b64encode(source)
Run Code Online (Sandbox Code Playgroud)