Fix a bug in RNDVOC() that prevented the reservoir magic word for working.

To do this, I first had to refactor the code into proper C, just so I could understand it. Then I found another layer of encryption around the value itself. Finally, I discovered that the line to actually set the new magic word was placed such that it was using a global index instead of the local one.
This commit is contained in:
Jason S. Ninneman 2017-05-29 14:22:52 -07:00
parent 18eac9f55d
commit 650575394f

16
misc.c
View file

@ -778,35 +778,33 @@ long randrange(long range)
#undef RNDVOC #undef RNDVOC
long fRNDVOC(long CHAR, long FORCE) { long fRNDVOC(long CHAR, long FORCE) {
long DIV, J, RNDVOC;
/* Searches the vocabulary for a word whose second character is char, and /* Searches the vocabulary for a word whose second character is char, and
* changes that word such that each of the other four characters is a * changes that word such that each of the other four characters is a
* random letter. If force is non-zero, it is used as the new word. * random letter. If force is non-zero, it is used as the new word.
* Returns the new word. */ * Returns the new word. */
long RNDVOC;
RNDVOC=FORCE; RNDVOC=FORCE;
if (RNDVOC == 0) { if (RNDVOC == 0) {
for (int I = 1; I <= 5; I++) { for (int I = 1; I <= 5; I++) {
J = 11 + randrange(26); long J = 11 + randrange(26);
if (I == 2) if (I == 2)
J = CHAR; J = CHAR;
RNDVOC = RNDVOC * 64 + J; RNDVOC = RNDVOC * 64 + J;
} }
} }
J = 10000; long DIV = 64L * 64L * 64L;
DIV = 64L * 64L * 64L;
for (int I = 1; I <= TABSIZ; I++) { for (int I = 1; I <= TABSIZ; I++) {
J = J + 7; if (MOD(ATAB[I]/DIV, 64L) == CHAR)
if (MOD((ATAB[I]-J*J)/DIV, 64L) == CHAR) {
ATAB[I] = RNDVOC;
break; break;
} }
}
ATAB[I] = RNDVOC + J * J;
return(RNDVOC); return(RNDVOC);
} }