Last active
September 19, 2016 12:49
(Cs50) Caesar
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
#include <cs50.h> | |
#include <string.h> | |
#include <ctype.h> | |
int main(int input, string argv[]) | |
{ | |
if(input == 2) | |
{ | |
int key = atoi(argv[1]); | |
if (key > 0) | |
{ | |
string plaintext = GetString(); | |
for (int currentchar = 0, n = strlen(plaintext); currentchar < n; currentchar++) | |
{ | |
if(isalpha(plaintext[currentchar])) | |
{ | |
int a = plaintext[currentchar]; | |
char b; | |
if (isupper(a)) {b = 'A';} | |
else {b = 'a';} | |
plaintext[currentchar] = ((((plaintext[currentchar] + key)- b) % 26)+b); | |
} | |
printf("%c",plaintext[currentchar]); | |
} | |
printf("\n"); | |
} | |
else | |
{ | |
printf("<key> need to be a positive integer\n"); | |
return 1; | |
} | |
} | |
else | |
{ | |
printf("Invalid parameter !: caesar <key>\n"); | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment