题解 | #字符串加解密# 写个密码本
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
思路:按照规则写两个密码本,对应加密和解密
def en_de_code(exp1, exp2): # 密码本 l1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" l2 = "BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza1234567890" res = "" #对照密码本加密解密 for i in exp1: if exp2 == 1: res += l2[l1.index(i)] elif exp2 == -1: res += l1[l2.index(i)] return res print(en_de_code(input(), 1)) print(en_de_code(input(), -1))
华为机试(python3) 文章被收录于专栏
少壮不努力,老大勤刷题