summaryrefslogtreecommitdiff
path: root/crypt.c
blob: b39ab61cb1badb4ee16327949fd6ed787774647d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 */