Just say no to encrypting internal state.

This commit is contained in:
Jason S. Ninneman 2017-05-26 10:21:19 -07:00
parent 5c4fdc35eb
commit 2270c6ad12
3 changed files with 27 additions and 37 deletions

9
init.c
View file

@ -238,7 +238,7 @@ L1005: LINUSE=KK;
if(LNLENG < LNPOSN)BUG(1); if(LNLENG < LNPOSN)BUG(1);
L1006: KK=KK+1; L1006: KK=KK+1;
if(KK >= LINSIZ)BUG(2); if(KK >= LINSIZ)BUG(2);
LINES[KK]=GETTXT(false,false,false,KK); LINES[KK]=GETTXT(false,false,false);
if(LINES[KK] != -1) goto L1006; if(LINES[KK] != -1) goto L1006;
LINES[LINUSE]=KK; LINES[LINUSE]=KK;
if(LOC == OLDLOC) goto L1005; if(LOC == OLDLOC) goto L1005;
@ -300,17 +300,14 @@ L1039: TRVS--; TRAVEL[TRVS]= -TRAVEL[TRVS]; TRVS++;
/* Here we read in the vocabulary. KTAB(N) is the word number, ATAB(N) is /* Here we read in the vocabulary. KTAB(N) is the word number, ATAB(N) is
* the corresponding word. The -1 at the end of section 4 is left in KTAB * the corresponding word. The -1 at the end of section 4 is left in KTAB
* as an end-marker. The words are given a minimal hash to make deciphering * as an end-marker. */
* the core-image harder. (We don't use gettxt's hash since that would force
* us to hash each input line to make comparisons work, and that in turn
* would make it harder to detect particular input words.) */
L1040: J=10000; L1040: J=10000;
for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) { for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) {
KTAB[TABNDX]=GETNUM(OPENED); KTAB[TABNDX]=GETNUM(OPENED);
if(KTAB[TABNDX] == -1) goto L1002; if(KTAB[TABNDX] == -1) goto L1002;
J=J+7; J=J+7;
ATAB[TABNDX]=GETTXT(true,true,true,0)+J*J; ATAB[TABNDX]=GETTXT(true,true,true);
} /* end loop */ } /* end loop */
BUG(4); BUG(4);

47
misc.c
View file

@ -30,7 +30,7 @@ L10: L=IABS(LINES[K])-1;
LNPOSN=1; LNPOSN=1;
STATE=0; STATE=0;
for (I=K; I<=L; I++) { for (I=K; I<=L; I++) {
PUTTXT(LINES[I],STATE,2,I); PUTTXT(LINES[I],STATE,2);
} /* end loop */ } /* end loop */
LNPOSN=0; LNPOSN=0;
L30: LNPOSN=LNPOSN+1; L30: LNPOSN=LNPOSN+1;
@ -79,7 +79,7 @@ L340: SHFTXT(LNPOSN+2,-2);
CASE=2; CASE=2;
L345: if(PARMS[NPARMS] < 0) goto L395; L345: if(PARMS[NPARMS] < 0) goto L395;
{long x = NPARMS+1; if(PARMS[x] < 0)CASE=0;} {long x = NPARMS+1; if(PARMS[x] < 0)CASE=0;}
PUTTXT(PARMS[NPARMS],STATE,CASE,0); PUTTXT(PARMS[NPARMS],STATE,CASE);
NPARMS=NPARMS+1; NPARMS=NPARMS+1;
goto L345; goto L345;
@ -98,8 +98,8 @@ L380: SHFTXT(LNPOSN+2,-2);
if(PRMTYP == 31)CASE=1; if(PRMTYP == 31)CASE=1;
if(PRMTYP == 33)CASE=0; if(PRMTYP == 33)CASE=0;
I=LNPOSN; I=LNPOSN;
PUTTXT(PARMS[NPARMS],STATE,CASE,0); PUTTXT(PARMS[NPARMS],STATE,CASE);
{long x = NPARMS+1; PUTTXT(PARMS[x],STATE,CASE,0);} {long x = NPARMS+1; PUTTXT(PARMS[x],STATE,CASE);}
if(PRMTYP == 13 && INLINE[I] >= 37 && INLINE[I] <= if(PRMTYP == 13 && INLINE[I] >= 37 && INLINE[I] <=
62)INLINE[I]=INLINE[I]-26; 62)INLINE[I]=INLINE[I]-26;
NPARMS=NPARMS+2; NPARMS=NPARMS+2;
@ -188,16 +188,16 @@ L10: if(BLKLIN)TYPE0();
MAPLIN(input); MAPLIN(input);
if (feof(input)) if (feof(input))
return false; return false;
WORD1=GETTXT(true,true,true,0); WORD1=GETTXT(true,true,true);
if(BLKLIN && WORD1 < 0) goto L10; if(BLKLIN && WORD1 < 0) goto L10;
WORD1X=GETTXT(false,true,true,0); WORD1X=GETTXT(false,true,true);
L12: JUNK=GETTXT(false,true,true,0); L12: JUNK=GETTXT(false,true,true);
if(JUNK > 0) goto L12; if(JUNK > 0) goto L12;
WORD2=GETTXT(true,true,true,0); WORD2=GETTXT(true,true,true);
WORD2X=GETTXT(false,true,true,0); WORD2X=GETTXT(false,true,true);
L22: JUNK=GETTXT(false,true,true,0); L22: JUNK=GETTXT(false,true,true);
if(JUNK > 0) goto L22; if(JUNK > 0) goto L22;
if(GETTXT(true,true,true,0) <= 0)return true; if(GETTXT(true,true,true) <= 0)return true;
RSPEAK(53); RSPEAK(53);
goto L10; goto L10;
} }
@ -283,14 +283,12 @@ L42: GETNUM=GETNUM*SIGN;
#define GETNUM(K) fGETNUM(K) #define GETNUM(K) fGETNUM(K)
#undef GETTXT #undef GETTXT
long fGETTXT(long SKIP,long ONEWRD, long UPPER, long HASH) { long fGETTXT(long SKIP,long ONEWRD, long UPPER) {
long CHAR, GETTXT, I; static long SPLITTING = -1; long CHAR, GETTXT, I; static long SPLITTING = -1;
/* Take characters from an input line and pack them into 30-bit words. /* Take characters from an input line and pack them into 30-bit words.
* Skip says to skip leading blanks. ONEWRD says stop if we come to a * Skip says to skip leading blanks. ONEWRD says stop if we come to a
* blank. UPPER says to map all letters to uppercase. HASH may be used * blank. UPPER says to map all letters to uppercase. If we reach the
* as a parameter for encrypting the text if desired; however, a hash of 0
* should result in unmodified bytes being packed. If we reach the
* end of the line, the word is filled up with blanks (which encode as 0's). * end of the line, the word is filled up with blanks (which encode as 0's).
* If we're already at end of line when GETTXT is called, we return -1. */ * If we're already at end of line when GETTXT is called, we return -1. */
@ -323,20 +321,19 @@ L14: LNPOSN=LNPOSN+1;
L15: /*etc*/ ; L15: /*etc*/ ;
} /* end loop */ } /* end loop */
if(HASH)GETTXT=GETTXT+MOD(HASH*13579L+5432L,97531L)*12345L+HASH;
return(GETTXT); return(GETTXT);
} }
#define GETTXT(SKIP,ONEWRD,UPPER,HASH) fGETTXT(SKIP,ONEWRD,UPPER,HASH) #define GETTXT(SKIP,ONEWRD,UPPER) fGETTXT(SKIP,ONEWRD,UPPER)
#undef MAKEWD #undef MAKEWD
long fMAKEWD(long LETTRS) { long fMAKEWD(long LETTRS) {
long I, L, MAKEWD; long I, L, MAKEWD;
/* Combine five uppercase letters (represented by pairs of decimal digits /* Combine five uppercase letters (represented by pairs of decimal digits
* in lettrs) to form a 30-bit value matching the one that GETTXT would * in lettrs) to form a 30-bit value matching the one that GETTXT would
* return given those characters plus trailing blanks and HASH=0. Caution: * return given those characters plus trailing blanks. Caution:
* lettrs will overflow 31 bits if 5-letter word starts with V-Z. As a * lettrs will overflow 31 bits if 5-letter word starts with V-Z. As a
* kludgey workaround, you can increment a letter by 5 by adding 50 to * kludgey workaround, you can increment a letter by 5 by adding 50 to
* the next pair of digits. */ * the next pair of digits. */
@ -360,13 +357,12 @@ L10: MAKEWD=MAKEWD+I*(MOD(L,50)+10);
#define MAKEWD(LETTRS) fMAKEWD(LETTRS) #define MAKEWD(LETTRS) fMAKEWD(LETTRS)
#undef PUTTXT #undef PUTTXT
#define STATE (*sTATE) #define STATE (*sTATE)
void fPUTTXT(long WORD, long *sTATE, long CASE, long HASH) { void fPUTTXT(long WORD, long *sTATE, long CASE) {
long ALPH1, ALPH2, BYTE, DIV, I, W; long ALPH1, ALPH2, BYTE, DIV, I, W;
/* Unpack the 30-bit value in word to obtain up to 5 integer-encoded chars, /* Unpack the 30-bit value in word to obtain up to 5 integer-encoded chars,
* and store them in inline starting at LNPOSN. If LNLENG>=LNPOSN, shift * and store them in inline starting at LNPOSN. If LNLENG>=LNPOSN, shift
* existing characters to the right to make room. HASH must be the same * existing characters to the right to make room. STATE will be zero when
* as it was when gettxt created the 30-bit word. STATE will be zero when
* puttxt is called with the first of a sequence of words, but is thereafter * puttxt is called with the first of a sequence of words, but is thereafter
* unchanged by the caller, so PUTTXT can use it to maintain state across * unchanged by the caller, so PUTTXT can use it to maintain state across
* calls. LNPOSN and LNLENG are incremented by the number of chars stored. * calls. LNPOSN and LNLENG are incremented by the number of chars stored.
@ -381,7 +377,6 @@ long ALPH1, ALPH2, BYTE, DIV, I, W;
/* ALPH1&2 DEFINE RANGE OF WRONG-CASE CHARS, 11-36 OR 37-62 OR EMPTY. */ /* ALPH1&2 DEFINE RANGE OF WRONG-CASE CHARS, 11-36 OR 37-62 OR EMPTY. */
DIV=64L*64L*64L*64L; DIV=64L*64L*64L*64L;
W=WORD; W=WORD;
if(HASH)W=W-MOD(HASH*13579L+5432L,97531L)*12345L-HASH;
/* 18 */ for (I=1; I<=5; I++) { /* 18 */ for (I=1; I<=5; I++) {
if(W <= 0 && STATE == 0 && IABS(CASE) <= 1)return; if(W <= 0 && STATE == 0 && IABS(CASE) <= 1)return;
BYTE=W/DIV; BYTE=W/DIV;
@ -403,7 +398,7 @@ L18: W=(W-BYTE*DIV)*64;
#undef STATE #undef STATE
#define PUTTXT(WORD,STATE,CASE,HASH) fPUTTXT(WORD,&STATE,CASE,HASH) #define PUTTXT(WORD,STATE,CASE) fPUTTXT(WORD,&STATE,CASE)
#undef SHFTXT #undef SHFTXT
void fSHFTXT(long FROM, long DELTA) { void fSHFTXT(long FROM, long DELTA) {
long I, II, JJ; long I, II, JJ;
@ -547,7 +542,7 @@ L32: N--; WORD=BUF[N]-CKSUM; N++;
#define SAVWRD(OP,WORD) fSAVWRD(OP,&WORD) #define SAVWRD(OP,WORD) fSAVWRD(OP,&WORD)
#undef VOCAB #undef VOCAB
long fVOCAB(long ID, long INIT) { long fVOCAB(long ID, long INIT) {
long HASH, I, VOCAB; long I, VOCAB;
/* Look up ID in the vocabulary (ATAB) and return its "definition" (KTAB), or /* Look up ID in the vocabulary (ATAB) and return its "definition" (KTAB), or
* -1 if not found. If INIT is positive, this is an initialisation call setting * -1 if not found. If INIT is positive, this is an initialisation call setting
@ -556,12 +551,10 @@ long HASH, I, VOCAB;
* (Thus "STEPS", which is a motion verb as well as an object, may be located * (Thus "STEPS", which is a motion verb as well as an object, may be located
* as an object.) And it also means the KTAB value is taken modulo 1000. */ * as an object.) And it also means the KTAB value is taken modulo 1000. */
HASH=10000;
/* 1 */ for (I=1; I<=TABSIZ; I++) { /* 1 */ for (I=1; I<=TABSIZ; I++) {
if(KTAB[I] == -1) goto L2; if(KTAB[I] == -1) goto L2;
HASH=HASH+7;
if(INIT >= 0 && KTAB[I]/1000 != INIT) goto L1; if(INIT >= 0 && KTAB[I]/1000 != INIT) goto L1;
if(ATAB[I] == ID+HASH*HASH) goto L3; if(ATAB[I] == ID) goto L3;
L1: /*etc*/ ; L1: /*etc*/ ;
} /* end loop */ } /* end loop */
BUG(21); BUG(21);

8
misc.h
View file

@ -20,12 +20,12 @@ extern long fYES(FILE *,long,long,long);
#define YES(input,X,Y,Z) fYES(input,X,Y,Z) #define YES(input,X,Y,Z) fYES(input,X,Y,Z)
extern long fGETNUM(FILE *); extern long fGETNUM(FILE *);
#define GETNUM(K) fGETNUM(K) #define GETNUM(K) fGETNUM(K)
extern long fGETTXT(long,long,long,long); extern long fGETTXT(long,long,long);
#define GETTXT(SKIP,ONEWRD,UPPER,HASH) fGETTXT(SKIP,ONEWRD,UPPER,HASH) #define GETTXT(SKIP,ONEWRD,UPPER) fGETTXT(SKIP,ONEWRD,UPPER)
extern long fMAKEWD(long); extern long fMAKEWD(long);
#define MAKEWD(LETTRS) fMAKEWD(LETTRS) #define MAKEWD(LETTRS) fMAKEWD(LETTRS)
extern void fPUTTXT(long,long*,long,long); extern void fPUTTXT(long,long*,long);
#define PUTTXT(WORD,STATE,CASE,HASH) fPUTTXT(WORD,&STATE,CASE,HASH) #define PUTTXT(WORD,STATE,CASE) fPUTTXT(WORD,&STATE,CASE)
extern void fSHFTXT(long,long); extern void fSHFTXT(long,long);
#define SHFTXT(FROM,DELTA) fSHFTXT(FROM,DELTA) #define SHFTXT(FROM,DELTA) fSHFTXT(FROM,DELTA)
extern void fTYPE0(); extern void fTYPE0();