作为学校工作,我正在尝试制作密码加密/解密程序。我需要考虑以下规则:
如果密码违反这些条件,我将终止程序:
print('Invalid password!')
sys.exit()
Run Code Online (Sandbox Code Playgroud)
我已经被困了几个小时试图添加这些条件......我不知道在哪里添加这些条件,无论我在哪里添加它们,即使我输入了有效的密码,我的程序也会终止TT
这是我到目前为止所拥有的(我已经删除了解密部分,以便我之后可以尝试为自己找出该部分):
# import sys module for termination
import sys
# init
password_out = ''
case_changer = ord('a') - ord('A')
encryption_key = (('a','m'), ('b','h'), ('c','t'), ('d','f'), ('e','g'),
('f','k'), ('g','b'), ('h','p'), ('i','j'), ('j','w'), ('k','e'),('l','r'),
('m','q'), ('n','s'), ('o','l'), ('p','n'), ('q','i'), ('r','u'), ('s','o'),
('t','x'), ('u','z'), ('v','y'), ('w','v'), ('x','d'), ('y','c'), ('z','a'),
('#', '!'), ('@', '('), ('%', ')'), ('0'), ('1'), ('2'), ('3'), ('4'), ('5'),
('6'), ('7'), ('8'), ('9'))
encrypting …Run Code Online (Sandbox Code Playgroud)