2e9447f499af28ef5d5dcde0a884cfba575039e8
[openafs.git] / src / des / make_odd.c
1 /*
2  * Copyright 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please see
5  * the file <mit-cpyright.h>.
6  *
7  * This routine generates an odd-parity table for use in key generation.
8  */
9
10 #include <afs/param.h>
11 #include <afsconfig.h>
12
13 RCSID("$Header$");
14
15 #include <mit-cpyright.h>
16 #include <stdio.h>
17
18 void gen(stream)
19     FILE *stream;
20 {
21     /*
22      * map a byte into its equivalent with odd parity, where odd
23      * parity is in the least significant bit
24      */
25     register int i, j, k, odd;
26
27     fprintf(stream,
28             "static unsigned char const odd_parity[256] = {\n");
29
30     for (i = 0; i < 256; i++) {
31         odd = 0;
32         /* shift out the lsb parity bit */
33         k = i >> 1;
34         /* then count the other bits */
35         for (j = 0; j < 7; j++) {
36             odd ^= (k&1);
37             k = k >> 1;
38         }
39         k = i&~1;
40         if (!odd)
41             k |= 1;
42         fprintf(stream, "%3d", k);
43         if (i < 255)
44             fprintf(stream, ", ");
45         if (i%8 == 0)
46             fprintf(stream, "\n");
47     }
48     fprintf(stream, "};\n");
49 }