I'm having a hard time understanding what to do with the ASCII keys & math formula. I understand that you move your plaintext over by the K amount, however, I'm not sure how to write this in code.

Maybe I'm not understanding the directions fully either - could someone explain to me what I should do next?

#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

// forumla is ci = (pi + k) % 26
// c = the new scrambled words
// p = the regular plain text
// k = the key number

// on each individual letter, move it K places over

// program must accept a single CLI argument!
int main(int argc, string argv[])
// access k string k = argv[2]
int k;
k = atoi(argv[2]);

printf("Could you give me a string? I'll encrypt it.\n");
string userInput = GetString();

// iterating the array 
for (int i = 0, n = strlen(userInput); i < n; i++)
    // prints a single digit
    printf("%d", userInput[i]);

  // print a new line at the end
  // return 0
  return 0;

In c, chars are essentially smaller ints. They have just enough bits to accomodate all ASCII symbols. You can add, subtract, multiply, divide, and % or mod, chars. For instance, printf("%c", 'a'-' ') should print 'A' each char corisponds to their ASCII number. So before doing that math you first need to convert 'A' or 'a' to 0. I hope that helps.

You must log in to answer this question.

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