Open In App

Cryptophasia Code in Python

Cryptophasia is a language that is created and spoken between twins before they learn their own mother tongue. Since no one knows that language, it still remains a secret. As humans never left a stone unturned, Scientists have found that this language is created, just by mispronouncing the existing language that we all know. Doesn’t this remind you about encryption? Yes, it’s quite similar. All we need to do is, change a few grammatical rules of a particular language so that the reader should know these rules in order to decrypt them.

Technique Used

As we all know, we could still read a misspelled word correctly, if their first and last alphabets are right. So, this explains the importance of the first and the last alphabets in a word in reading it properly. Cryptophasia wisely uses this technique, to encrypt a word. It changes the first and the last alphabets of a word and encrypts it. Now let’s see the rules that are been followed to achieve this state, so that no one can decrypt these words, except those who know these rules.



Rules:

apple --> pple
pple --> pplea
pplea --> ppleaay

The word ‘apple’ has been encrypted into ‘ppleaay’. In this way, any word can be encrypted into an unknown form, making it difficult for the reader to understand it.

Implementation

Before coding, we should be aware that the input can be of any form. They may contain uppercase and lowercase alphabets, special characters, spaces, and numbers. In order to encrypt it efficiently, we won’t be using uppercase alphabets and special characters. Because when these uppercase and special characters are present in the word, it can even provide a clue to the reader about the word.



A few cases can be as follows:

This makes us realize that it’s really needed to:

Since strings are immutable, it is quite difficult to make changes in a given word. So, it’s highly essential to convert the string into a list that is mutable. In our program, since we are playing with alphabets of a word, splitting the alphabets of the word as well into a list plays an important role.

Below is the implementation.




# Cleaning & Converting Text into List
def CleConvStr2List(text):
    A, B, C = ([] for i in range(3))
  
    # Split line into words
    A = text.split()
  
    # Removing special chars from word
    for i in range(len(A)):
        B.append(''.join(e for e in A[i] if e.isalnum()))
          
    while('' in B):
        B.remove("")
  
    # Split word into chars
    for i in range(len(B)):
        C.append(list(B[i]))
          
    return C
  
# Performing Cryptophasia
def Cryptophasia(text):
    C = []
    C = CleConvStr2List(text)
      
    for i in range(len(C)):
        C[i].append(C[i][0])
        C[i].append('a')
        C[i].append('y')
        del C[i][0]
          
    D = []
    word = ''
      
    for i in range(len(C)):
        D.append(word.join(C[i]))
          
    return " ".join(D)
  
# Driver Code
print(Cryptophasia('Apple'))
print(Cryptophasia('GeeksforGeeks'))
print(Cryptophasia('happy'))

Output:

ppleAay
eeksforGeeksGay
appyhay

Article Tags :