summaryrefslogtreecommitdiff
path: root/C/HF/chap7
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-09-06 09:26:21 +0200
committerCarlos Maiolino <[email protected]>2025-09-06 09:26:21 +0200
commit973e27b243ea7f12b6743894465c67a4a6a87eb2 (patch)
tree006a2d9fc8f86b4914499302325fbcaa3941e17c /C/HF/chap7
parent736967952470e740781c95cf5afb7e705ec59030 (diff)
Move some other code here
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'C/HF/chap7')
-rw-r--r--C/HF/chap7/Makefile14
-rw-r--r--C/HF/chap7/ecat.c23
-rw-r--r--C/HF/chap7/ecat.corebin0 -> 12046336 bytes
-rw-r--r--C/HF/chap7/encrypt.c6
-rw-r--r--C/HF/chap7/encrypt.h7
-rw-r--r--C/HF/chap7/ls.txt1
-rw-r--r--C/HF/chap7/message.c13
-rw-r--r--C/HF/chap7/text.txt1
-rw-r--r--C/HF/chap7/xor.c20
-rw-r--r--C/HF/chap7/xor.h7
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
new file mode 100644
index 0000000..2b80a6f
--- /dev/null
+++ b/C/HF/chap7/ecat.core
Binary files differ
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