Created
September 5, 2014 22:06
-
-
Save AbstractBeliefs/47323393b1bbb091214b to your computer and use it in GitHub Desktop.
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> | |
void caeser(char* input, int shift){ | |
do { | |
*input = *input - 'a'; // convert to 0-idx alphabet | |
*input = *input + shift; // shift | |
*input = *input % 26; // wraparound going past z | |
*input = *input + 'a'; // shift back to ascii alphabet | |
} while (*++input); | |
return; | |
} | |
int main(int argc, char* argv[]) { | |
if (argc < 3){ | |
return 1; | |
} | |
int shift = atoi(argv[1]); | |
for (int i = 2; i < argc; i++){ | |
caeser(argv[i], shift); | |
printf("%s ", argv[i]); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment