From 973e27b243ea7f12b6743894465c67a4a6a87eb2 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Sat, 6 Sep 2025 09:26:21 +0200 Subject: Move some other code here Signed-off-by: Carlos Maiolino --- C/HF/chap4/cryptic/Makefile | 14 ++++++++++++++ C/HF/chap4/cryptic/ecat.c | 23 +++++++++++++++++++++++ C/HF/chap4/cryptic/encrypt.c | 9 +++++++++ C/HF/chap4/cryptic/encrypt.h | 6 ++++++ C/HF/chap4/cryptic/message.c | 13 +++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 C/HF/chap4/cryptic/Makefile create mode 100644 C/HF/chap4/cryptic/ecat.c create mode 100644 C/HF/chap4/cryptic/encrypt.c create mode 100644 C/HF/chap4/cryptic/encrypt.h create mode 100644 C/HF/chap4/cryptic/message.c (limited to 'C/HF/chap4/cryptic') diff --git a/C/HF/chap4/cryptic/Makefile b/C/HF/chap4/cryptic/Makefile new file mode 100644 index 0000000..64312d5 --- /dev/null +++ b/C/HF/chap4/cryptic/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/chap4/cryptic/ecat.c b/C/HF/chap4/cryptic/ecat.c new file mode 100644 index 0000000..5266116 --- /dev/null +++ b/C/HF/chap4/cryptic/ecat.c @@ -0,0 +1,23 @@ +#include +#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); + printf("%s", buf); + } + + printf("\n"); + fclose(fd); + + return 0; +} diff --git a/C/HF/chap4/cryptic/encrypt.c b/C/HF/chap4/cryptic/encrypt.c new file mode 100644 index 0000000..128b1a4 --- /dev/null +++ b/C/HF/chap4/cryptic/encrypt.c @@ -0,0 +1,9 @@ +#include "encrypt.h" + +void encrypt(char *message) +{ + while (*message) { + *message = *message ^ 42; + message++; + } +} diff --git a/C/HF/chap4/cryptic/encrypt.h b/C/HF/chap4/cryptic/encrypt.h new file mode 100644 index 0000000..7d5cf9d --- /dev/null +++ b/C/HF/chap4/cryptic/encrypt.h @@ -0,0 +1,6 @@ +#ifndef ENCRYPT_H +#define ENCRYPT_H + +void encrypt(char *m); + +#endif diff --git a/C/HF/chap4/cryptic/message.c b/C/HF/chap4/cryptic/message.c new file mode 100644 index 0000000..345774c --- /dev/null +++ b/C/HF/chap4/cryptic/message.c @@ -0,0 +1,13 @@ +#include +#include "encrypt.h" + +int main(void) +{ + char msg[80]; + while (fgets(msg, 80, stdin)) { + encrypt(msg); + printf("%s\n", msg); + } + + return 0; +} -- cgit v1.2.3