from cryptography.fernet import Fernet
import pyinputplus as pyip

print("Welcome to this basic password encryptor!")

key = Fernet.generate_key()
ask_action = pyip.inputStr("Please enter what action you would like to do: Encrypt/Decrypt, type 'stop' at any time to stop.")
while ask_action not in ['stop', 'Stop', 'STOP']:
    if ask_action in ['Encrypt', 'encrypt', 'ENCRYPT']:
        crypter = Fernet(key)
        user_pw = pyip.inputStr("Please enter the password you would like to encrypt:")
        bytes_pw = str.encode(user_pw)
        encrypted_pw = crypter.encrypt(bytes_pw)
        print("Here is your encrypted password: {}".format(encrypted_pw))
        ask_action = pyip.inputStr("Please enter what action you would like to do: Encrypt/Decrypt, type 'stop' at any time to stop.")

    elif ask_action in ['decrypt', 'Decrypt', 'DECRYPT']:
        decrypted_pw = crypter.decrypt(encrypted_pw)
        print("This is your decrypted pw: {}".format(decrypted_pw))
        ask_action = pyip.inputStr("Please enter what you would like to do: Encrypt/Decrypt, type 'stop' at any time to stop.")

print("Thank you for using this password encryptor!")
AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。QQ、微信在线,随时响应!V:Jiabcdefh
AI悦创 » python password encryptor

发表评论