From: Jason S. Ninneman Date: Fri, 26 May 2017 17:21:19 +0000 (-0700) Subject: Just say no to encrypting internal state. X-Git-Tag: seed~40 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=refs%2Fmerge-requests%2F11%2Fhead;p=open-adventure.git Just say no to encrypting internal state. --- diff --git a/init.c b/init.c index a74dd86..ba49245 100644 --- a/init.c +++ b/init.c @@ -238,7 +238,7 @@ L1005: LINUSE=KK; if(LNLENG < LNPOSN)BUG(1); L1006: KK=KK+1; if(KK >= LINSIZ)BUG(2); - LINES[KK]=GETTXT(false,false,false,KK); + LINES[KK]=GETTXT(false,false,false); if(LINES[KK] != -1) goto L1006; LINES[LINUSE]=KK; 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 * 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 - * 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.) */ + * as an end-marker. */ L1040: J=10000; for (TABNDX=1; TABNDX<=TABSIZ; TABNDX++) { KTAB[TABNDX]=GETNUM(OPENED); if(KTAB[TABNDX] == -1) goto L1002; J=J+7; - ATAB[TABNDX]=GETTXT(true,true,true,0)+J*J; + ATAB[TABNDX]=GETTXT(true,true,true); } /* end loop */ BUG(4); diff --git a/misc.c b/misc.c index a656cbc..3fded19 100644 --- a/misc.c +++ b/misc.c @@ -30,7 +30,7 @@ L10: L=IABS(LINES[K])-1; LNPOSN=1; STATE=0; for (I=K; I<=L; I++) { - PUTTXT(LINES[I],STATE,2,I); + PUTTXT(LINES[I],STATE,2); } /* end loop */ LNPOSN=0; L30: LNPOSN=LNPOSN+1; @@ -79,7 +79,7 @@ L340: SHFTXT(LNPOSN+2,-2); CASE=2; L345: if(PARMS[NPARMS] < 0) goto L395; {long x = NPARMS+1; if(PARMS[x] < 0)CASE=0;} - PUTTXT(PARMS[NPARMS],STATE,CASE,0); + PUTTXT(PARMS[NPARMS],STATE,CASE); NPARMS=NPARMS+1; goto L345; @@ -98,8 +98,8 @@ L380: SHFTXT(LNPOSN+2,-2); if(PRMTYP == 31)CASE=1; if(PRMTYP == 33)CASE=0; I=LNPOSN; - PUTTXT(PARMS[NPARMS],STATE,CASE,0); - {long x = NPARMS+1; PUTTXT(PARMS[x],STATE,CASE,0);} + PUTTXT(PARMS[NPARMS],STATE,CASE); + {long x = NPARMS+1; PUTTXT(PARMS[x],STATE,CASE);} if(PRMTYP == 13 && INLINE[I] >= 37 && INLINE[I] <= 62)INLINE[I]=INLINE[I]-26; NPARMS=NPARMS+2; @@ -188,16 +188,16 @@ L10: if(BLKLIN)TYPE0(); MAPLIN(input); if (feof(input)) return false; - WORD1=GETTXT(true,true,true,0); + WORD1=GETTXT(true,true,true); if(BLKLIN && WORD1 < 0) goto L10; - WORD1X=GETTXT(false,true,true,0); -L12: JUNK=GETTXT(false,true,true,0); + WORD1X=GETTXT(false,true,true); +L12: JUNK=GETTXT(false,true,true); if(JUNK > 0) goto L12; - WORD2=GETTXT(true,true,true,0); - WORD2X=GETTXT(false,true,true,0); -L22: JUNK=GETTXT(false,true,true,0); + WORD2=GETTXT(true,true,true); + WORD2X=GETTXT(false,true,true); +L22: JUNK=GETTXT(false,true,true); if(JUNK > 0) goto L22; - if(GETTXT(true,true,true,0) <= 0)return true; + if(GETTXT(true,true,true) <= 0)return true; RSPEAK(53); goto L10; } @@ -283,14 +283,12 @@ L42: GETNUM=GETNUM*SIGN; #define GETNUM(K) fGETNUM(K) #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; /* 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 - * blank. UPPER says to map all letters to uppercase. HASH may be used - * 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 + * blank. UPPER says to map all letters to uppercase. If we reach the * 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. */ @@ -323,20 +321,19 @@ L14: LNPOSN=LNPOSN+1; L15: /*etc*/ ; } /* end loop */ - if(HASH)GETTXT=GETTXT+MOD(HASH*13579L+5432L,97531L)*12345L+HASH; return(GETTXT); } -#define GETTXT(SKIP,ONEWRD,UPPER,HASH) fGETTXT(SKIP,ONEWRD,UPPER,HASH) +#define GETTXT(SKIP,ONEWRD,UPPER) fGETTXT(SKIP,ONEWRD,UPPER) #undef MAKEWD long fMAKEWD(long LETTRS) { long I, L, MAKEWD; /* Combine five uppercase letters (represented by pairs of decimal digits * 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 * kludgey workaround, you can increment a letter by 5 by adding 50 to * the next pair of digits. */ @@ -360,13 +357,12 @@ L10: MAKEWD=MAKEWD+I*(MOD(L,50)+10); #define MAKEWD(LETTRS) fMAKEWD(LETTRS) #undef PUTTXT #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; /* 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 - * existing characters to the right to make room. HASH must be the same - * as it was when gettxt created the 30-bit word. STATE will be zero when + * existing characters to the right to make room. STATE will be zero when * 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 * 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. */ DIV=64L*64L*64L*64L; W=WORD; - if(HASH)W=W-MOD(HASH*13579L+5432L,97531L)*12345L-HASH; /* 18 */ for (I=1; I<=5; I++) { if(W <= 0 && STATE == 0 && IABS(CASE) <= 1)return; BYTE=W/DIV; @@ -403,7 +398,7 @@ L18: W=(W-BYTE*DIV)*64; #undef STATE -#define PUTTXT(WORD,STATE,CASE,HASH) fPUTTXT(WORD,&STATE,CASE,HASH) +#define PUTTXT(WORD,STATE,CASE) fPUTTXT(WORD,&STATE,CASE) #undef SHFTXT void fSHFTXT(long FROM, long DELTA) { long I, II, JJ; @@ -547,7 +542,7 @@ L32: N--; WORD=BUF[N]-CKSUM; N++; #define SAVWRD(OP,WORD) fSAVWRD(OP,&WORD) #undef VOCAB 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 * -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 * as an object.) And it also means the KTAB value is taken modulo 1000. */ - HASH=10000; /* 1 */ for (I=1; I<=TABSIZ; I++) { if(KTAB[I] == -1) goto L2; - HASH=HASH+7; 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*/ ; } /* end loop */ BUG(21); diff --git a/misc.h b/misc.h index f4567e3..a42a5a3 100644 --- a/misc.h +++ b/misc.h @@ -20,12 +20,12 @@ extern long fYES(FILE *,long,long,long); #define YES(input,X,Y,Z) fYES(input,X,Y,Z) extern long fGETNUM(FILE *); #define GETNUM(K) fGETNUM(K) -extern long fGETTXT(long,long,long,long); -#define GETTXT(SKIP,ONEWRD,UPPER,HASH) fGETTXT(SKIP,ONEWRD,UPPER,HASH) +extern long fGETTXT(long,long,long); +#define GETTXT(SKIP,ONEWRD,UPPER) fGETTXT(SKIP,ONEWRD,UPPER) extern long fMAKEWD(long); #define MAKEWD(LETTRS) fMAKEWD(LETTRS) -extern void fPUTTXT(long,long*,long,long); -#define PUTTXT(WORD,STATE,CASE,HASH) fPUTTXT(WORD,&STATE,CASE,HASH) +extern void fPUTTXT(long,long*,long); +#define PUTTXT(WORD,STATE,CASE) fPUTTXT(WORD,&STATE,CASE) extern void fSHFTXT(long,long); #define SHFTXT(FROM,DELTA) fSHFTXT(FROM,DELTA) extern void fTYPE0();