Caesar's encoding problem
I have an exercise that is based in Caesar's encoding method.
I have to encode ASCII characters from:
32 to 127 with any key.
key may be [1, any integer].
I made two functions one for encoding end the second for decoding ....when i encode a word i cant get the original back after decoding....can you help?
I think MOD is the problem..
This is the encode function:
Code:
char *Ceasar_enc(char text[],int key) {
char *p=text;
long int temp;
while(*p){
/* 127 - 32= 96 ascii values plus 32 to start from 32 not from 0 and end to ascii char 127 not 96
*/
temp=(*p+key)%96+32;
*p++=(char)temp;
}
This is the decode function-i didnt write the decode formula because every time i write one i get faulse results
Code:
char *Ceasar_dec(char text[],int key) {
char *p=text;
long temp;
while(*p){
/* i cant find the correct decode formula */
*p++=(char)temp;
}
return text;
}