Created
May 25, 2023 03:49
-
-
Save christianscott/14fbfd855f0b71e398d3107db7b15b5a to your computer and use it in GitHub Desktop.
caesar cypher .c
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> | |
int main(int argc, char *argv[]) { | |
if (argc <= 1) { | |
printf("Usage: %s [+/-shift]\n", argv[0]); | |
return 1; | |
} | |
char* shift_str = argv[1]; | |
int sign = 1; | |
if (shift_str[0] == '-') { | |
sign = -1; | |
shift_str++; | |
} else if (shift_str[0] == '+') { | |
shift_str++; | |
} | |
int shift = atoi(shift_str); | |
shift *= sign; | |
FILE* stdin = fopen("/dev/stdin", "r"); | |
while (!feof(stdin)) { | |
char c = fgetc(stdin); | |
if (c == EOF) { | |
break; | |
} | |
if (c == '\n') { | |
printf("\n"); | |
continue; | |
} | |
printf("%c", (c+shift)%256); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment