<?php

$fx=(int)@$_REQUEST['FX'];

switch ($fx)
{
case 0:
	user_input();
	break;
case 1:
	make_lic();
	user_input();
	break;
}

function pre($s1)
{
	echo "<pre>";
	print_r($s1);
	echo "</pre>";
}

function make_lic()
{
	if (empty($_REQUEST['EXENO'])) {
		echo "<div style=\"color:red;\">Serial does not contain any licenses!</div>";
		return;
	}

	$s1="[".$_REQUEST['SERIAL']."]\n";
	foreach ($_REQUEST['EXENO'] as $ex1) {
		$s1 .= $_REQUEST['VERSION'].'.'.$ex1."=1\n";
	}

	$key40=sha1($s1);
	$ar20=array();
	for ($i=0;$i<40;$i+=2) {
		sscanf(substr($key40,$i,2),"%x",$x);
		$ar20[]=$x;
	}

   echo "<form><textarea rows=10 cols=50 style=\"border: 1px solid gray;\">\n";
	$l=strlen($s1);
	for ($i=0,$j=0; $i<$l; $i++) {
		$x = ord($s1{$i}) ^ $ar20[$j];
		if (++$j >= 20) $j=0;
		printf("%02x",$x);
	}
	echo "$key40</textarea></form>\n";
}

function user_input()
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method=GET>
<input type=HIDDEN name="FX" value="1">
<table>
<tr>
	<td>Serial</td>
	<td><input type=TEXT name="SERIAL" value="ÅÑÆ12345678"></td>
</tr>
<tr>
	<td>Version</td>
	<td><input type=TEXT name="VERSION" value="2.4.1.0"></td>
</tr>
<tr>
	<td>Program</td>
	<td><select name="EXENO[]" SIZE=5 MULTIPLE>
		<option value="250">Base
		<option value="260">Extended (TCP/IP)
		<option value="270">AS/400
		<option value="290">Add ons
		<option value="300">Fullgraphics Advanced
	</select></td>
</tr>
<tr>
	<td></td>
	<td><input type=SUBMIT value="Get License"></td>
</tr>
</table>
</form>
<?php
}
?>