I recently started C++ and I wanted to create a simple ceaser cipher function that could be called on, however because I copied the coding structure form my python program I seem to be getting 4 errors and 2 warnings. The mode bit is a bool where true is to encrypt and false is to decrypt (it worked on python so hey) :).
First one on the line of me creating the function where "int" is, its saying "identifier "in" undefined"
Second one in the same line saying "expected a ')'"
Third one is after the 3 if statements, saying "identifier "CharPos" undefined" even though it is defined
And Forth on the same line saying "'CharPos': undeclared identifier"
#include <iostream>
#include <fstream>
#include <string>
std::string Encryption(std::string Password, int Key, bool Mode) {
std::string Alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
std::string EncryptPass = "";
if (Key > 36) {
Key = Key % 36;
}
for (int X = 0; X < Password.length(); X++) {
if (Password.at(X) == ' ') {
EncryptPass = EncryptPass + " ";
}
else {
for (int Y = 0; Y < 36; Y++) {
if (Password.at(X) == Alphabet.at(Y)) {
if (Mode == true) {
int CharPos = Y + Key;
if (CharPos > 35) {
CharPos = CharPos - 36;
}
}
if (Mode == false) {
int CharPos = Y - Key;
if (CharPos < 0) {
CharPos = CharPos + 36;
}
}
if (Mode != true and Mode != false) {
int CharPos = 0;
}
char CharPos2 = CharPos;
char EncryptChar = Alphabet.at(CharPos2);
EncryptPass = EncryptPass + EncryptChar;
}
}
}
}
return EncryptPass;
}
Any help would be appreciated