Skip to content

Build Lookup Table

A function that fills a 65 by 256 byte substitution table from a single build value using XOR mixing.

Published Aug 31, 1998

A small key-schedule style routine: give it one integer seed and it walks a 65-by-256 grid of unsigned bytes, mixing the loop counters, a running total, and the seed with XOR (with collision and zero-value fallbacks) to produce a deterministic lookup box. It is the kind of precomputed table you feed to a stream cipher or obfuscation layer so per-byte work becomes a single array read. Use it when you want a cheap, reproducible substitution table generated at startup instead of shipped as data.

//////////////////////////////////////////////////////////////////////////////////////////

#include <Windows.H>
#include <StdIO.H>

//////////////////////////////////////////////////////////////////////////////////////////

unsigned char sDataBox[65][256];

int BuildLookupTable(int BuildValue, unsigned char LookupTable[65][256])
{
	int Loop1 = 0;
	int Loop2 = 0;
	int TotalValue = 0;

	unsigned char Value 	= 0;
	unsigned char LastValue = 0;

	while(Loop1 < 65)
	{
		Loop2 = 0;
		while(Loop2 < 256)
		{
			Value = ( (Loop1 * BuildValue) ^ (Loop2 * BuildValue) ^ TotalValue);

			if(Value == LastValue) Value += (BuildValue | Loop1) ^ (BuildValue | Loop2);
			LastValue = Value;

			if(Value == 0)	Value = ((Loop1 * Loop2) ^ TotalValue) + BuildValue;

			sDataBox[Loop1][Loop2] = (unsigned char) Value;

			TotalValue++;
			Loop2++;
		}

		Loop1++;
	}

	return TotalValue;
}

//////////////////////////////////////////////////////////////////////////////////////////

int main()
{

	BuildLookupTable(8408,sDataBox);

	return 0;
}

//////////////////////////////////////////////////////////////////////////////////////////
An unhandled error has occurred. Reload 🗙