How's this idea...
import java.math.BigInteger;
public class mykey
{
// Strip spaces and non-alpha from sName before calling.
public static long convertToKey(String sName)
{
// Convert string into Base-26 number A-Z becomes 0-9A-P...
StringBuffer sbuff = new StringBuffer(sName.toUpperCase());
for (int i = 0; i < sbuff.length(); ++i)
{
char cVal = sbuff.charAt(i);
if (cVal > 'J')
cVal = (char) (cVal-'K'+'A');// K-Z becomes A-P
else
cVal = (char) (cVal-'A'+'0');// A-J becomes 0-9
sbuff.setCharAt(i, cVal);
}
// Convert base-26 string into BigInteger...
BigInteger bigInt = new BigInteger(sbuff.toString(), 26);
// Convert BigInteger into long license key...
long lKey = bigInt.longValue();
return(lKey);
}
public static void main(String args[])
{
System.out.println("Name: "+args[0]);
long lKey = convertToKey(args[0]);
System.out.println("lKey: "+lKey);
}
}
You could use the getBytes() method on the String name and
then run the resulting byte array though an MD5 (or SHA1) message digest function.
This produces a 20 byte value that is not guarenteed to be unique
but the probability of it matching another random string is
remarkably small.
matfud
Essentially the licence key problem is one of digital signatures. Depending on your infrastructure, you may wish to use a public/private key signature algorithm, whereby they submit their name with proof of payment and you return a signed version, which can be checked with the public key hard-coded into your software.