Created
June 10, 2017 14:29
-
-
Save MohamedTaha98/4bdf8398e7c0adb5e358f45aabc4d47d to your computer and use it in GitHub Desktop.
CS50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cs50.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <stdio.h> | |
int main (int argc, string argv[]) { | |
if (argc != 2) { | |
printf ("Please Enter Exactly 1 Key\n"); | |
return 1; | |
} | |
string key = argv[1]; | |
int lengthk = strlen(key); | |
for (int i = 0; i < lengthk; i++) { | |
if (isalpha(key[i])) { | |
if (isupper(key[i])) | |
key[i] -= 65; | |
else | |
key[i] -= 97; | |
} | |
else { | |
printf ("Please Enter a Text Key\n"); | |
return 1; | |
} | |
} | |
string s = GetString(); | |
int lengths = strlen(s); | |
int j = 0; | |
for (int i = 0; i < lengths; i++) { | |
j %= lengthk; | |
if (isalpha(s[i])) { | |
if (isupper(s[i])) { | |
s[i] -= 65; | |
s[i] = (s[i] + key[j]) % 26; | |
s[i] += 65; | |
} | |
else { | |
s[i] -= 97; | |
s[i] = (s[i] + key[j]) % 26; | |
s[i] += 97; | |
} | |
j++; | |
} | |
printf ("%c", s[i]); | |
} | |
printf ("\n"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment