求大佬解决(要源代码)(有赏)
第一题key = int(input("请输入秘钥:"))
clear_text = input("请输入明文:")
def translate(clear_text: str, key: int) -> str:
key = key % 26
j: str = ""
for s in clear_text:
letter_number = ord(s)
if (
letter_number + key <= 90
or letter_number >= 97
and letter_number + key <= 122
):
j += chr(letter_number + key)
else:
j += chr(letter_number + key - 26)
return j
cipher = translate(clear_text, key)
第二题
import re
import string
import random
c = string.ascii_letters + string.digits + string.punctuation
t =
s = "".join(t)
print(s)
letters = "".join(re.findall(r"\d", s))
digits = "".join(re.findall(r"", s))
punctuation = "".join(re.findall(r"[\W_]", s))
print(letters)
print(digits)
print(punctuation)
key=int(input('请输入秘钥:'))
s=input('请输入明文:')
a='abcdefghijklmnopqrstuvwxyz'
b=a+a[:key]
a+=a.upper()
b+=b.upper()
result=s.translate(str.maketrans(a,b))
print('密文为:',result)
第二个我还没学到正则表达式 第一题用判断:明文 + 密钥 - 32 >= 'Z' ,令其等于: 明文 + 密钥 - 32 - ’Z' +‘A' 即可
第二题用一个判断自然就将字符分开了 °蓝鲤歌蓝 发表于 2021-1-9 20:38
第一题
大佬我个人主页还有两道题有悬赏,您可以帮我看看嘛
页:
[1]