Help with a cipher code
Feb 19, 2014 at 3:28am UTC
Ok, so as far as I can tell I have written everything right in this, but every time I try to run, it initializes, gets through two lines of, then tells me there is a fatal error involving my strings and my professor basically told me I was on my own to solve it, but I'm clueless. Any thoughts?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#include <iostream>
#include <string>
#include "SubstCipher.h"
using namespace std;
SubstCipher::SubstCipher(string newCipher)
{
newCipher = cipherKeys;
}
int SubstCipher::charToAlphabetPosition(char c)
{
return static_cast <int >(c) - static_cast <int >('a' );
}
char SubstCipher::alphabetPositionToChar(int pos)
{
return static_cast <char >(pos + static_cast <int >('a' ));
}
string SubstCipher::getCipherKeys()
{
return cipherKeys;
}
void SubstCipher::setCipherKeys(string newKey)
{
cipherKeys = newKey;
}
char SubstCipher::encodeChar(char newChar)
{
return cipherKeys[charToAlphabetPosition(newChar)];
}
char SubstCipher::decodeChar(char oldChar)
{
return alphabetPositionToChar(cipherKeys.find(oldChar));
}
string SubstCipher::encodeString(string newString)
{
string codeString = "" ;
for (int i=0; i < newString.length(); i++)
{
char letter;
letter = newString[i];
letter = encodeChar(letter);
codeString = codeString + letter;
}
return codeString;
}
string SubstCipher::decodeString(string oldString)
{
string decodeString = "" ;
for (int i=0; i < oldString.length(); i++)
{
char code;
code = oldString[i];
code = decodeChar(code);
decodeString = decodeString + code;
}
return decodeString;
}
Feb 19, 2014 at 3:33am UTC
I vote you're in the wrong forum. Try the General C++ programming.
Feb 19, 2014 at 3:40am UTC
8 9 10 11
SubstCipher::SubstCipher(string newCipher)
{
newCipher = cipherKeys;
}
Did you perhaps mean
cipherKeys = newCipher;
?
Feb 19, 2014 at 3:50am UTC
Oh my gosh that's it!! Thank you so much! You just saved my royal rear end!
Topic archived. No new replies allowed.