Skip to content

Instantly share code, notes, and snippets.

@MohamedTaha98
Last active June 10, 2017 14:28
Show Gist options
  • Save MohamedTaha98/ca82295cc22f1f8cd574dc28a766d2cc to your computer and use it in GitHub Desktop.
Save MohamedTaha98/ca82295cc22f1f8cd574dc28a766d2cc to your computer and use it in GitHub Desktop.
CS50
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
int main (int argc, string argv[]) {
if (argc != 2) {
printf ("Please Enter 1 Key\n");
return 1;
}
int key = atoi (argv[1]);
string s = GetString();
if (s != NULL) {
for (int i = 0, length = strlen(s); i < length; i++) {
if (isalpha(s[i])) {
if (isupper(s[i])) {
s[i] -= 65;
s[i] = (s[i] + key) % 26;
s[i] += 65;
}
else {
s[i] -= 97;
s[i] = (s[i] + key) % 26;
s[i] += 97;
}
}
printf ("%c", s[i]);
}
printf ("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment