c - Caesar Cipher shifting characters -
i had received assignment last month , ended getting wrong because of problem state after this. currently, doing caesar's cipher , believe have right format. ask user string , encrypted key == 3
. however, want loop around alphabet if plaintext letter x
, y
, z
, x
, y
, or z
. but, when put of characters in, not a
, b
, , c
, ]...
, other braces. hints fix problem. thank you!
void main() { int key = 3; char string[256]; int = 0; printf("enter string want encrypted\n"); fgets(string, sizeof(string), stdin); (i = 0; < strlen(string); i++) { if (string[i] == ' ') {;} else if ((string[i] >= 'a' && string[i] <= 'z' || string[i] >= 'a' && string[i] <= 'z')){ string[i] = string[i] + key; } } printf("cipher text:%s",string); }
you need @ ascii table: http://www.asciitable.com/. you're using ascii encoding of characters.
z has decimal value of 90, 93 ']'. need manually wrap around beginning of alphabet. best done modulo , adding ascii value of first alphabetic character. it's how wrap capital letters (back 'a' or 'a').
Comments
Post a Comment