JSFiddle - React, Tailwind, and code Playground

by michapixel

HTML

<script src="https://raw.githubusercontent.com/ckknight/random-js/master/lib/random.js"></script>

JavaScript

/**
 * Generates a Key Byte
 * @param {32bit integer} seed e.g. 0xA2791717
 * @param {8bit integer} a    
 * @param {8bit integer} b    
 * @param {8bit integer} c    
 * @return {8bit hex string} 
 */
function PKV_GetKeyByte(seed, a, b, c) {
	var result;
	a = a%25;
	b = b%3;
	if (a%2 == 0) {
		result = ((seed >> a) & 0x000000FF) ^ ((seed >> b) | c);
	} else {
		result = ((seed >> a) & 0x000000FF) ^ ((seed >> b) & c);
	}
	result = result & 0xFF; /* mask 255 values! */
    return result.toString(16).toUpperCase();
} 
 
/**
 * Generates the checksum
 * @param {string} s Seed + Keys
 * @return {16bit hex string} 
 */
function PKV_GetChecksum(s) {
	var left,	/* unsigned 16bit integer */
		right,	/* unsigned 16bit integer */
		sum;	/* unsigned 16bit integer */
	left  = 0x0056; /* 101 */
	right = 0x00AF; /* 175 */
	if (s.length) {
		for (var i = 0; i < s.length; i++) {
			right += s.charCodeAt(i);
			if (right > 0x00FF) { 
				right -= 0x00FF;
			}
			left += right;
			if (left > 0x00FF) {
				left -= 0x00FF;
			}
		};
	}
	sum = (left << 8) + right;
	return sum.toString(16);
}
 
/**
 * Generates a serial number
 * @param {32bit integer} seed 
 * @return {20 chars String}
 */
function PKV_MakeKey(seed) {
	var keyBytes = [],
		result = "", 
		serial;
 
	/* Fill keyBytes with values derived from Seed.
	The parameters used here must be extactly the same
	as the ones used in the PKV_CheckKey function.
	A real key system should use more than four bytes. */
 
	keyBytes[0] = PKV_GetKeyByte(seed, 24, 3, 200);
	keyBytes[1] = PKV_GetKeyByte(seed, 10, 0, 56);
	keyBytes[2] = PKV_GetKeyByte(seed, 1, 2, 91);
	keyBytes[3] = PKV_GetKeyByte(seed, 7, 1, 100);
 
	/* the key string begins with a hexidecimal string of the seed */
	result += seed.toString(16).toUpperCase();
 
	/* then is followed by hexidecimal strings of each byte in the key */
	for (var i = 0; i < keyBytes.length; i++) {
		result += keyBytes[i].toUpperCase();
	};
 
	/* Add checksum to key string */
	result +=...