Created
April 29, 2015 10:41
-
-
Save wolf99/17c25d7da39b397632b4 to your computer and use it in GitHub Desktop.
Minimal caesar cipher implementation for 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<stdio.h> | |
#include<stdlib.h> | |
#include<ctype.h> | |
#include<cs50.h> // Can be commented out if using test word | |
//char c[] = "hello"; // Uncomment these lines to use test word "hello". | |
//char *p = &c[0]; | |
int main(int argc, char * argv[]) { | |
char k=(argc>1)?k=atoi(*++argv):0; | |
if((argc<2)||(k<=0)){printf("Bad number.\n");return 1;} | |
else{ | |
string p=GetString(); // Comment this line out if using test word. | |
while(*p!=0) printf("%c",((isalpha(*p))?((((*p++-((isupper(*p))?65:97))+k)%26)+((isupper(*p))?65:97)):*p++)); | |
return 0; | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment