The code has to follow the header provided below Overview En

The code has to follow the header provided below.

Overview: Encryptions and ciphers are very common in many areas of engineering. For this assignment, you must write a C++ program that implements a few common operations that involve a simple cipher engine. This functionality will be implemented through the development of an abstract data type (ADT). Objective: The main goal of this assignment is to gain experience in implementing abstract data types (ADTs) following the approach discussed in class. Additional goals include practice with constructor, destructor, dynamic memory allocation (for arrays). Project specification: Linear congruential generator (LCR) are a method to generate random number. However, traditionally it was used as cipher engine to encrypt documents during their physical transportation

The method of LCR is to generate a pseudo-randomized number based upon a given number through the recurrence relation as below:

Y = (a * X + c) mod m ,where Y is a new numbber, X is the given number, a is pre-set multiplier, c is pre-set increment, m is pre-set modulus.

We use modulus m as the total character numbers (29 total characters). If given a = 5, and c = 1. For character b, Y=(1 *5 + 1) mod 29 = 6, and in encrypted texts, we will write g For character p, Y=(15 *5 + 1) mod 29 = 18, and in encrypted texts, we will write s For character space, Y=(28 *5 + 1) mod 29 = 25, and in encrypted texts, we will write z Spring 2017 2 Therefore, a given text string, such as “I love you”, the encrypted string will become “mz.ntvzfno”. And without knowing the correct value of a, c, and m, it is very hard for anyone else to understand your documents.

In the project1 part B, you will need to implement an ADT version of the class LCR cipher. Your code should define this class by revising and extending the header file that is shown on the next page. An instance of the LCR cipher class will contain the following private data members:

A context char array: to store either original or encrypted string

A key char array: to store cipher keys which contains info about value of a and c

A bool variable: to tell whether the string is encrypted or not

Memory for above array must be allocated dynamically to contain the actual text contents. Your code must allocate the proper amount of memory, not an arbitrarily large block.

Normally, encrypted text contents and keys of how to encrypt the text are transferred separately, which ensures the safety of encrypted text contents. Here, we will use two files to represent each of them. First file will contain the info either encrypted string or original string. Second file will contain the string like what we have done in part A (e.g.: RRRRWWWZXXY). We can perform Run-length encoding (RLE) operation on it and retrieve two largest numbers for the value of a and c, for example:

Second file string: RRRRWWWZXXY

After RLE: R4W3ZX2Y

So: a=4 and c=3 for LCR encryption keys (modulus m will be 29)

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 (I recommend everyone do this as final project 1 will require this action anyway)

#include <iostream>

#include <iomanip>

#include <stdlib.h>

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

Solution

#include #include #include using namespace std; string encryptionMessage(string Msg) { string CTxt = \"\"; int a = 3; int b = 6; for (int i = 0; i < Msg.length(); i++) { CTxt = CTxt + (char) ((((a * Msg[i]) + b) % 26) + 65); } return CTxt; } string decryptionMessage(string CTxt) { string Msg = \"\"; int a = 3; int b = 6; int a_inv = 0; int flag = 0; for (int i = 0; i < 26; i++) { flag = (a * i) % 26; if (flag == 1) { a_inv = i; } } for (int i = 0; i < CTxt.length(); i++) { Msg = Msg + (char) (((a_inv * ((CTxt[i] - b)) % 26)) + 65); } return Msg; } int main(int argc, char **argv) { cout << \"Enter the message: \"; string message; cin >> message; cout << \"Message is :\" << message; cout << \"\ Encrypted Message is : \" << encryptionMessage(message); cout << \"\ Decrypted Message is: \" << decryptionMessage( encryptionMessage(message)); }
The code has to follow the header provided below. Overview: Encryptions and ciphers are very common in many areas of engineering. For this assignment, you must
The code has to follow the header provided below. Overview: Encryptions and ciphers are very common in many areas of engineering. For this assignment, you must

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site