diff options
Diffstat (limited to 'C/HF/chap7')
| -rw-r--r-- | C/HF/chap7/Makefile | 14 | ||||
| -rw-r--r-- | C/HF/chap7/ecat.c | 23 | ||||
| -rw-r--r-- | C/HF/chap7/ecat.core | bin | 0 -> 12046336 bytes | |||
| -rw-r--r-- | C/HF/chap7/encrypt.c | 6 | ||||
| -rw-r--r-- | C/HF/chap7/encrypt.h | 7 | ||||
| -rw-r--r-- | C/HF/chap7/ls.txt | 1 | ||||
| -rw-r--r-- | C/HF/chap7/message.c | 13 | ||||
| -rw-r--r-- | C/HF/chap7/text.txt | 1 | ||||
| -rw-r--r-- | C/HF/chap7/xor.c | 20 | ||||
| -rw-r--r-- | C/HF/chap7/xor.h | 7 |
10 files changed, 92 insertions, 0 deletions
diff --git a/C/HF/chap7/Makefile b/C/HF/chap7/Makefile new file mode 100644 index 0000000..64312d5 --- /dev/null +++ b/C/HF/chap7/Makefile @@ -0,0 +1,14 @@ +ecat: ecat.o encrypt.o + cc -o ecat ecat.o encrypt.o + +ecat.o: encrypt.h ecat.c + cc -c ecat.c + +message: message.o encrypt.o + cc -o message message.o encrypt.o + +message.o: encrypt.h message.c + cc -c message.c + +encrypt.o: encrypt.h encrypt.c + cc -c encrypt.c diff --git a/C/HF/chap7/ecat.c b/C/HF/chap7/ecat.c new file mode 100644 index 0000000..ec034e4 --- /dev/null +++ b/C/HF/chap7/ecat.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include "xor.h" +#include "encrypt.h" + +int main(int argc, char **argv) +{ + FILE *fd; + char buf[80]; + + if (argc != 2) + return 1; + + fd = fopen(argv[1], "r"); + + while (fgets(buf, 80, fd)) { + encrypt(buf, xor64); + printf("%s", buf); + } + + printf("\n"); + fclose(fd); + return 0; +} diff --git a/C/HF/chap7/ecat.core b/C/HF/chap7/ecat.core Binary files differnew file mode 100644 index 0000000..2b80a6f --- /dev/null +++ b/C/HF/chap7/ecat.core diff --git a/C/HF/chap7/encrypt.c b/C/HF/chap7/encrypt.c new file mode 100644 index 0000000..1b5ce25 --- /dev/null +++ b/C/HF/chap7/encrypt.c @@ -0,0 +1,6 @@ +#include "encrypt.h" +typedef void (*encrypt_fn_t)(char *message); + +void encrypt(char *message, encrypt_fn_t encrypt_fn) { + encrypt_fn(message); +} diff --git a/C/HF/chap7/encrypt.h b/C/HF/chap7/encrypt.h new file mode 100644 index 0000000..4e130e9 --- /dev/null +++ b/C/HF/chap7/encrypt.h @@ -0,0 +1,7 @@ +#ifndef ENCRYPT_H +#define ENCRYPT_H + +typedef void (*encrypt_fn_t)(char *message); +void encrypt(char *message, encrypt_fn_t); + +#endif /* ENCRYPT_H */ diff --git a/C/HF/chap7/ls.txt b/C/HF/chap7/ls.txt new file mode 100644 index 0000000..928beb3 --- /dev/null +++ b/C/HF/chap7/ls.txt @@ -0,0 +1 @@ +J diff --git a/C/HF/chap7/message.c b/C/HF/chap7/message.c new file mode 100644 index 0000000..345774c --- /dev/null +++ b/C/HF/chap7/message.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include "encrypt.h" + +int main(void) +{ + char msg[80]; + while (fgets(msg, 80, stdin)) { + encrypt(msg); + printf("%s\n", msg); + } + + return 0; +} diff --git a/C/HF/chap7/text.txt b/C/HF/chap7/text.txt new file mode 100644 index 0000000..c87bea7 --- /dev/null +++ b/C/HF/chap7/text.txt @@ -0,0 +1 @@ +RONALDO diff --git a/C/HF/chap7/xor.c b/C/HF/chap7/xor.c new file mode 100644 index 0000000..0efa3a4 --- /dev/null +++ b/C/HF/chap7/xor.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include "xor.h" + +void xor42(char *message) +{ + printf("Orig: %s\n", message); + while (*message) { + *message = *message ^ 42; + message++; + } +} + +void xor64(char *message) +{ + printf("Orig: %s\n", message); + while (*message) { + *message = *message ^ 64; + message++; + } +} diff --git a/C/HF/chap7/xor.h b/C/HF/chap7/xor.h new file mode 100644 index 0000000..6f3de42 --- /dev/null +++ b/C/HF/chap7/xor.h @@ -0,0 +1,7 @@ +#ifndef XOR_H +#define XOR_H + +void xor42(char *m); +void xor64(char *m); + +#endif |
