Question: Write a utility class that encrypts and decrypts names. Your utility class should contain a cache of previously encrypted names so that if you encrypt

Write a utility class that encrypts and decrypts names.

Your utility class should contain a cache of previously encrypted names so that if you encrypt or decrypt a name, the cache is checked first to see if the name is there. You can implement the cache any way you would like.

Encryption algorithm: o Split the name into two equal parts. if it is an odd number length, then add a # at the end of the name to make the length even. Example:Amin -> "Am""in" Example:Vimal -> "Vim""al#"o Reverse the parts and concatenate back into one string Example: Amin -> Am in -> inAm Example: Vimal -> Vim al# -> al#Vimo Decryption would reverse this algorithm and remove the '#' symbol if present.

Encryption method: o If the non-encrypted name is in the cache, just return the encrypted name o Otherwise encrypt the name per the encryption algorithm, add to the cache, and return the encrypted name

Decryption method: o If the encrypted name is in the cache, return the non-encrypted name o Otherwise decrypt the name by reversing the encryption algorithm, add to the cache, and return the non-encrypted name

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!