Caesar cipher print problems

The following code should print a suitable caesar cipher.

In my encrypt function (see below) the output is:
===
===
=ogpf
which is not what i want. please see code

char* Cipher::Encrypt(char* cipherAlphabet, char* cleanText, int groupCount)
{
char *cipheredText = new char[128];

int n = 0;
int o = 0;

for (int a = 0; cleanText[a] != NULL; a++)
{
char b = cleanText[a];
cipheredText[o] = cipheredText[b - 97];
o++;

if (((o+1)%(groupCount + 1)) == 0)
{
cipheredText[o] = '\n';
o++;
}
}

do
{
cipheredText[o] = (rand()%26+96);
o++;
}

while(((o+1)%(groupCount+1))!=0);

cipheredText[o] = '\0';
return cipheredText;

}
cipheredText[o] = cipheredText[b - 97];
This says; set the value of element o in the cipheredText array to be the same value as the element b - 97 of the same array. It's copying parts of cipheredText around itself. It makes no sense. What are you trying to do?
Trying to print out the ciphered Text based upon what the user has inputted
Yes, I get that. What is this line:
cipheredText[o] = cipheredText[b - 97];
meant to do?
its meant to swap the value of the clean Text to what the cipher calulcation should be
Well then you need to:

1) Get the letter you want to change.

unsigned char letterToChange = cleanText[i];

2) Change it

letterToChange = letterToChange + offsetValue;

3) Check that you haven't changed it off the end of the alphabet

1
2
3
4
if (letterToChange  > 'z')
{
  letterToChange   = letterToChange  - 26;
}


4) Write the changed letter into the ciphertext

cipheredText[i] = letterToChange;

The above code relies on the input text and output text being lower-case.
Last edited on
How about the offsetvalue what do i declare that as?
How about the offsetvalue what do i declare that as?

You know what a caesar cipher is, yes? What do you think it should be.
Last edited on
Topic archived. No new replies allowed.