Hello everyone!
Well I"m supposed to make a version of the ceaser cipher and I thought I got it to work, but when I run the program it goes all the way to the end of cout << "Result:\n"; then terminates even though I have it to output the array.
I can't figure out what's wrong. Thanks for any help, much appreciated.
In the last case you can use the equality operator "==".
Additionaly, you should fix it:
Use src[counter] =+ key; instead of src[counter] = + key;
Moreover you have to check the source code. You made lots of mistakes. In encrypt section if you add a number to an element of the src array, you should substruct from element of src array in decrypt section.
I.e.:
1 2 3 4 5 6 7 8 9 10
void caesar_encrypt(char src[], int key, char dst[])
{
for(int counter = 0;counter < strlen(src);counter++)
{
if (src[counter] >= 65 && src[counter] <= 90)
{
src[counter] =+ key;
if (src[counter] + key > 90)
src[counter] -= 32;
and so on
1 2 3 4 5 6 7 8 9
void caeser_decrypt(char src[], int key, char dst[])
{
for (int counter = 0;counter < strlen(src);counter++)
{
if (src[counter] >= 65 && src[counter] <= 90)
{
src[counter =- key];
if (src[counter] - key > 90)
src[counter] += 32;
Alright so by what you showed me I tried doing the rest of the encrypt and decrypt function along with the string issue. I still get the same thing though with the whole compile time error. Sorry I get confused I'm more of a visual learner.
And of course in the decrypt section you should do it.
src[counter] = - 32 means the -32 value is put to src[counter]. You should substract 32 from src[counter]. It means the followings src[counter] = src[counter] - 32; in other words src[counter] =- 32;
The other problem when use the src[counter =- key];. Here you change the index of array to negative! number instead of substract a number from an element of src array. src[counter] -=key;
I have made simplest program from yours. It doesn't test if the encrypted text will be in alphabet range! In other words it is possible that one of character will be a sign after encrypting. I think you should understand it before creating more complex program.