In part B, you will need to implement an ADT version of the class linear Linear
ID: 3789723 • Letter: I
Question
In part B, you will need to implement an ADT version of the class linear Linear congruential generator LCR cipher in c++ program. Your code should define this class by revising and extending the header file that is shown on the next page.
Attention: not all encryption keys will work with LCR, as some encryption keys will cipher multicharacters into same one, which make unencrypt really hard. Your code need to do a check here, make sure the value from the keys are correct. If not, you code should reject the encryption request. Therefore, your client code will need to ask user to input two file names and then output the string after encryption. For extra credit, you code need to ask user whether to encrypt the string or to unencrypt the string. And then perform as requested.
in part A if the input was RRRRRB from the input file, then the output would be 5RB with the LCG algorithm.
#include
#include
#include
using namespace std;
class LCR_cipher
{
public:
// Constructor:
LCR_cipher(char *context_string, char *keys_string);
// Destructor: deallocate memory that was allocated dynamically
~LCR_cipher();
//check whether *keys string has valid LCR encryption value
Bool iskeysOK();
//encrypt context string
Void encryption();
//unencrypt context string (optional)
Void unencryption();
//check whether the context string is encrypted or not
Bool isencrypted();
//Retrieve CLR encryption value from *keys string
Void getkeys(int& a, int& c);
// output the *context to console
Void output_context();
private:
char *context;
//array to store context string
char *keys;
//array to store encryption keys
bool encrypted;
//whether string in *context is encrypted or not };
// End class
// End header file
Explanation / Answer
#include using namespace std; class mRND { public: void seed(unsigned int s) { _seed = s; } protected: mRND() : _seed(0), _a(0), _c(0), _m(2147483648) { } int rnd() { return (_seed = (_a * _seed + _c) % _m); } int _a, _c; unsigned int _m, _seed; }; class MS_RND: public mRND { public: MS_RND() { _a = 214013; _c = 2531011; } int rnd() { return mRND::rnd() >> 16; } }; class BSD_RND: public mRND { public: BSD_RND() { _a = 1103515245; _c = 12345; } int rnd() { return mRND::rnd(); } }; int main(int argc, char* argv[]) { BSD_RND bsd_rnd; MS_RND ms_rnd; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.