大学问题Python 3密码创建的加密和保存

问题描述 投票:-1回答:1

[我知道这可能很简单,但是我是新手,并且在学习网络安全的第一年中

我已经拖曳了该站点和其他站点,或者大多数脚本都在python 2中或者对我不起作用

我正在使用repl来测试我的代码以确保其正常工作

这是我们必须为日志填写的问题

编写一个程序,询问用户是否要编码或解码如果进行编码,则要求输入要编码的内容和参考将编码后的值保存在以引用命名的文件中如果解码,请询问用户是否要从先前的文件或字符串中解码如果是文件,请询问用户以供参考,然后阅读相关文件并打印解码后的值如果是字符串,请询问用户以64为基数的字符串并打印解码后的值


这是我当前的脚本,我设法让用户输入密码,然后按要求对其进行加密和解密,一切正常,但是不确定用户在创建密码或保存密码时如何为用户添加“参考”进入文件并询问用户是否要从文件或字符串中解码:

# Note:encoding from base64 and decoding*

from base64 import b64encode
from base64 import b64decode

# Note:user input a password*

Password1 = input("Enter password")
encoded = b64encode(Password1.encode())

# Note:prints an encoded password*

print (encoded.decode('ascii'))

# Note:decode user input password*

decoded = b64decode(encoded)
print (decoded)

# Note:figure how to save password into a file*

save_path = ('passwords')
name_of_file = input ("What is the name of the file: ")

TIA:)

Sean

python python-3.x encryption base64 password-encryption
1个回答
0
投票

听起来您在这里有几个不同的问题。

首先,如何保存输出文件。

reference = prompt("Enter reference")
with open(reference + ".txt", "w+") as f:
    f.write( ... ) # put your output here like you were using print 
    f.close()

第二,如何询问用户是要从文件还是从字符串解码。

mode = input("file or string")
if mode is "file":
   #open and read from file
elif mode is "string":
   #prompt for password
else:
    print("error: unknown mode")
© www.soinside.com 2019 - 2024. All rights reserved.