CN Assignment
CN Assignment
Question No. 1
● N becomes O
● A becomes B
● S becomes T
● I becomes J
● R becomes S
● Design an original and creative transformation for the encapsulation and decapsulation
processes.
Code:
def encapsulate(input_data):
encapsulated_message = ''.join([str(ord(character) + 3).zfill(3) for character in
input_data])
return encapsulated_message
def decapsulate(encapsulated_data):
split_chars = [encapsulated_data[i:i+3] for i in range(0, len(encapsulated_data), 3)]
decapsulated_message = ''.join([chr(int(chunk) - 3) for chunk in split_chars])
return decapsulated_message
initial_text = "AI2024"
encapsulated = encapsulate(initial_text)
decapsulated = decapsulate(encapsulated)
print(f"Initial Text: {initial_text}")
print(f"Encapsulated: {encapsulated}")
print(f"Decapsulated: {decapsulated}")
Encapsulation Process:
It takes through the character present in the string which is being entered and it just counters the
input and increments the ASCII value of character by 3 and then returns the encrypted string.
Decapsulation Process:
It takes through the encrypted string and then decrements the ASCII value of each character by 3
and then returns the decrypted string.
Main Function:
Takes the string from the user and then prints the original one and then displays the encrypted one
and then displays the decrypted one and then the program exits.