Question
Create a class to encrypt and decrypt cstrings. Your encryptor class must be written with two constructors. A default constructor which initializes a seed with
Create a class to encrypt and decrypt cstrings. Your encryptor class must be written with two constructors. A default constructor which initializes a seed with a random number. And, a second constructor which takes one parameter to allow the user to set the seed. Calling an encrypt class member function with a cstring, passed by reference, encrypts the passed cstring instance by adding the seed value to every character in the cstring. Calling a decrypt class member function with a cstring, passed by reference, decrypts the passed cstring instance by subtracting the seed value from every character in the cstrring.
Requirements and Grading
1. Define a CstringEncryptor class in its own header file. In the class definition declare:
A private char seed member variable.
A default construtor.
A constructor that take on char parameter
An encrypt function that take a cstring passed by reference.
A decrypt function that take a cstring passed by reference.
Accessor and mutator functions for the seed member variable.
2. In a source file for the CstringEncryptor class functions define a default constructor for the CstirngEncryptor. In the constructor generate a random number between 0x00 and 0xFF and set the seed member variable to that.
3. In the CstringEncryptor class source file define a second constructor for the CstringEncryptor class that takes a char parameter and sets the class seed member variable to that parameter
4. In the CstringEncryptor class source file define the class encrypt member function that takes a cstring passed by reference. A dd the seed value to every character in the cstring parameter.
5. In the CstringEncryptor class source file define the class decrypt member function that takes a cstring passed by reference. S ubtract the seed value from every character in the cstring parameter.
6. In the CstringEncryptor class source file define the class mutator and accessor functions for the seed.
7. In the main function:
A. Create an instance of your CstringEncryptor class using the default constructor.
B. Create a second instance of you CstringEncryptor class using the constructor that requires 1 parameter. Pass in a value of 4 . C. Create a cstring and assign it a string literal value of your choice.
D. Print out the original message. E. Encrypt the cstring instance created in part C with the first CstringEncryptor instance. Then print out the encrypted cstring.
F. Decrypt the cstring instance created in part C with the first CstringEncryptor instance. Then print out the decrypted cstring.
G. Encrypt the cstring instance created in part C with the second CstringEncryptor instance. Then print out the encrypted cstring. H. Decrypt the cstring instance created in part C with the second CstringEncryptor instance. Then print out the decrypted cstring.
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