'''LAB 4 : WAP to accept a text from the user and perform encryption
and decryption on it using modules. The module should contain functions
that encrypt and decrypt the text, that take the text and key as parameters'''
cipher.py
'''Module to encrypt and decrypt a code '''
#CONSTANT
KEY='ac!if@me#o$'
def encrypt(x,k=KEY):
'''Function that accepts a message,a default arg k,
and returns the encrypted message'''
return k.join(x)
def decrypt(x,k =KEY):
'''Function that accepts an encrypted message , a default
argument k, and returns the decrypted message'''
l=x.split(k)
s=''.join(l)
return s
prog4.py
import cipher
text = input("Enter the text that you want to encrypt : ")
key=input("Enter the key : ")
ec = cipher.encrypt(text,key)
print('original text : ',text)
print('encrypted text : ', ec)
dc = cipher.decrypt(ec,key)
print('decrypted text : ', dc)
No comments:
Post a Comment