Python编码base64打印新行



我想尝试用base64加密我的python代码。但当我使用n时,我会得到一个错误:

print("hello 
IndentationError: unexpected indent

这是我使用的代码:

import base64
def encode(data):
try:
# Standard Base64 Encoding
encodedBytes = base64.b64encode(data.encode("utf-8"))
return str(encodedBytes, "utf-8")
except:
return ""

def decode(data):
try:
message_bytes = base64.b64decode(data)
return message_bytes.decode('utf-8')
except:
return ""
your_code = encode("""
print("hello n world")
""")
exec(decode(your_code))

我可以使用两次print()函数而不是n,但有办法使用n吗?

我希望你能帮我解决

首先,您必须删除your_code部分中的缩进。其次,您必须用\n替换n

import base64

def encode(data):
try:
# Standard Base64 Encoding
encodedBytes = base64.b64encode(data.encode("utf-8"))
return str(encodedBytes, "utf-8")
except:
return ""

def decode(data):
try:
message_bytes = base64.b64decode(data)
return message_bytes.decode('utf-8')
except:
return ""

your_code = encode("""
print("hello \n world")
""")
exec(decode(your_code))

最新更新