home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / cbw / part02 / cipher.h < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-16  |  3.4 KB  |  132 lines

  1.  
  2. /*
  3.  * Declarations for the information about a block.
  4.  */
  5.  
  6.  
  7. #define    SZMAX     100    /* Number of classes in ecinfo table. */
  8. #define    NCLASSES 256    /* Max number of classes of characters in a block. */
  9.  
  10.  
  11. /* Macros */
  12.  
  13. /* Iterate of the positions in a class.
  14.  * class is the index of one of the members of an equivalence class.
  15.  * pos is a loop variable assigned to the positions in a class
  16.  * starting with the value of class.
  17.  * Both eci->next and firstflag must be bound in the calling environment.
  18.  * firstflag is just an integer used as a flag, so it does not need to be
  19.  * initialized.  eci->next must be a table of next pointers for this block.
  20.  */
  21. #define    for_pos_in_class(pos, class)  \
  22.         for ((pos=class)&(firstflag=TRUE) ; \
  23.              firstflag || pos != class ; \
  24.              (firstflag=FALSE)&(pos = eci->next[pos]))
  25.  
  26.  
  27. /* Return TRUE if given wiring conflicts with the wiring
  28.  * in the given permutation.
  29.  */
  30. #define    perm_conflict(perm,x,y) \
  31.         ( ! perm_no_conflict(perm,x,y))
  32.  
  33. #define perm_no_conflict(perm,x,y) \
  34.         (   (x != y) \
  35.          && (   ((perm)[x] == NONE  &&  (perm)[y] == NONE) \
  36.              || ((perm)[x] == y     &&  (perm)[y] == x)  ))
  37.  
  38.  
  39. /* Structure Declarations */
  40.  
  41.  
  42. /* Used for tables of unique permutation wirings. */
  43. #define    perment    struct xperment
  44. perment {
  45.         int    x;        /* Sorted so x < y. */
  46.         int    y;        /* x can be NONE. */
  47.         };
  48.  
  49. #define    clinfo    struct    clinfox
  50. clinfo    {
  51.         short    nchars;        /* Number of chars in class. */
  52.         short    npairs;        /* Cur num of chars next to ones in this class. */
  53.         short    used;        /* True if class has an accepted value. */
  54.         short    changed;    /* True if best value might have changed. */
  55.         short    firstpos;    /* Position of first char of this class. */
  56.         };
  57.  
  58. #define    adjinfo    struct    adjinfox
  59. adjinfo    {
  60.         short    left;        /* Index of class to the left (or NONE). */
  61.         short    right;        /* Index of class to the right (or NONE). */
  62.         };
  63.  
  64.  
  65. #define    ecsize    struct ecsizex
  66. ecsize    {
  67.         int    size;        /* Size of class. */
  68.         int    firstpos;    /* Index of first member. */
  69.         };
  70.  
  71.  
  72. #define    ecinfo    struct    ecinfox
  73. ecinfo    {
  74.         /* Index of next free spot in sizelist. */
  75.         int    sizelast;
  76.         
  77.         /* Minimum size of class to put in sizelist. */
  78.         int    sizemin;
  79.         
  80.         /* Table of all the classes sorted largest first. */
  81.         ecsize    sizelist[SZMAX+1];
  82.         
  83.         /* Original ciphertext. */
  84.         char    ciphertext[BLOCKSIZE+1];
  85.         
  86.         /* Cipher chars shifted by  their index. */
  87.         int    scipher[BLOCKSIZE+1];
  88.         
  89.         /* Next[i] is a circular list of the positions of all the */
  90.         /* members of the class that contains ith cipher char. */
  91.         int    next[BLOCKSIZE+1];
  92.         
  93.         /* Position of first member of the class influenced by perm[i]. */
  94.         int    permmap[BLOCKSIZE+1];
  95.         /* Decipher permutation. A  -1 indicated unknown wiring. */
  96.         
  97.         /* This is cumulative. */
  98.         int    perm[BLOCKSIZE+1];
  99.         
  100.         /* Cumulative chars deciphered. */
  101.         int    plaintext[BLOCKSIZE+1];
  102.         
  103.         /* Index in classlist to put net class. */
  104.         int    nclasses;
  105.         
  106.         /* List of classes of characters. */
  107.         clinfo    classlist[NCLASSES];
  108.         
  109.         /* Table mapping positions into their class list index. */
  110.         short    posclass[BLOCKSIZE+1];
  111.         };
  112.  
  113.  
  114. /* The gsinfo structure is used to hold information about both
  115.  * guessed at characters and known characters.  Both are needed to
  116.  * compute scores based on letter pairs.
  117.  */
  118.  
  119. #define    gsinfo    struct    gsinfox
  120. gsinfo    {
  121.         /* Ptr to a plaintext block of accepted chars. */
  122.         int    *cknown;
  123.         
  124.         /* Ptr to a plaintext block of guessed at chars. */
  125.         int    *cguessed;
  126.         
  127.         /* Vector of positions within cguessed that have characters. */
  128.         /* The list is terminated by -1. */
  129.         int    cpos[SZMAX+1];
  130.         };
  131.  
  132.