Question: _______________________________________________________________________________________________________________________ Assg_2.cbp (CBP File): ___________________________________________________________________________ Decoder.cpp (CPP File): #include decoder.h _________________________________________________________________________ Decoder.h (H File): #ifndef __DECODER_H__ #define __DECODER_H__ #endif // __DECODER_H__ _________________________________________________________________________ encoded (Text Doc):

_______________________________________________________________________________________________________________________ Assg_2.cbp (CBP File): ___________________________________________________________________________ Decoder.cpp (CPP File): #include "decoder.h" _________________________________________________________________________ Decoder.h(H File): #ifndef __DECODER_H__ #define __DECODER_H__ #endif // __DECODER_H__ _________________________________________________________________________ encoded (TextDoc): ITRERLNTHDHCAISDEMATIHAEZTASG ________________________________________________________________________ encoder.cpp (CPP File): #include "encoder.h" ______________________________________________________________________ encoder.h (H File):_______________________________________________________________________________________________________________________

Assg_2.cbp (CBP File):

___________________________________________________________________________

Decoder.cpp (CPP File):

#include "decoder.h"

_________________________________________________________________________

Decoder.h (H File):

#ifndef __DECODER_H__

#define __DECODER_H__

#endif // __DECODER_H__

_________________________________________________________________________

encoded (Text Doc): ITRERLNTHDHCAISDEMATIHAEZTASG

________________________________________________________________________

encoder.cpp (CPP File): #include "encoder.h"

______________________________________________________________________

encoder.h (H File): #ifndef __ENCODER_H__

#define __ENCODER_H__

#endif // __ENCODER_H__

________________________________________________________________________

message (text doc): I had the craziest dream last night

_______________________________________________________________________

railFence.cpp (cpp file): #include

#include

#include "encoder.h"

#include "decoder.h"

std::string msg;

int key;

///Determines the number of letters on each rail, given a key and an encoded message, and separates

///the encoded message into an array of size key, representing the rails. The length of the cycle

///must be determined, along with the size of the remainder representing an unfinished cycle.

void splitEncoded( std::string strarray[]){

int cycle= (2 * key)-2;

int div=cycle;

int len=msg.length();

int remainder=0;

int pos=0;

for(int i=0; i

int counter=((len)/div);

if(cycle!=0 && remainder!=0){

counter= 2*counter;

if((len%div)>=(div-(i-1))){

counter+=2;

}

else if((len%div)>i){

counter++;

}

}

else if(((len)%div)>i){

counter++;

}

strarray[i]=msg.substr(pos,counter);

pos+=counter;

cycle=cycle-2;

remainder+=2;

}

}

///Takes the filled array representing the rails and cycles down and up to

///to retrieve the chars in the correct order, building the decoded

/// message.

std::string concatDecoded( std::string strarray[], int len){

std::string decodedMsg;

int counter=0;

while(counter

for(int i=0; i

if(counter==len){

return decodedMsg;

}

decodedMsg+=strarray[i][0];

if(strarray[i].length()>1)

strarray[i]=strarray[i].substr(1);

else

strarray[i]="";

++counter;

}

for(int i=key-2; i>0; i--){

if(counter==len){

return decodedMsg;

}

decodedMsg+=strarray[i][0];

if(strarray[i].length()>1)

strarray[i]=strarray[i].substr(1);

else

strarray[i]="";

++counter;

}

}

return decodedMsg;

}

///returns a char converted to Uppercase

char toUpperCase (char c)

{

///FILL THIS FUNCTION: converts char c to UPPER CASE and returns UPPER CASE.

return c;

};

///Return true if char is alpha numeric

bool isAlphanumeric (char c)

{

///FILL THIS FUNCTION: evaluates char c, returns true if c is Alphanumeric (0-9, A-Z, a-z)

return true;///this is just a place holder for your return statement.

};

///Given an uncoded message and an array representing the rails

///cycles down and up the rails, filling the array until message ends

void splitMessage( std::string strarray[]){

int counter=0;

while(counter

for(int i=0; i

strarray[i]+= msg[counter];

++counter;

if(counter==msg.length())

return;

}

for(int i=key-2; i>0; i--){

strarray[i]+= msg[counter];

++counter;

if(counter==msg.length())

return;

}

}

};

///given a filled array representing the rails, concatenates the

///strings on the rails and returns a coded message

std::string concatEncoded(std::string strarray[]){

///FILL THIS FUNCTION: given an array of strings representing the rails,

///and the size of the array,

///concatenate the strings into a single string representing the encoded message and

///return it.

return "this is an encoded message";///this is just a place holder for your return statement

}

///given a message, formats the message for encoding or decoding

void prepmessage(){

///FILL THIS FUNCTION: given a message, converts message to all

///uppercase and removes non-alphanumeric characters including spaces

///and punctuation. Notice this is a VOID function!!!

}

///makes functions calls for encoding a message

void encodeMessage(){

prepmessage();

std::string encoded[key];//an array representing the rails

splitMessage(encoded);

msg=concatEncoded(encoded);

};

///makes function calls to decode a coded message

void decodeMessage(){

std::string decoded[key];//an array representing the rails

splitEncoded(decoded);

msg=concatDecoded( decoded, msg.length());

}

///**********************************************

///EVERYTHING BELOW THIS LINE REMAINS IN RAILFENCE.CPP

///**********************************************

///reads message from file stream in

std::string readMessage(std::istream& in)

{

std::string inmsg;

std::string line;

getline (in, line);

while (in)

{

inmsg = inmsg + line + " ";

getline (in, line);

}

return inmsg;

}

///given an out stream, prints the message

void printMessage(std::ostream& out){

out

out

}

///promps the user for a KEY 2-5

int getKey(){

int newkey;

while(true){

std::cout

if(std::cin>>newkey){

if(newkey>1 && newkey

break;

}

std::cout

std::cin.ignore();

}

std::cin.ignore();

return key;

};

///prints a menu and asks the user for a selection

char getselection(){

std::string selection="0";

std::cin.clear();

while(selection[0]'3'){

std::cout

getline(std::cin, selection);

if(selection[0]'3'){

std::cout

}

}

return selection[0];

}

int main()

{

bool quit=false;

while(!quit){

char select=getselection();

switch(select){

case '1':

key = getKey();

msg=readMessage(std::cin);

printMessage(std::cout);

encodeMessage();

printMessage(std::cout);

break;

case '2':

key = getKey();

msg=readMessage(std::cin);

printMessage(std::cout);

prepmessage();

decodeMessage();

printMessage(std::cout);

break;

case '3':

std::cout

quit=true;

}

}

return 0;

}

Objectives: This assignment will give you an opportunity to explore the process of dividing a C++ program into modules and using the project support components of a C++ IDE to manage your modules. General Instructions: Read the problem description below and implement this program in CH. The files for this assignment are provided under the folder for this assignment. You will be submitting two separate projects. See Part A and Part B for details. All of the functions making up this program are complete and in working order except for those marked with ///FILL THIS FUNCTION comments, which you must implement. The major challenge in this assignment is to divide the program into separately compiled modules. An Encoder module, consisting of files 'encoder.h' and 'encoder.cpp', containing code dealing specifically with encoding a message. A decoder module, consisting of files 'decoder.h' and 'decoder.cpp', containing code dealing specifically with decoding a message. There are some functions that are not specifically related to either of these modules, but that contain code needed by them. You should apportion these functions to the modules in a way consistent with the goals of high cohesion and low coupling. Consult the comments in the provided code for additional details. First step will be to change input from std::cin to taking input from a file called message.txt" or "encoded.txt". The given code has two Global Variables. Your finished code should have no Global Variables. Problem description: You have a friend who enjoys sending you messages that have been encrypted using a Rail Fence Cipher. While you could easily work them out by hand, sometimes the message is long, and after 15 minutes of work all you have is several rambling sentences about what they did or didn't do over the weekend. To save yourself some time, you decide to create a program to quickly decipher their messages, and even encode your responses The assignment will be to create a C++ program that, given txt file containing a coded message, will decode the message when given a key between 2 and 5. The program will also be able to encode a message given in a text file, using a corresponding key between 2 and 5. A Rail Fence Cipher is a type of transposition cipher. When given a message "I had the craziest dream last night" and a key representing the number of rails, the letters of the message are transposed onto the rails in a zig-zag pattern. Lets assume a key of 3': I...T... R ...E...R....N ... I H.D.H.C.A.I.S.D.E.M.A.T.I.H. ..A...E......I ...A...S...G.. As you can see the message goes down and up the rails, excluding spaces. Once the message is on the rails, it is read off row by row to get the following encoded message. ITRERLNTHDHCAISDEMATIHATEZTASG For the purposes of this assignment, you will have to remove the spaces and punctuation from the message before encoding it. The resulting encoded and decoded messages will be without spaces or punctuation, but that won't prevent the decoded message from being readable. Encoding with a key of 3: *****Welcome to Rail Fence Coder***** Menu: 1 encrypt a file 2 - decrypt a file 3 quit Selection: 1 Select a Key (2-5): 3 I had the craziest dream last night I TRERLNTH DHCAIS DEMAT IHAEZTASG Decoding a message that had been encoded with a key of 3: *****Welcome to Rail Fence Coder***** Menu: 1 encrypt a file 2 decrypt a file 3 quit Selection: 2 Select a key

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 Databases Questions!