Going through the CS50 exercise Caesar, and I'm still very new to C. My code to validate the key is all working, but as I try to convert from plaintext to the cipher text I keep getting caught up with the conversion form the ASCII number to the char. For example if I run the plaintext with the argv[1] as 27 I get /023/024. I recognize the math is off and if anyone has any pointers about that that would be great, but the main thing I'm curious about is why when I try to assign f into input[i] I get this "/000" type format.

string input = get_string("plaintext: ");
int len = strlen(input);
int i = 0;
while (input[i] != '\0')
    int mod = atoi(argv[1]);
    int t = input[i] + mod;
    int f = t % 26;
    input[i] = f;
printf("ciphertext: %s\n", input);

The issue is that the process is missing a couple of steps. The method that uses modulo requires that the letters, which are represented as ASCII values, must first be converted to numbers from 0 to 25 inclusive, and lastly, after the shift, must be reconverted from a number between 0 and 25 inclusive, back to an ASCII value.

You would likely benefit from reviewing the video that covers this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .