home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / kerberosIV / make_odd / make_odd.c next >
Encoding:
C/C++ Source or Header  |  1991-02-14  |  1.2 KB  |  50 lines

  1. /*
  2.  * $Source: /usr/src/kerberosIV/make_odd/RCS/make_odd.c,v $
  3.  * $Author: bostic $
  4.  *
  5.  * Copyright 1988 by the Massachusetts Institute of Technology.
  6.  *
  7.  * For copying and distribution information, please see
  8.  * the file <mit-copyright.h>.
  9.  *
  10.  * This routine generates an odd-parity table for use in key generation.
  11.  */
  12.  
  13. #include <mit-copyright.h>
  14. #include <stdio.h>
  15.  
  16. void gen(stream)
  17.     FILE *stream;
  18. {
  19.     /*
  20.      * map a byte into its equivalent with odd parity, where odd
  21.      * parity is in the least significant bit
  22.      */
  23.     register i, j, k, odd;
  24.  
  25.     fprintf(stream,
  26.             "#include <sys/cdefs.h>\n");
  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. }
  50.