
Danny B.
asked 12/02/20Need C++ coding Help Encryption and Decryption Using Substitution and Caesar Cipher.
Program Specification:
Using the techniques presented during this semester create a complete C++ program to emulate an
Encryption/Decryption Machine. The machine will be capable of the following:
Encrypt a string entered by the user
Choose between two different encryption methods
Decrypt a string entered by the user
Choose between two different decryptions methods
Decrypt without knowing the encryption method (provide all possible outputs)
The interface must be professional and fully intuitive to the user
The program will be menu driven.
The program will use a class to define and implement each of the methods as member functions and will
store the original string and the encrypted/decrypted strings as data members.
In addition to using a class you must also use all the major structures we used this semester including:
Selection statements (if, if-else, switch) the appropriate one(s) of course
Loops (while, for, do-while) the appropriate one(s) of course
Standard Libraries (don’t recreate the wheel)
Functions
Arrays
The two encryption/decryption methods are:
Substitution cipher
Caesar cipher
You will need to research each and determine how to implement them. Remember in the case of the
Caesar cipher there are 25 possible shifts, you must be able to choose or test for all 25 options.
1 Expert Answer

Patrick B. answered 12/03/20
Math and computer tutor/teacher
Here are the encryption and decryption methods that you need. Work on the menus LATER!!!
using namespace std;
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define ALPHABET ("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
typedef
class Cipher
{
public:
void EncryptCaesar(char * inbuff, int shiftNum, bool dir, char * outbuff)
{
char key[27];
if (dir)
{
memset(key,0,27);
strcpy(key,ALPHABET+shiftNum);
memcpy(key+26-shiftNum,ALPHABET,shiftNum);
}
else
{
memset(key,0,27);
memcpy(key,ALPHABET+26-shiftNum,shiftNum);
memcpy(key+shiftNum,ALPHABET,26-shiftNum);
}
cout << "key = >" <<key <<"<" << endl;
int N = strlen(inbuff);
memset(outbuff,0,N+1);
char chChar='?';
for (int iLoop=0; iLoop<N; iLoop++)
{
chChar = inbuff[iLoop];
if (isalpha(chChar))
{
outbuff[iLoop] = key[(toupper(chChar))-65];
}
else
{
outbuff[iLoop] = chChar;
}
}
}
void DecryptCaesar(char * inbuff, int shiftNum, bool dir, char * outbuff)
{
char key[27];
if (dir)
{
memset(key,0,27);
strcpy(key,ALPHABET+shiftNum);
memcpy(key+26-shiftNum,ALPHABET,shiftNum);
}
else
{
memset(key,0,27);
memcpy(key,ALPHABET+26-shiftNum,shiftNum);
memcpy(key+shiftNum,ALPHABET,26-shiftNum);
}
cout << "key = >" <<key <<"<" << endl;
int N = strlen(inbuff);
memset(outbuff,0,N+1);
char chChar='?';
for (int iLoop=0; iLoop<N; iLoop++)
{
chChar = inbuff[iLoop];
if (isalpha(chChar))
{
char * targetChar = strchr(key,toupper(chChar));
int iIndexPos = targetChar-key;
outbuff[iLoop] = ALPHABET[iIndexPos];
}
else
{
outbuff[iLoop] = chChar;
}
}
}
void EncryptSubstitution(char * inbuff, char * mixedAlphabetKey, char * outbuff)
{
int N = strlen(inbuff);
memset(outbuff,0,N+1);
char chChar='?';
for (int iLoop=0; iLoop<N; iLoop++)
{
chChar = inbuff[iLoop];
if (isalpha(chChar))
{
outbuff[iLoop] = mixedAlphabetKey[(toupper(chChar))-65];
}
else
{
outbuff[iLoop] = chChar;
}
}
}
void DecryptSubstitution(char * inbuff, char * mixedAlphabetKey, char * outbuff)
{
int N = strlen(inbuff);
memset(outbuff,0,N+1);
char chChar='?';
for (int iLoop=0; iLoop<N; iLoop++)
{
chChar = inbuff[iLoop];
if (isalpha(chChar))
{
char * targetChar = strchr(mixedAlphabetKey,toupper(chChar));
int iIndexPos = targetChar-mixedAlphabetKey;
outbuff[iLoop] = ALPHABET[iIndexPos];
}
else
{
outbuff[iLoop] = chChar;
}
}
}
void Decrypt(char * inbuff)
{
}
} *TCipher;
#define CIPHER_SIZE (sizeof(Cipher))
int main()
{
char inbuff[255];
char outbuff[255];
char str[255];
strcpy(inbuff,"The quick brown fox jumped over the lazy dogs.");
Cipher cipher;
cipher.EncryptCaesar(inbuff,5,false,outbuff);
cout << outbuff << endl;
cipher.DecryptCaesar(outbuff,5,false,str);
cout << str << endl;
char strKey[27];
strcpy(strKey,"SUPERMANBCDFGHIJKLOQTVWXYZ");
cipher.EncryptSubstitution(inbuff,strKey,outbuff);
cout << outbuff << endl;
memset(str,0,255);
cipher.DecryptSubstitution(outbuff,strKey,str);
cout << str << endl;
char strMsg[27];
strcpy(strMsg,"UIF RVJDL CSPXO GPY KVNQFE PWFS UIF MBAZ EPHT.");
for (int shiftLoop=0; shiftLoop<26; shiftLoop++)
{
memset(outbuff,0,255);
cipher.DecryptCaesar(strMsg,shiftLoop,true,outbuff);
cout << "shift # = " <<shiftLoop << " possible decrypt " << outbuff << endl;
}
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code uploaded to RESOURCES section12/03/20