Python Function to Encrypt and Decrypt the String using join and split functions

#Function to Encrypt and Decrypt the String
def encrypt(St, Key):
    return Key.join(St)

def decrypt(St, Key):
    return St.split(Key)

#main program body

#Encrypting Plain Text to Cipher Text
plain = input("Enter plain message to encrypt: ")
code  = input("Enter Encryption Key: ")
cipher= encrypt(plain,code)
print("The encrypted string is :",cipher)

#Decrypting Cipher Text to Plain Text
pList=decrypt(cipher,code)

#pList is in the form of a List, converting back it to string below
plain="".join(pList)
print("The decrypted string is :",plain)




Output:

Enter plain message to encrypt: Hello World
Enter Encryption Key: @
The encrypted string is : H@e@l@l@o@ @W@o@r@l@d
The decrypted string is : Hello World

'''



No comments

Post your comments

Powered by Blogger.