Skip to content

Instantly share code, notes, and snippets.

/caesar.c Secret

Created April 5, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/90e2154d85f7224aff7279cd964bda99 to your computer and use it in GitHub Desktop.
Save anonymous/90e2154d85f7224aff7279cd964bda99 to your computer and use it in GitHub Desktop.
caesar.c - shared from CS50 IDE
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int c;
int k;
int main(int argc, string argv[]) {
if (argc == 0 || argc >2) {
printf ("ERROR\n");
return 1;
}
k = atoi(argv[1]);
string p = GetString();
printf("plaintext: %s\n", p);
printf ("ciphertext: ");
for (int i = 0, n = strlen(p); i < n; i++) {
if (isalpha (p[i])) {
c = (p[i] + k)%26;
printf ("%c", (char) c);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment