Fixed warning about comparing signed and unsigned integer types

This commit is contained in:
2018-05-13 22:26:42 -04:00
parent 0cfe5e40bd
commit 90dcd3412c
5 changed files with 18 additions and 18 deletions

View File

@@ -29,7 +29,7 @@ Atbash::~Atbash(){
*/ */
void Atbash::setInputString(std::string input){ void Atbash::setInputString(std::string input){
//Strip all punctuation and whitespace from input and make all letters capital //Strip all punctuation and whitespace from input and make all letters capital
for(int cnt = 0;cnt < input.size();++cnt){ for(unsigned int cnt = 0;cnt < input.size();++cnt){
char letter = input[cnt]; char letter = input[cnt];
//If it is upper case add it to the inputString //If it is upper case add it to the inputString
if(isupper(letter)){ if(isupper(letter)){
@@ -68,7 +68,7 @@ std::string Atbash::getOutputString() const{
*/ */
std::string Atbash::encode(){ std::string Atbash::encode(){
//Step through every element in the inputString and shift it the correct amount //Step through every element in the inputString and shift it the correct amount
for(int cnt = 0;cnt < inputString.size();++cnt){ for(unsigned int cnt = 0;cnt < inputString.size();++cnt){
outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A'))); outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A')));
} }
@@ -94,7 +94,7 @@ std::string Atbash::encode(std::string input){
* @return The decoded inputString (outputString) * @return The decoded inputString (outputString)
*/ */
std::string Atbash::decode(){ std::string Atbash::decode(){
for(int cnt = 0;cnt < inputString.size();++cnt){ for(unsigned int cnt = 0;cnt < inputString.size();++cnt){
outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A'))); outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A')));
} }

View File

@@ -79,7 +79,7 @@ std::string Caesar::getOutputString() const{
*/ */
std::string Caesar::encode(){ std::string Caesar::encode(){
char temp; //A temperary holder for the current working character char temp; //A temperary holder for the current working character
for(int cnt = 0;cnt < inputString.size();++cnt){ for(unsigned int cnt = 0;cnt < inputString.size();++cnt){
temp = inputString.at(cnt); temp = inputString.at(cnt);
//If it is a upper case letter shift it and wrap if necessary //If it is a upper case letter shift it and wrap if necessary
if(isupper(temp)){ if(isupper(temp)){
@@ -130,7 +130,7 @@ std::string Caesar::encode(int shiftAmount, std::string input){
*/ */
std::string Caesar::decode(){ std::string Caesar::decode(){
char temp; char temp;
for(int cnt = 0;cnt < inputString.size();++cnt){ for(unsigned int cnt = 0;cnt < inputString.size();++cnt){
temp = inputString.at(cnt); temp = inputString.at(cnt);
//If it is an upper case letter shift it and wrap if necessary //If it is an upper case letter shift it and wrap if necessary
if(isupper(temp)){ if(isupper(temp)){

View File

@@ -34,7 +34,7 @@ void Morse::setEncodeInputString(std::string input){
//Make sure the input is empty to begin //Make sure the input is empty to begin
std::string temp; std::string temp;
//Step through every element in input, removing anything that is not a letter and making all letters uppercase //Step through every element in input, removing anything that is not a letter and making all letters uppercase
for(int cnt = 0;cnt < input.size();++cnt){ for(unsigned int cnt = 0;cnt < input.size();++cnt){
char letter = input[cnt]; char letter = input[cnt];
//If it is a letter or number add it to the inputString, turning all letters capital //If it is a letter or number add it to the inputString, turning all letters capital
if(isalnum(letter)){ if(isalnum(letter)){
@@ -54,7 +54,7 @@ void Morse::setEncodeInputString(std::string input){
void Morse::setDecodeInputString(std::string input){ void Morse::setDecodeInputString(std::string input){
std::string temp; std::string temp;
//Step through every element in input, removing everything except . or - //Step through every element in input, removing everything except . or -
for(int cnt = 0;cnt < input.size();++cnt){ for(unsigned int cnt = 0;cnt < input.size();++cnt){
char letter = input[cnt]; char letter = input[cnt];
//If it is a letter or number add it to the inputString, turning all letters capital //If it is a letter or number add it to the inputString, turning all letters capital
if(letter == '.' || letter == '-' || letter == ' '){ if(letter == '.' || letter == '-' || letter == ' '){
@@ -95,7 +95,7 @@ std::string Morse::encode(){
std::string temp = inputString.str(); std::string temp = inputString.str();
//Loop through every element in the input string and see what type it is //Loop through every element in the input string and see what type it is
//while(!inputString.eof()){ //while(!inputString.eof()){
for(int cnt = 0;cnt < temp.size();++cnt){ for(unsigned int cnt = 0;cnt < temp.size();++cnt){
char letter; char letter;
//Get the next character in the input //Get the next character in the input
letter = temp[cnt]; letter = temp[cnt];

View File

@@ -45,7 +45,7 @@ void Playfair::createGrid(){
//Add any new leters from the keyword to the grid //Add any new leters from the keyword to the grid
///If you reach row 5 then the entire grid has been filled ///If you reach row 5 then the entire grid has been filled
char current; char current;
for(int cnt = 0;(cnt < keyword.size()) && (row < 5);++cnt){ for(unsigned int cnt = 0;(cnt < keyword.size()) && (row < 5);++cnt){
current = keyword[cnt]; current = keyword[cnt];
//If the current letter needs to be replaced, do so //If the current letter needs to be replaced, do so
if(current == REPLACED){ if(current == REPLACED){
@@ -176,7 +176,7 @@ std::string Playfair::encode(){
char letter1, letter2; char letter1, letter2;
int row1, col1, row2, col2; int row1, col1, row2, col2;
//Step through every element in the input string and encode a pair //Step through every element in the input string and encode a pair
for(int cnt = 1;cnt < inputString.size();cnt += 2){ for(unsigned int cnt = 1;cnt < inputString.size();cnt += 2){
//Grab two elements from the input string and search the grid for them //Grab two elements from the input string and search the grid for them
letter1 = inputString[cnt - 1]; letter1 = inputString[cnt - 1];
letter2 = inputString[cnt]; letter2 = inputString[cnt];
@@ -250,7 +250,7 @@ std::string Playfair::decode(){
char letter1, letter2; char letter1, letter2;
int row1, col1, row2, col2; int row1, col1, row2, col2;
//Step through every element in the input string and encode a pair //Step through every element in the input string and encode a pair
for(int cnt = 1;cnt < inputString.size();cnt += 2){ for(unsigned int cnt = 1;cnt < inputString.size();cnt += 2){
//Grab two elements from the input string and search the grid for them //Grab two elements from the input string and search the grid for them
letter1 = inputString[cnt - 1]; letter1 = inputString[cnt - 1];
letter2 = inputString[cnt]; letter2 = inputString[cnt];
@@ -323,7 +323,7 @@ void Playfair::setKeyword(std::string key){
//Make sure the keyword is blank //Make sure the keyword is blank
keyword = ""; keyword = "";
//Remove all punctuation and make everything capital //Remove all punctuation and make everything capital
for(int cnt = 0;cnt < key.size();++cnt){ for(unsigned int cnt = 0;cnt < key.size();++cnt){
//If it is an upper case letter, just add it to the keyword //If it is an upper case letter, just add it to the keyword
if(isupper(key[cnt])){ if(isupper(key[cnt])){
keyword += key[cnt]; keyword += key[cnt];
@@ -356,7 +356,7 @@ void Playfair::setInputString(std::string input){
//Make sure inputString is empty //Make sure inputString is empty
inputString = ""; inputString = "";
//Remove all punctuation and make everything capital //Remove all punctuation and make everything capital
for(int cnt = 0;cnt < input.size();++cnt){ for(unsigned int cnt = 0;cnt < input.size();++cnt){
char temp = input[cnt]; char temp = input[cnt];
if(isupper(temp)){ if(isupper(temp)){
//If the letter is the character than needs replaced, replace it //If the letter is the character than needs replaced, replace it
@@ -377,7 +377,7 @@ void Playfair::setInputString(std::string input){
} }
//Check if anything is doubled and needs bumped down by DOUBLED //Check if anything is doubled and needs bumped down by DOUBLED
for(int cnt = 1;cnt < inputString.size();){ for(unsigned int cnt = 1;cnt < inputString.size();){
char letter1, letter2; char letter1, letter2;
//Get two adjacent letters and compare them //Get two adjacent letters and compare them
letter1 = inputString[cnt - 1]; letter1 = inputString[cnt - 1];

View File

@@ -35,7 +35,7 @@ void Vigenere::setInputString(std::string input){
inputString = ""; inputString = "";
//Loop through every character in input. Remove all whitespace and punctuation and make sure all letters are capital and add it to inputString //Loop through every character in input. Remove all whitespace and punctuation and make sure all letters are capital and add it to inputString
for(int cnt = 0;cnt < input.size();++cnt){ for(unsigned int cnt = 0;cnt < input.size();++cnt){
char letter = input[cnt]; char letter = input[cnt];
if(isupper(letter)){ if(isupper(letter)){
inputString += letter; inputString += letter;
@@ -74,7 +74,7 @@ void Vigenere::setKeyword(std::string key){
//Make sure the keyword is blank //Make sure the keyword is blank
keyword = ""; keyword = "";
//Loop through every letter in the key and make sure all of them are uppercase letters //Loop through every letter in the key and make sure all of them are uppercase letters
for(int cnt = 0;cnt < key.size();++cnt){ for(unsigned int cnt = 0;cnt < key.size();++cnt){
char letter = key[cnt]; char letter = key[cnt];
if(isupper(letter)){ if(isupper(letter)){
keyword += letter; keyword += letter;
@@ -134,7 +134,7 @@ std::string Vigenere::encode(){
outputString.reserve(inputString.size()); outputString.reserve(inputString.size());
//Step through every charater in the inputString and advance it the correct amount, according to offset //Step through every charater in the inputString and advance it the correct amount, according to offset
for(int cnt = 0;cnt < inputString.size();++cnt){ for(unsigned int cnt = 0;cnt < inputString.size();++cnt){
char letter = (inputString[cnt] + offset[cnt % offset.size()]); //By using % you allow it to loop without having a separate counter char letter = (inputString[cnt] + offset[cnt % offset.size()]); //By using % you allow it to loop without having a separate counter
//Make sure the character is still a letter, if not, wrap around //Make sure the character is still a letter, if not, wrap around
if(letter < 'A'){ if(letter < 'A'){
@@ -174,7 +174,7 @@ std::string Vigenere::decode(){
outputString.reserve(inputString.size()); outputString.reserve(inputString.size());
//Step through every charater in the inputString and reduce it the correct amount, according to offset //Step through every charater in the inputString and reduce it the correct amount, according to offset
for(int cnt = 0;cnt < inputString.size();++cnt){ for(unsigned int cnt = 0;cnt < inputString.size();++cnt){
char letter = (inputString[cnt] - offset[cnt % offset.size()]); //By using % you allow it to loop without having a separate counter char letter = (inputString[cnt] - offset[cnt % offset.size()]); //By using % you allow it to loop without having a separate counter
if(letter < 'A'){ if(letter < 'A'){
letter += 26; letter += 26;