summaryrefslogtreecommitdiff
path: root/crypt.c
diff options
context:
space:
mode:
authordaniel <daniel@planethacker.net>2025-05-07 09:45:50 -0700
committerdaniel <daniel@planethacker.net>2025-05-07 09:45:50 -0700
commiteeac69b2168c5a65f9608771006ccc43033cbd23 (patch)
tree1dc44a6016b607085a691768810d551045df9901 /crypt.c
initial commitHEADmain
Diffstat (limited to 'crypt.c')
-rw-r--r--crypt.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/crypt.c b/crypt.c
new file mode 100644
index 0000000..b39ab61
--- /dev/null
+++ b/crypt.c
@@ -0,0 +1,50 @@
+/*
+ * LOKI3
+ *
+ * [ crypt.c ]
+ *
+ * 1996/7 Guild Corporation Worldwide [daemon9]
+ */
+
+#include "loki.h"
+#include "crypt.h"
+
+#ifdef WEAK_CRYPTO
+/*
+ * Simple XOR obfuscation.
+ *
+ * ( Syko was right -- the following didn't work under certain compilation
+ * environments... Never write code in which the order of evaluation defines
+ * the result. See K&R page 53, at the bottom... )
+ *
+ * if (!m) while (i < bs) t[i] ^= t[i++ +1];
+ * else
+ * {
+ * i = bs;
+ * while (i) t[i - 1] ^= t[i--];
+ * }
+ *
+ */
+void blur(int m, int bs, uint8_t *t) {
+ int i = 0;
+
+ if (!m) { /* Encrypt */
+ while (i < bs) {
+ t[i] ^= t[i + 1];
+ i++;
+ }
+ } else { /* Decrypt */
+ i = bs;
+ while (i) {
+ t[i - 1] ^= t[i];
+ i--;
+ }
+ }
+}
+#endif /* WEAK_CRYPTO */
+
+#ifdef NO_CRYPTO
+void blur(int m, int bs, uint8_t *t){}
+#endif /* NO_CRYPTO */
+
+/* EOF */