diff options
| author | Carlos Maiolino <[email protected]> | 2025-09-06 11:12:35 +0200 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-09-06 11:12:35 +0200 |
| commit | 133a564a7ba1f57ff229e7c181227d43b4bae584 (patch) | |
| tree | 4377f34caf6abaa71621666aee3061e58c84f5d3 | |
| parent | 2c9056a23e1a55fd21a8e314c903d9325bffd62e (diff) | |
Create ecat based on a lib archive
Signed-off-by: Carlos Maiolino <[email protected]>
| -rw-r--r-- | C/HF/chap8/Makefile | 15 | ||||
| -rwxr-xr-x | C/HF/chap8/bin/ecat | bin | 0 -> 12944 bytes | |||
| -rw-r--r-- | C/HF/chap8/bin/libs/libencrypt.a | bin | 0 -> 3754 bytes | |||
| -rw-r--r-- | C/HF/chap8/include/libs/encrypt.h | 10 | ||||
| -rw-r--r-- | C/HF/chap8/include/libs/xor.h | 8 | ||||
| -rw-r--r-- | C/HF/chap8/ls.txt | 1 | ||||
| -rw-r--r-- | C/HF/chap8/res.txt | 1 | ||||
| -rw-r--r-- | C/HF/chap8/src/ecat.c | 29 | ||||
| -rw-r--r-- | C/HF/chap8/src/libs/encrypt.c | 13 | ||||
| -rw-r--r-- | C/HF/chap8/src/libs/xor.c | 30 | ||||
| -rw-r--r-- | C/HF/chap8/src/message.c | 13 | ||||
| -rw-r--r-- | C/HF/chap8/text.txt | 1 | ||||
| -rw-r--r-- | C/HF/chap8/v2.txt | 2 |
13 files changed, 123 insertions, 0 deletions
diff --git a/C/HF/chap8/Makefile b/C/HF/chap8/Makefile new file mode 100644 index 0000000..df3283e --- /dev/null +++ b/C/HF/chap8/Makefile @@ -0,0 +1,15 @@ +LIBS_DIR=./src/libs +INCLUDE_DIR=./include + +ecat: bin/libs/libencrypt.a + cc -I $(INCLUDE_DIR) -L bin/libs -o bin/ecat src/ecat.c -lencrypt + +# Create a lib archive +bin/libs/libencrypt.a: bin/libs/xor.o bin/libs/encrypt.o + ar -rcs bin/libs/libencrypt.a bin/libs/xor.o bin/libs/encrypt.o + +bin/libs/xor.o: $(INCLUDE_DIR)/libs/xor.h src/libs/xor.c + cc -I $(INCLUDE_DIR) -c src/libs/xor.c -o bin/libs/xor.o + +bin/libs/encrypt.o: $(INCLUDE_DIR)/libs/encrypt.h src/libs/encrypt.c + cc -I $(INCLUDE_DIR) -c src/libs/encrypt.c -o bin/libs/encrypt.o diff --git a/C/HF/chap8/bin/ecat b/C/HF/chap8/bin/ecat Binary files differnew file mode 100755 index 0000000..1167d31 --- /dev/null +++ b/C/HF/chap8/bin/ecat diff --git a/C/HF/chap8/bin/libs/libencrypt.a b/C/HF/chap8/bin/libs/libencrypt.a Binary files differnew file mode 100644 index 0000000..f609c17 --- /dev/null +++ b/C/HF/chap8/bin/libs/libencrypt.a diff --git a/C/HF/chap8/include/libs/encrypt.h b/C/HF/chap8/include/libs/encrypt.h new file mode 100644 index 0000000..e70d8f6 --- /dev/null +++ b/C/HF/chap8/include/libs/encrypt.h @@ -0,0 +1,10 @@ +#ifndef ENCRYPT_H +#define ENCRYPT_H + +typedef void (*encrypt_fn_t)(char *message); +typedef void (*encrypt_arr_t[])(char *message); + +void encrypt(char *message, encrypt_fn_t); +void encrypt_arr(char *message, encrypt_arr_t fn_arr, int size); + +#endif /* ENCRYPT_H */ diff --git a/C/HF/chap8/include/libs/xor.h b/C/HF/chap8/include/libs/xor.h new file mode 100644 index 0000000..8dd8e17 --- /dev/null +++ b/C/HF/chap8/include/libs/xor.h @@ -0,0 +1,8 @@ +#ifndef XOR_H +#define XOR_H + +void xor16(char *m); +void xor42(char *m); +void xor64(char *m); + +#endif diff --git a/C/HF/chap8/ls.txt b/C/HF/chap8/ls.txt new file mode 100644 index 0000000..928beb3 --- /dev/null +++ b/C/HF/chap8/ls.txt @@ -0,0 +1 @@ +J diff --git a/C/HF/chap8/res.txt b/C/HF/chap8/res.txt new file mode 100644 index 0000000..9d96016 --- /dev/null +++ b/C/HF/chap8/res.txt @@ -0,0 +1 @@ +"/6 diff --git a/C/HF/chap8/src/ecat.c b/C/HF/chap8/src/ecat.c new file mode 100644 index 0000000..9be8a47 --- /dev/null +++ b/C/HF/chap8/src/ecat.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <libs/xor.h> +#include <libs/encrypt.h> + +int main(int argc, char **argv) +{ + FILE *fd; + char buf[80]; + + char f = '\0'; + + encrypt_arr_t fn_arr = {xor16, xor42, xor64}; + if (argc != 2) + return 1; + + printf("Arr size: %ld\n", sizeof(fn_arr) / sizeof(*fn_arr)); + fd = fopen(argv[1], "r"); + + while (fgets(buf, 80, fd)) { + encrypt_arr(buf, fn_arr, 3); + printf("encrypted message: '%s'", buf); + } + + printf("\n"); + + printf("%c", (char)(f ^ 16 ^ 42 ^ 64)); + fclose(fd); + return 0; +} diff --git a/C/HF/chap8/src/libs/encrypt.c b/C/HF/chap8/src/libs/encrypt.c new file mode 100644 index 0000000..d894cfc --- /dev/null +++ b/C/HF/chap8/src/libs/encrypt.c @@ -0,0 +1,13 @@ +#include <libs/encrypt.h> + +void encrypt(char *message, encrypt_fn_t encrypt_fn) { + encrypt_fn(message); +} + +void encrypt_arr(char *message, encrypt_arr_t fn_arr, int size) +{ + int i; + + for (i = 0; i < size; i++) + encrypt(message, fn_arr[i]); +} diff --git a/C/HF/chap8/src/libs/xor.c b/C/HF/chap8/src/libs/xor.c new file mode 100644 index 0000000..30286e7 --- /dev/null +++ b/C/HF/chap8/src/libs/xor.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <libs/xor.h> + +void xor16(char *message) +{ + printf("Orig: %s\n", message); + while (*message) { + *message = *message ^ 16; + message++; + } +} + +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/chap8/src/message.c b/C/HF/chap8/src/message.c new file mode 100644 index 0000000..345774c --- /dev/null +++ b/C/HF/chap8/src/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/chap8/text.txt b/C/HF/chap8/text.txt new file mode 100644 index 0000000..935e3ea --- /dev/null +++ b/C/HF/chap8/text.txt @@ -0,0 +1 @@ +XULA diff --git a/C/HF/chap8/v2.txt b/C/HF/chap8/v2.txt new file mode 100644 index 0000000..7c3b204 --- /dev/null +++ b/C/HF/chap8/v2.txt @@ -0,0 +1,2 @@ +RONALDO +p |
