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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started