Commits

Alexey Savanovich committed e582eda

static_archive

Comments (0)

Files changed (7)

 test.c
+*.o
+*.a
 test
 cards
-.idea
-tags
 core
 memory
 string_cant_be_updated

static_archive/README

+gcc -c encrypt.c -o encrypt.o
+gcc -c checksum.c -o checksum.o
+
+gcc test_code.c encrypt.o checksum.o -o test_code
+test_code.c:2:21: fatal error: encrypt.h: No such file or directory
+compilation terminated.
+
+ar -rcs libhfsecurity.a encrypt.o checksum.o
+nm libhfsecurity.a
+
+gcc test_code.c -I . -L . -lhfsecurity -o test_code
+

static_archive/checksum.c

+#include "checksum.h"
+
+
+int checksum(char *message)
+{
+    int c = 0;
+    while (*message) {
+        c += c ^ (int)(*message);
+        message++;
+    }
+    return c;
+}

static_archive/checksum.h

+int checksum(char *message);

static_archive/encrypt.c

+#include "encrypt.h"
+
+
+void encrypt(char *message)
+{
+    while (*message) {
+        *message = *message ^ 31;
+        message++;
+    }
+}
+

static_archive/encrypt.h

+void encrypt(char *message);

static_archive/test_code.c

+#include <stdio.h>
+#include <encrypt.h>
+#include <checksum.h>
+
+
+int main()
+{
+    char s[] = "Speak friend and enter";
+
+    encrypt(s);
+    printf("Encrypted to '%s'\n", s);
+    printf("Checksum is %i\n", checksum(s));
+
+    encrypt(s);
+    printf("Decrypted back to '%s'\n", s);
+    printf("Checksum is %i\n", checksum(s));
+
+    return 0;
+}
+