QWE密码
-
加密对象: 字母
-
原理:
-
就是一个简单地单表替换,该表是由电脑键盘的字母顺序来的,比如"Q"对应"A",“W"对应"B”,“E"对应"C”,对应如下下表:
明文 a b c d e f g h i j k l m n o p q r s t u v w x y z 密文 q w e r t y u i o p a s d f g h j k l z x c v b n m
-
-
代码
# write by 2021/7/23 # QWE密码 DIC_QWE = "qwertyuiopasdfghjklzxcvbnm" DIC_ABC = "abcdefghijklmnopqrstuvwxyz" def encrypt_qwe(string): ciphertext = "" string = string.replace(" ", "") for i in string: if i in string: if i in DIC_ABC: ciphertext += DIC_QWE[DIC_ABC.index(i)] else: return -1 return ciphertext def decrypt_qwe(string): plaintext = "" string = string.replace(" ", "") for i in string: if i in string: if i in DIC_QWE: plaintext += DIC_ABC[DIC_QWE.index(i)] else: return -1 return plaintext if __name__ == '__main__': ciphertext_ = encrypt_qwe("i love you") plaintext_ = decrypt_qwe(ciphertext_) print(f"{plaintext_}: {ciphertext_}")