Search code examples
pythoncryptographyblock-cipher

Given a plain text and a possible cipher text, determine whether the cipher text can be formed from the plain text using the mentioned scheme


The alphabets are enumerated as A = 0, B = 1, C = 2, ... , Z = 25. Consider an encryption scheme where a character with value Ci in the plaintext is replaced by another character with value Cj using the formula Cj = (Ci + 5) % 26. After replacement, the resulting string is shuffled (permuted) at random to obtain the cipher text.

Given a plain text and a possible cipher text, your task is to determine whether the cipher text can be formed from the plain text using the above mentioned scheme.

(Assume that all the strings are in uppercase)

Input Format:

The first line of the input contains a string indicating the plain text.

The second line of the input a string indicating a possible cipher text

Output Format:

Display Yes or No (no newline after the output)

Example:

Input:

PYTHON TDMSUY

Output:

Yes

Input:

JOCPNPTEL JQYVSUTHO

Output:

No

Please answer in Python


Solution

  • IPYNB Formatted Code Here

    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)