// ${name: libxlKey}
// ${title: Keygen for LibXL}

import crypt
import console;

getKey = function(name){
    
    var three = function(){
    	A37 = lambda() string.unpack(string.random(1,"cdfghijklmnopqrstuvwxyz"))
		A39 = function(n){
			var v = math.floor( math.random(0,26) + (202 - n) )
			return (v!=102) ? ((v>=97 && v<123) ? v : A39(n)) : ((v>=108 && v<123) ? v : A39(n))
		}
		
		var k37 = A37();
		var k39 = A39( k37 )
		var k35 = k37 + k39 - 105
		return k35, k37, k39; 
	}
	
	var key = raw.buffer("windows-2020200000c0e00060b06060a0000000")
	var md5 = string.left( crypt.md5( string.reverse(name), false), 16)
	for(i=1;#md5) key[8+2*i] = md5[i]
	key[35], key[37], key[39] = three()
	
	return key; 
}

var name = "aardio"
console.printf( 'name : %s\nkey  : %s', name, getKey(name) )
console.pause(true);

// https://suiang.cn/aardio/code/libxlKey