Skip to content

Instantly share code, notes, and snippets.

@AbstractBeliefs
Created September 5, 2014 22:06
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 AbstractBeliefs/47323393b1bbb091214b to your computer and use it in GitHub Desktop.
Save AbstractBeliefs/47323393b1bbb091214b to your computer and use it in GitHub Desktop.
#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