Skip to content

Instantly share code, notes, and snippets.

@wolf99
Created April 29, 2015 10:41
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 wolf99/17c25d7da39b397632b4 to your computer and use it in GitHub Desktop.
Save wolf99/17c25d7da39b397632b4 to your computer and use it in GitHub Desktop.
Minimal caesar cipher implementation for CS50
#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