首页 前端知识 Python 给定一段密文字符串,字符都是映射得来,现在需要解密并输出。映射规则是:('a'-'i')分别用('1'-'9')表示,('j'-'z')分别用('10*'-'26*'表示

Python 给定一段密文字符串,字符都是映射得来,现在需要解密并输出。映射规则是:('a'-'i')分别用('1'-'9')表示,('j'-'z')分别用('10*'-'26*'表示

2024-04-18 18:04:28 前端知识 前端哥 807 145 我要收藏
```python
复制

def decrypt(ciphertext): mapping = { '1': 'a', '2': 'b', '3': 'c', '': 'd', '5': 'e', '6': 'f', '': 'g', '8': 'h', '9': 'i', '10*': 'j', '11*': 'k', '12*': 'l', '13* 'm', '14*': 'n', '15*': 'o', '16*': '', '17*': 'q', '': 'r', '19': 's', '20*': 't', '21*': 'u', '22*': 'v', '23*': 'w', '24*': 'x', '25*': 'y', '26*': 'z' }

result = ''
i =0
while i < len(ciphertext):
if i 2 < len(ciphertext) and ciphertext[i:i 3] in mapping:
复制

result = mapping[ciphertext[i:i 3]] i = 3 else: result = mapping[ciphertext[i]] i =1

return result
复制

ciphertext = '1023151818145191923120914723920819318916**914*7' print(decrypt(ciphertext))

输出为:
复制

knowledgeiswaitingthisiscripting ```

转载请注明出处或者链接地址:https://www.qianduange.cn//article/5212.html
标签
评论
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!