Algorithm to Generate License Key from User's Name

I'm looking for an algorithm to generate a license key from a person's name. I've been searching these forums and the web all day but haven't come up with much.Can you give me any ideas?Thanks,Philip
[231 byte] By [philmakera] at [2007-9-29 9:36:22]
# 1

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);

}

}

rkconnera at 2007-7-14 23:08:53 > top of Java-index,Other Topics,Algorithms...
# 2

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

matfuda at 2007-7-14 23:08:53 > top of Java-index,Other Topics,Algorithms...
# 3

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.

YATArchivista at 2007-7-14 23:08:53 > top of Java-index,Other Topics,Algorithms...