Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A<--> N B<--> O C<--> P D<-->Q E<--> R F<--> S G<--> T H<--> U I<-->V J<-->W K<-

ID: 3547763 • Letter: A

Question


                 

                        A<--> N                     

                        B<--> O                     

                        C<--> P                     

                        D<-->Q                     

                        E<--> R                     

                        F<--> S                     

                        G<--> T                     

                        H<--> U                     

                        I<-->V                     

                        J<-->W                     

                        K<--> X                     

                        L<-->Y                     

                        M<--> Z                     


                 

                    Thus, the translation of the word JULIUS using ROT13 would be WHYVHF.                 

                    In this assignment, you will write a program that will allow for all Caesar Ciphers, using all rotation values (13 being an example above, from ROT13). You                    will also allow for rotation from both the left and right.                 

                    You will place a message, up to 200 characters (all in lowercase), in an input file. Your main() function shall read data from the                    file. Since this message may include spaces and newlines, we will use .get to read every character. Your program will also have 7 functions:                 

The Caesar Cipher is a simple letter substitution cipher (cipher: algorithm for performing encryption or decryption) that was developed in ancient Rome and used by Julius Caesar to communicate to his army. ROT13 is one instance of this cipher, and it replaces a letter with the letter 13 letters after it in the alphabet:

Explanation / Answer

#include <iostream>

#include <cstdlib>

#include <time.h>

#include <cctype>

using namespace std;

//pre: none

//post: returns true if the parameter is alphabetic, false otherwise

bool alphabetic (char ch);

//pre: array has been declared, size has been initialized

//post: user has been prompted for input. array has up to fifty characters accepted from keyboard. Size contains the number of characters stored in the array.

void fillArray(char array[], int& size);

//pre: array has been declared, size has been initialized to the size of the array

//post: array has been encrypted according to this algorithm:

void rot13(char array[], int size);

//pre: none

//post: returns true if the character is from the first half of the alphabet, false otherwise

bool firstHalf(char ch);

const int MAX = 50;

char Array[MAX];

int size = 0;

int main ()

{

char score[MAX];

int size;

fillArray (score,size);

rot13 (score,size);

return 0;

}

void fillArray (char array[], int& size)

{

cout << "Enter " << MAX << " characters. ";

for (char ch = 0; ch < size; ch++)

{

cin >>array[ch];

cout<<array[ch]<<endl;

}

}

bool alphabetic (char ch)

{

if (isalpha(ch))

return true;   

else

return false;

}

bool firstHalf (char ch)

{

if (('a'<=ch<='m')||('A'<=ch<='M'))

return true;

else

return false;

}

void rot13 (char array[], int size)

{

char ch;

bool alpha;

bool first;

alpha = alphabetic (ch);

first = firstHalf (ch);

if(alpha)

{

for(int i =0;array[i] < size;i++)

{

if(first)

{

i += 13;

cout<<i<<endl;

}

else

{

i-= 13;

cout<<i<<endl;

}

ch= array[i];

}

cout<<ch<<endl;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote