python:通過函數實現手機號的加密、解密

# 聲明一個函數 將電話進行加密 返回加密後的內容
# 解密函數:傳入加密後的內容 返回的是電話號碼
# 電話號碼不固定


# 加密
def encryption():
    content = input("請輸入您的電話號碼: ")
    if len(content) == 11:
        phone = '0123456789'
        password = 'abcdefghij'
        encryption_tab = str.maketrans(phone, password)
        res1 = content.translate(encryption_tab)
        print("請保管好您的密碼: ", res1)
        return res1
    else:
        print("請檢查你的手機號是否輸入正確!")


res1 = encryption()


# 解密
def decrypt():
    content = input("請輸入您的密碼: ")
    if len(content) == 11:
        phone = '0123456789'
        password = 'abcdefghij'
        decrypt_tab = str.maketrans(password, phone)
        res2 = content.translate(decrypt_tab)
        print("這是您的電話號碼: ", res2)
        return res2
    else:
        print("請檢查你的密碼是否輸入正確!")


res2 = decrypt()


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章