| barnsta (5) | |
|
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; } | |
|
|
|
| Moschops (5959) | |
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? | |
|
|
|
| barnsta (5) | |
| Trying to print out the ciphered Text based upon what the user has inputted | |
|
|
|
| Moschops (5959) | |
Yes, I get that. What is this line:cipheredText[o] = cipheredText[b - 97];meant to do? | |
|
|
|
| barnsta (5) | |
| its meant to swap the value of the clean Text to what the cipher calulcation should be | |
|
|
|
| Moschops (5959) | |||
|
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
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
|
|||
| barnsta (5) | |
| How about the offsetvalue what do i declare that as? | |
|
|
|
| Moschops (5959) | ||
You know what a caesar cipher is, yes? What do you think it should be. | ||
|
Last edited on
|
||