Created
November 7, 2018 13:36
-
-
Save mkakh/c4f577dec22a414b21cdb9d00d158f72 to your computer and use it in GitHub Desktop.
大学2年のときに作った暗号・復号化プログラム シーザ暗号がベース
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[]) | |
| { | |
| int key; | |
| int i; | |
| int mode; | |
| char str[512]; | |
| FILE *fp; | |
| if (argc != 2) { | |
| fprintf(stderr, "Usage: %s FILENAME\n", argv[0]); | |
| exit(EXIT_FAILURE); | |
| } | |
| if ((fp = fopen(argv[1], "r")) == NULL) { | |
| fprintf(stderr, "%sが開けませんでした.\n", argv[1]); | |
| exit(EXIT_FAILURE); | |
| } | |
| fprintf(stderr, "mode> "); | |
| scanf("%d", &mode); | |
| mode %= 2; | |
| fprintf(stderr, "KEY> "); | |
| scanf("%d", &key); | |
| int shamt = key; | |
| while(fgets(str, sizeof(str), fp) != NULL) { | |
| i = 0; | |
| while(str[i] != '\0') { | |
| if (!mode) | |
| printf("%c", str[i++]+shamt); | |
| else | |
| printf("%c", str[i++]-shamt); | |
| shamt++; | |
| shamt %= 126-33; | |
| shamt+=32; | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment