python - 给定一个纯文本和一个可能的密文,确定密文是否可以使用上述方案从纯文本形成
问题描述
字母表被枚举为 A = 0, B = 1, C = 2, ... , Z = 25。考虑一个加密方案,其中使用公式 Cj 将明文中具有值 Ci 的字符替换为具有值 Cj 的另一个字符= (Ci + 5) % 26.替换后,将得到的字符串随机打乱(置换)得到密文。
给定一个纯文本和一个可能的密文,你的任务是确定密文是否可以使用上述方案从纯文本中形成。
(假设所有字符串都是大写的)
输入格式:
输入的第一行包含一个指示纯文本的字符串。
输入的第二行一个字符串,表示可能的密文
输出格式:
显示是或否(输出后没有换行符)
例子:
输入:
Python TDMSUY
输出:
是的
输入:
JOCPNPTEL JQYVSUTHO
输出:
不
请用 Python 回答
解决方案
s = input()
p = input()
#s = s[::-1]
t = ''
for c in s:
t+=chr((ord(c)+5-ord('A'))%26 + ord('A'))
def removeSpaces(string):
string = string.replace(' ','')
string = string.replace(',','')
return string.lower()
def check(t, p):
# the sorted strings are checked
if(sorted(t)== sorted(p)):
print("Yes",end='')
else:
print("No",end='')
check(t, p)
推荐阅读
- php - 在 Netbeans 8.2 中调试期间为空调用堆栈
- javascript - javascript forEach() 函数如何在 mongodb shell 中迭代文档?
- python - 为什么代码会为我的两个变量提供 NameError?
- express - 快速路由器删除 - 404 未找到
- c++ - "+:", ":" 表示在 c++ 中的函数名之前
- c++ - 仅发布版本中的异常
- javascript - 滚动在移动视图上不起作用
- c# - 在 XAML 中无法访问 Helix SharpDx 工具包
- gnuplot - 在 GNU PLOT 中绘制一维轮廓
- laravel - “未定义的变量:书籍