-
Notifications
You must be signed in to change notification settings - Fork 2
/
specs.h
185 lines (159 loc) · 7.04 KB
/
specs.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef __SPECS_H
#define __SPECS_H
/*
* Specifications of inter-module dependencies.
*
* Robert W. Baldwin, December 1984.
*/
/* General Information. */
/* A pvec is an 'string' of integers that represent plaintext
* characters. The string is terminated by a -1.
* A pbuf is a fixed length array of integers that represent plaintext
* characters. A value of -1 means that the characters is unknown.
* A cbuf is a fixed length array of bytes that represent ciphertext chars.
* A perm is a mapping from shifted ciphertext characters to shifted
* plaintext characters. Each character is shifted (incremented) by
* its offset in the block of 256 characters that contain it.
* A gsi is a data structure about a guess that includes information
* on the characters that are assumed to be right.
* An eci is a data structure that descibes a block of cipher and
* plain text.
* A string is a null terminated vector of bytes.
*/
extern twindow banner;
extern twindow webster;
extern twindow dblabel;
extern gwindow dbstore;
extern twindow gblabel;
extern gwindow gbstore;
extern twindow user;
extern gwindow *ibanner();
extern gwindow *iwebster();
extern gwindow *idblabel();
extern gwindow *idbstore();
extern gwindow *igblabel();
extern gwindow *igbstore();
extern gwindow *iuser();
extern char *savestr();
extern int substrp(/* big, little */);
extern int read_slashed(/* *string */);
extern char *(quitcmd(/* arg-string */));
extern char *(lpbguess(/* arg-string */));
extern char *(atrguess(/* arg-string */));
extern char *(kntguess(/* arg-string */));
extern char *(ecbguess(/* arg-string */));
extern char *(pwdguess(/* arg-string */));
extern char *(permsave(/* arg-string */));
extern char *(permload(/* arg-string */));
extern char *(webmatch(/* arg-string */));
extern char *(clearzee(/* arg-string */));
extern char *(pgate(/* arg-string */));
extern char *(cmddo(/* cmdtab, string */));
extern char *(cmdcomplete(/* cmdtab, string */));
extern void gblset(/* w, string */);
extern void gbsswitch(/* w, private, keytable, firsttime, lasttime, draw */);
extern void gbsclear(/* w */);
extern int gbspos2row(/* pos */);
extern int gbspos2col(/* pos */);
/* extern hstadd(/\* w, string *\/); */
extern void usrstatus(/* w, string */);
extern int usrfirst(/* w, row, col */);
extern void usrhelp(/* w, string */);
extern void dblbnum(/* w, int */);
extern int dbsmerge(/* w, perm */);
extern void dbssetblk(/* w, int */);
extern int dbsgetblk(/* w */);
extern void dbstrypq(/* ecbi, pque_hdr, pos */);
extern float score(/* pbuf */);
extern void gsi_init(/* gsi, pbuf, gssbuf */);
extern void gsi_clear(/* gsi */);
extern int gsi_class_guess(/* gsi, eci, firstpos, c */);
extern float gsi_1score(/* gsi */); /* Uses 1st order stats. */
extern float gsi_2score(/* gsi */); /* Uses 2nd order stats. */
extern float var_1score(/* pvec */); /* Uses first order stats. */
extern float prob_1score(/* pvec */); /* Uses first order stats. */
extern float pvec_1score(/* pvec */); /* Uses first order stats. */
extern void load_1stats(); /* Loads first order stats. */
extern void print_1stats();
extern void load_1stats_from(/* statfname */);
extern void load_2stats_from(/* statfname */);
extern void load_tri_from(/* filename */);
extern void ec_init(/* char cipher[], int perm[], ecinfo *eci */);
extern int decode(/* cbuf, pbuf, perm */); /* FALSE if has bad chars. */
/* Return -1 if bad chars, otherwise # of chars added to pvec. */
extern int decode_wire(/* eci, x, y, pvec */);
/* Returns -1 if bad chars, otherwise # of chars added to pvec. */
extern int decode_class(/* eci, firstpos, firstplain, pvec */);
/* Returns number of wires added to permvec assuming that plaintext
* str occurs at pos. Fills in permvec. Returns -1 if conflict. */
extern int perm_from_string(/* eci, str, pos, permvec */);
/* Fills in pvec with the plaintext characters deduced
* from the wires in permvec that are not in the positions
* ranging from butfirst to butlast. Returns -1 if any
* non-ascii chars are deduced, else count of chars. */
extern int permvec2pvec(/* eci, permvec, pvec, butfirst, butlast */);
extern void permvec_copy(/* from, to, maxnum */);
extern void pvec_copy(/* from, to, maxnum */);
extern void print_pvec(/* stream, pvec */);
extern int accept_permvec(/* atri, permvec */);
extern void char2buf(/* cbuf, pbuf, length */); /* Fills in pbuf. */
extern void buf2char(/* cbuf, pbuf, length, nonechar */); /* Fill cbuf. */
extern void str2pvec(/* string, pvec */); /* Fills in pvec. */
extern void pvec2str(/* string, pvec */); /* Fills in string. */
extern int fillcbuf(/* blocknum, *cbuf */); /* Ret TRUE if sucessful. */
extern int *refperm(/* blocknum */); /* Ret NULL if fails. */
extern void copyperm(/* src, dst */);
extern void readperm(/* fd, permbuffer */); /* Gets chars from fd to fill perm. */
extern void writeperm(/* fd, permbuffer */); /* Writes perm to file. */
extern void multperm(/* left, right, result = (left)(right) */);
extern void expperm(/* src, dst, k */); /* dst = src ** k. */
extern int permcount(/* perm */); /* Return # values != -1. */
extern int permwcount(/* perm */); /* Return # of wires. */
extern void approx_init(); /* Call before fexp or isqrt. */
extern float fexp(/* float */); /* Fast exp func. */
extern float isqrt[]; /* Sqrts of integers < BLOCKSIZE */
/* Globals State */
extern char *cipherfile; /* Ciphertext file name. */
extern char *permfile; /* Permutation save file name. */
extern char *letterstats; /* Single letter stat file name. */
extern char *bigramstats; /* Letter pair statistics file name. */
extern char *trigramstats; /* Trigram statistics file name. */
extern int permchgflg; /* TRUE if perms chged since save. */
extern char statmsg[]; /* Buffer to build status messages. */
/* Extensions to C */
#ifndef reg
#define reg register
#endif
#define abs(x) (((x) > 0) ? x : (0 - x))
/* Macros */
#define graphic(c) (c & SYMBOL)
#define notascii(c) (c>127)
#define printable(c) ((32 <= c) && (c <= 126))
#define lletter(c) (('a'<= (c)) && ((c) <= 'z'))
#define uletter(c) (('A'<= (c)) && ((c) <= 'Z'))
#define isspace(c) ( ((c) == ' ') || ((c) == '\t') || ((c) == '\n') )
#define isletter(c) (lletter(c) || uletter(c))
#define tolower(c) ( uletter(c) ? ((c) - 'A' + 'a') : (c) )
/* Constants */
#define BLOCKSIZE 256 /* Number of chars in a cipher block. */
#define MODMASK 0377 /* Arithmetic mod 256. */
#define CHARMASK 0177 /* ASCII char mask. */
#define MAXCHAR 127 /* Highest ASCII value. */
#define MXBIINDEX 40 /* Num different chars in a bigram. */
#define LINELEN 64 /* Number of characters per line. */
#define NLINES 4 /* Number of line pairs. */
#define NONE (-1) /* No info on something. */
#define ERROR (-1) /* Procedure can't meet normal case specs. */
#define EOL (-37) /* A hack used by read_char() */
#define PI (3.1415926)
#define NPERMS 15 /* Max number of blocks in a file. */
#ifndef TRUE
#define TRUE 1 /* The whole truth. */
#endif
#ifndef FALSE
#define FALSE 0 /* Lies, falsehoods, etc. */
#endif
#ifndef NULL
#define NULL 0 /* A zero by any other name ... */
#endif
#endif /* __SPECS_H */