/* ThinkQuest International 2006
	The DReaMers - DRM: Two Sides of the Story
	definition.js
	--------------------------------------------
	Copyright: You may use this script for non-commercial purposes,
	but must acknowledge the team.
	--------------------------------------------
	Last Revised: 04/01/06
*/

function check(name,company,key)
{
//this is the function that check if the key is correct
//pre:a 12-digit pass and user name are given,
//post: return true or false for the key
var initial,temp,pass,expool,time,counter;
var cons=79;
expool=1;
initial=0;

initial=2+key.substring(0,1)+key.substring(1,2);

for(counter=1;counter<=1+key.substring(10,11)+key.substring(11,12);counter++)
{
initial=initial*79;
if(initial>99999999)
{
  expool=expool+(initial-initial%100000000)/100000000;
  initial=initial%99999999+1;
}

}
pass=(initial*expool)%99999999+1;
pass=key.substring(0,1)+key.substring(1,2)+pass+key.substring(10,11)+key.substring(11,12);
//calculate the pass

if(pass==key)
alert("Congratulations!" +name+", Thank you for buying our software!");
else
alert("Sorry your product key is not correct.");

//compare the result
}

function keygen()
{
//this function is to generate number that satisfy the first one;
var first,second,eleven,twelve;
var pass,initial,time,counter,expool=1;
first=Math.floor(Math.random()*1000)%10;
second=Math.floor(Math.random()*1000)%10;
eleven=Math.floor(Math.random()*1000)%10;
twelve=Math.floor(Math.random()*1000)%10;
//randomly generate numbers;


initial="2"+first+second;
time="1"+eleven+twelve;

for(counter=1;counter<=time;counter++)
{
initial=initial*79;
if(initial>99999999)
{
  expool=expool+(initial-initial%100000000)/100000000;
  initial=initial%99999999+1;
}

}
pass=(initial*expool)%99999999+1;

pass=""+first+second+pass+eleven+twelve;
//generate pass!
return pass;
}



