首页 > 解决方案 > 给定一个纯文本和一个可能的密文,确定密文是否可以使用上述方案从纯文本形成

问题描述

字母表被枚举为 A = 0, B = 1, C = 2, ... , Z = 25。考虑一个加密方案,其中使用公式 Cj 将明文中具有值 Ci 的字符替换为具有值 Cj 的另一个字符= (Ci + 5) % 26.替换后,将得到的字符串随机打乱(置换)得到密文。

给定一个纯文本和一个可能的密文,你的任务是确定密文是否可以使用上述方案从纯文本中形成。

(假设所有字符串都是大写的)

输入格式:

输入的第一行包含一个指示纯文本的字符串。

输入的第二行一个字符串,表示可能的密文

输出格式:

显示是或否(输出后没有换行符)

例子:

输入:

Python TDMSUY

输出:

是的

输入:

JOCPNPTEL JQYVSUTHO

输出:

请用 Python 回答

标签: pythoncryptographycypher

解决方案


IPYNB 格式的代码在这里

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)

推荐阅读