SlideShare a Scribd company logo
1 of 5
Download to read offline
Please help reviewing the following code for caesar cipher (ccipher.h and ccipher.cc) which
is giving incorrect output. It must inherit from susbtitution cipher (cipher.cc) which I
include below as well as the wrong output and the expected output.
There are no typos, I've made sure of it so that is not reason.
SUBSTITUTION CIPHER
cipher.cc
#include "cipher.h"
/* Cheshire smile implementation.
It only contains the cipher alphabet
*/
struct Cipher::CipherCheshire {
string cipher_alpha;
};
/* This function checks the cipher alphabet
to make sure it's valid
*/
bool is_valid_alpha(string alpha);
// -------------------------------------------------------
// Cipher implementation
/* Default constructor
This will actually not encrypt the input text
because it's using the unscrambled alphabet
*/
Cipher::Cipher()
{
// TODO: Implement this default constructor
this->smile = new CipherCheshire();
this->smile->cipher_alpha = "abcdefghijklmnopqrstuvwxyz";
}
/* This constructor initiates the object with a
input cipher key
*/
Cipher::Cipher(string cipher_alpha)
{
// TODO: Implement this constructor
if (is_valid_alpha(cipher_alpha)) {
this->smile - new CipherCheshire();
this->smile->cipher_alpha = cipher_alpha;
} else {
cout << "Invalid alpha" << endl;
exit(EXIT_FAILURE);
}
}
/* Destructor
*/
Cipher::~Cipher()
{
// TODO: Implement this constructor
delete this->smile;
}
/* This member function encrypts the input text
using the intialized cipher key
*/
string Cipher::encrypt(string raw)
{
cout << "Encrypting...";
string retStr = "";
int length = raw.length();
int pos;
string alph = "abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < length; i++) {
if (raw[i] == ' ') {
retStr += ' ';
} else {
pos = find_pos(smile->cipher_alpha, LOWER_CASE(raw[i]));
if (isupper(raw[i])) {
retStr += UPPER_CASE(alph[pos]);
} else {
retStr += alph[pos];
}
}
}
cout << "Done" << endl;
return retStr;
}
/* This member function decrypts the input text
using the intialized cipher key
*/
string Cipher::decrypt(string enc)
{
string retStr;
int length = enc.length();
int pos;
string alph = "abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < length; i++) {
if (enc[i] == ' ') {
retStr += ' ';
} else {
pos = find_pos(smile->cipher_alpha, LOWER_CASE(enc[i]));
if (isupper(enc[i])) {
retStr += UPPER_CASE(alph[pos]);
} else {
retStr += alph[pos];
}
}
}
cout << "Done" << endl;
return retStr;
}
// -------------------------------------------------------
// Helper functions
/* Find the character c's position in the cipher alphabet/key
*/
unsigned int find_pos(string alpha, char c)
{
unsigned int pos = 0;
int i;
int size = alpha.length();
// TODO: You will likely need this function. Finish it.
char ch = tolower(c);
for (i = 0; i < size; i++) {
if (ch == alpha.at(i)) {
por = i;
break;
}
}
return pos;
}
/* Make sure the cipher alphabet is valid -
a) it must contain every letter in the alphabet
b) it must contain only one of each letter
c) it must be all lower case letters
ALL of the above conditions must be met for the text to be a valid
cipher alphabet.
*/
bool is_valid_alpha(string alpha)
{
bool is_valid = true;
if(alpha.size() != ALPHABET_SIZE) {
is_valid = false;
} else {
unsigned int letter_exists[ALPHABET_SIZE];
for(unsigned int i = 0; i < ALPHABET_SIZE; i++) {
letter_exists[i] = 0;
}
for(unsigned int i = 0; i < alpha.size(); i++) {
char c = alpha[i];
if(!((c >= 'a') && (c <= 'z'))) {
is_valid = false;
} else {
letter_exists[(c - 'a')]++;
}
}
for(unsigned int i = 0; i < ALPHABET_SIZE; i++) {
if(letter_exists[i] != 1) {
is_valid = false;
}
}
}
return is_valid;
}
CAESAR CIPHER:
ccipher.h
ccipher.cc
INPUT TEXT:
EXPECTED OUTPUT:
MY WRONG OUTPUT:
30 Sometimes it is the people no one can imagine anything of who do the things no one can
imagine Wsqixmqiw mx mw xli tistpi rs sri ger mqekmri ercxlmrk sj als hs xli xlmrkw rs sri ger
mqekmri Sometimes it is the people no one can imagine anything of who do the things no one
can imagine Sometimes it is the people no one can imagine anything of who do the things no one
can imagine Sometimes it is the people no one can imagine anything of who do the things no one
can imagine Okiapeiao ep eo pda laklha jk kja ywj eiwceja wjupdejc kb sdk zk pda pdejco jk kja
ywj eiwceja Kgewlaewk al ak lzw hwghdw fg gfw usf aesyafw sfqlzafy gx ozg vg lzw lzafyk fg
gfw usf aesyafw Sometimes it is the people no one can imagine anything of who do the things no
one can imagine Sometimes it is the people no one can imagine anything of who do the things no
one can imagine

More Related Content

Similar to Please help reviewing the following code for caesar cipher (ccipher-h.pdf

I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
Please help me fill out the TODO parts in the Caesar cipher that must.pdf
Please help me fill out the TODO parts in the Caesar cipher that must.pdfPlease help me fill out the TODO parts in the Caesar cipher that must.pdf
Please help me fill out the TODO parts in the Caesar cipher that must.pdf
anfenterprises
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfData StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
rozakashif85
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
ezonesolutions
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
MARRY7
 

Similar to Please help reviewing the following code for caesar cipher (ccipher-h.pdf (20)

Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
Embedding perl
Embedding perlEmbedding perl
Embedding perl
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
Please help me fill out the TODO parts in the Caesar cipher that must.pdf
Please help me fill out the TODO parts in the Caesar cipher that must.pdfPlease help me fill out the TODO parts in the Caesar cipher that must.pdf
Please help me fill out the TODO parts in the Caesar cipher that must.pdf
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfData StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
Network security
Network securityNetwork security
Network security
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Asterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAsterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up Telephony
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
2 BytesC++ course_2014_c8_ strings
2 BytesC++ course_2014_c8_ strings 2 BytesC++ course_2014_c8_ strings
2 BytesC++ course_2014_c8_ strings
 

More from pankajsingh316693

PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdfPLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
pankajsingh316693
 
Please help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdfPlease help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdf
pankajsingh316693
 
please help in python!!! (I have my code written below but i dont know.pdf
please help in python!!! (I have my code written below but i dont know.pdfplease help in python!!! (I have my code written below but i dont know.pdf
please help in python!!! (I have my code written below but i dont know.pdf
pankajsingh316693
 
Please give feedback on the below discussion- Networking Devices Route.pdf
Please give feedback on the below discussion- Networking Devices Route.pdfPlease give feedback on the below discussion- Networking Devices Route.pdf
Please give feedback on the below discussion- Networking Devices Route.pdf
pankajsingh316693
 

More from pankajsingh316693 (20)

PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdfPLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
PLEASE HELP ME--------------------- 1- Financing a start-up company St.pdf
 
Please help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdfPlease help with creating a javascript file to produce the outcome bel (1).pdf
Please help with creating a javascript file to produce the outcome bel (1).pdf
 
Please help with best magnification for- Duodenum - mucosa Duodenum -.pdf
Please help with best magnification for- Duodenum - mucosa Duodenum -.pdfPlease help with best magnification for- Duodenum - mucosa Duodenum -.pdf
Please help with best magnification for- Duodenum - mucosa Duodenum -.pdf
 
Please help What stage of the cell cycle is this cell- The nuclear mem.pdf
Please help What stage of the cell cycle is this cell- The nuclear mem.pdfPlease help What stage of the cell cycle is this cell- The nuclear mem.pdf
Please help What stage of the cell cycle is this cell- The nuclear mem.pdf
 
PLEASE HELP ME Use the Internet to identify three network firewalls-.pdf
PLEASE HELP ME  Use the Internet to identify three network firewalls-.pdfPLEASE HELP ME  Use the Internet to identify three network firewalls-.pdf
PLEASE HELP ME Use the Internet to identify three network firewalls-.pdf
 
Please help me with this Java programming question- Please find your o.pdf
Please help me with this Java programming question- Please find your o.pdfPlease help me with this Java programming question- Please find your o.pdf
Please help me with this Java programming question- Please find your o.pdf
 
please help in python!!! (I have my code written below but i dont know.pdf
please help in python!!! (I have my code written below but i dont know.pdfplease help in python!!! (I have my code written below but i dont know.pdf
please help in python!!! (I have my code written below but i dont know.pdf
 
Please help me with the above multiple choice questions- This is my la.pdf
Please help me with the above multiple choice questions- This is my la.pdfPlease help me with the above multiple choice questions- This is my la.pdf
Please help me with the above multiple choice questions- This is my la.pdf
 
PLEASE HELP ME ASAP----- 2- Advantages and disadvantages of IPOs An in.pdf
PLEASE HELP ME ASAP----- 2- Advantages and disadvantages of IPOs An in.pdfPLEASE HELP ME ASAP----- 2- Advantages and disadvantages of IPOs An in.pdf
PLEASE HELP ME ASAP----- 2- Advantages and disadvantages of IPOs An in.pdf
 
Please help me find the rock type ( Igneous- Sedimentary- or Metamorph.pdf
Please help me find the rock type ( Igneous- Sedimentary- or Metamorph.pdfPlease help me find the rock type ( Igneous- Sedimentary- or Metamorph.pdf
Please help me find the rock type ( Igneous- Sedimentary- or Metamorph.pdf
 
please help Data tableenter a zero-)(b) Prepare the statement of owner.pdf
please help Data tableenter a zero-)(b) Prepare the statement of owner.pdfplease help Data tableenter a zero-)(b) Prepare the statement of owner.pdf
please help Data tableenter a zero-)(b) Prepare the statement of owner.pdf
 
please help thanks Pedigree of a Family with Tay-Sachs Disease I II.pdf
please help  thanks  Pedigree of a Family with Tay-Sachs Disease I II.pdfplease help  thanks  Pedigree of a Family with Tay-Sachs Disease I II.pdf
please help thanks Pedigree of a Family with Tay-Sachs Disease I II.pdf
 
Please help How many pairs of homologous chromosomes are there in a c.pdf
Please help  How many pairs of homologous chromosomes are there in a c.pdfPlease help  How many pairs of homologous chromosomes are there in a c.pdf
Please help How many pairs of homologous chromosomes are there in a c.pdf
 
please help 9- The shoreline of the western Coromandel Peninsula is.pdf
please help   9- The shoreline of the western Coromandel Peninsula is.pdfplease help   9- The shoreline of the western Coromandel Peninsula is.pdf
please help 9- The shoreline of the western Coromandel Peninsula is.pdf
 
Please give feedback on the below discussion- Networking Devices Route.pdf
Please give feedback on the below discussion- Networking Devices Route.pdfPlease give feedback on the below discussion- Networking Devices Route.pdf
Please give feedback on the below discussion- Networking Devices Route.pdf
 
Please give an explanation if possible- thank you so much Singlet ox.pdf
Please give an explanation if possible- thank you so much   Singlet ox.pdfPlease give an explanation if possible- thank you so much   Singlet ox.pdf
Please give an explanation if possible- thank you so much Singlet ox.pdf
 
please fast answer Let X be a continuous random variable with cumulat.pdf
please fast answer  Let X be a continuous random variable with cumulat.pdfplease fast answer  Let X be a continuous random variable with cumulat.pdf
please fast answer Let X be a continuous random variable with cumulat.pdf
 
Please explain why you choose one of the four options as your answer-.pdf
Please explain why you choose one of the four options as your answer-.pdfPlease explain why you choose one of the four options as your answer-.pdf
Please explain why you choose one of the four options as your answer-.pdf
 
Please fill in the space complexity- Problem 2 -1 pt- The following ta.pdf
Please fill in the space complexity- Problem 2 -1 pt- The following ta.pdfPlease fill in the space complexity- Problem 2 -1 pt- The following ta.pdf
Please fill in the space complexity- Problem 2 -1 pt- The following ta.pdf
 
Please explain in detail so i can further my understanding of this top.pdf
Please explain in detail so i can further my understanding of this top.pdfPlease explain in detail so i can further my understanding of this top.pdf
Please explain in detail so i can further my understanding of this top.pdf
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

Please help reviewing the following code for caesar cipher (ccipher-h.pdf

  • 1. Please help reviewing the following code for caesar cipher (ccipher.h and ccipher.cc) which is giving incorrect output. It must inherit from susbtitution cipher (cipher.cc) which I include below as well as the wrong output and the expected output. There are no typos, I've made sure of it so that is not reason. SUBSTITUTION CIPHER cipher.cc #include "cipher.h" /* Cheshire smile implementation. It only contains the cipher alphabet */ struct Cipher::CipherCheshire { string cipher_alpha; }; /* This function checks the cipher alphabet to make sure it's valid */ bool is_valid_alpha(string alpha); // ------------------------------------------------------- // Cipher implementation /* Default constructor This will actually not encrypt the input text because it's using the unscrambled alphabet */ Cipher::Cipher() { // TODO: Implement this default constructor this->smile = new CipherCheshire(); this->smile->cipher_alpha = "abcdefghijklmnopqrstuvwxyz"; } /* This constructor initiates the object with a input cipher key */ Cipher::Cipher(string cipher_alpha) { // TODO: Implement this constructor if (is_valid_alpha(cipher_alpha)) { this->smile - new CipherCheshire();
  • 2. this->smile->cipher_alpha = cipher_alpha; } else { cout << "Invalid alpha" << endl; exit(EXIT_FAILURE); } } /* Destructor */ Cipher::~Cipher() { // TODO: Implement this constructor delete this->smile; } /* This member function encrypts the input text using the intialized cipher key */ string Cipher::encrypt(string raw) { cout << "Encrypting..."; string retStr = ""; int length = raw.length(); int pos; string alph = "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < length; i++) { if (raw[i] == ' ') { retStr += ' '; } else { pos = find_pos(smile->cipher_alpha, LOWER_CASE(raw[i])); if (isupper(raw[i])) { retStr += UPPER_CASE(alph[pos]); } else { retStr += alph[pos]; } } } cout << "Done" << endl; return retStr; } /* This member function decrypts the input text
  • 3. using the intialized cipher key */ string Cipher::decrypt(string enc) { string retStr; int length = enc.length(); int pos; string alph = "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < length; i++) { if (enc[i] == ' ') { retStr += ' '; } else { pos = find_pos(smile->cipher_alpha, LOWER_CASE(enc[i])); if (isupper(enc[i])) { retStr += UPPER_CASE(alph[pos]); } else { retStr += alph[pos]; } } } cout << "Done" << endl; return retStr; } // ------------------------------------------------------- // Helper functions /* Find the character c's position in the cipher alphabet/key */ unsigned int find_pos(string alpha, char c) { unsigned int pos = 0; int i; int size = alpha.length(); // TODO: You will likely need this function. Finish it. char ch = tolower(c); for (i = 0; i < size; i++) { if (ch == alpha.at(i)) { por = i; break;
  • 4. } } return pos; } /* Make sure the cipher alphabet is valid - a) it must contain every letter in the alphabet b) it must contain only one of each letter c) it must be all lower case letters ALL of the above conditions must be met for the text to be a valid cipher alphabet. */ bool is_valid_alpha(string alpha) { bool is_valid = true; if(alpha.size() != ALPHABET_SIZE) { is_valid = false; } else { unsigned int letter_exists[ALPHABET_SIZE]; for(unsigned int i = 0; i < ALPHABET_SIZE; i++) { letter_exists[i] = 0; } for(unsigned int i = 0; i < alpha.size(); i++) { char c = alpha[i]; if(!((c >= 'a') && (c <= 'z'))) { is_valid = false; } else { letter_exists[(c - 'a')]++; } } for(unsigned int i = 0; i < ALPHABET_SIZE; i++) { if(letter_exists[i] != 1) { is_valid = false; } } } return is_valid; } CAESAR CIPHER: ccipher.h ccipher.cc
  • 5. INPUT TEXT: EXPECTED OUTPUT: MY WRONG OUTPUT: 30 Sometimes it is the people no one can imagine anything of who do the things no one can imagine Wsqixmqiw mx mw xli tistpi rs sri ger mqekmri ercxlmrk sj als hs xli xlmrkw rs sri ger mqekmri Sometimes it is the people no one can imagine anything of who do the things no one can imagine Sometimes it is the people no one can imagine anything of who do the things no one can imagine Sometimes it is the people no one can imagine anything of who do the things no one can imagine Okiapeiao ep eo pda laklha jk kja ywj eiwceja wjupdejc kb sdk zk pda pdejco jk kja ywj eiwceja Kgewlaewk al ak lzw hwghdw fg gfw usf aesyafw sfqlzafy gx ozg vg lzw lzafyk fg gfw usf aesyafw Sometimes it is the people no one can imagine anything of who do the things no one can imagine Sometimes it is the people no one can imagine anything of who do the things no one can imagine