Check out the UuidCreate() and UuidToString() functions, this will generate a string guaranteed to be unique.
Main Topics
Browse All Topicsplz give best algo for Serial Number Generator in vc++
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Just a precision:
UuidToString doesn't generates unique numbers in all conditions, sometimes uniqueness is restricted to local machine. Read details at: http://msdn.microsoft.com/
Here ya go, full source, wrote it myself.
You will need to make a "LicenseKeys.h" and "LicenseKeys.cpp" from the below code.
I've included a sample function call at the end which will generate this in your output window:
Key 0 = D9DBC775045A42
Key 1 = B9D9CBB5054B34
Key 2 = 77B9C9B806597C
Key 3 = 7377A9B507581C
Key 4 = A773679C084A6E
Key 5 = 56A7635909443F
Key 6 = 685697530A5028
Key 7 = 2D6846860B51EB
Key 8 = 1A2D583D0C56B5
Key 9 = 511A1D4D0D4CF4
Key 10 = F9510A110E44FA
Key 11 = BCF940FD0F405E
Key 12 = A9BCE93B004B6A
Key 13 = 96A9ACE201421A
Key 14 = D79699A50246C2
Key 15 = DBD78691035793
Each key encodes from and decodes to a 16 bit value. The key string itself consist of the scrambled key+scrable offset+crc. The crc is needed as if there wasn't one, a hacker could make new keys just by counting up values.
//////////////////////////
//////////////////////////
// The following should be in a file like LicenseKeys.h
#pragma once
class CLicenseKeys
{
public:
CLicenseKeys(void){};
~CLicenseKeys(void){};
#define KEY_CHAR_LEN_S 10
// Keys
int CLicenseKeys::GenerateKey(
DWORD CLicenseKeys::DecodeKey( BYTE *szKey );
unsigned short CLicenseKeys::CRC16(BYTE* data, unsigned int len);
};
//////////////////////////
//////////////////////////
// The following should be in a file like LicenseKeys.cpp
BYTE bEncTable[16] = {
0x12, 0x53, 0x57, 0x55, 0x35, 0xf3, 0xee, 0x22,
0xd2, 0xe3, 0xa8, 0x95, 0xcc, 0x74, 0x38, 0x25
};
#pragma optimize("atp",on)
unsigned short CLicenseKeys::CRC16(BYTE* data, unsigned int len)
{
#define CRC32_GEN 0x4321 // A value to XOR with, change if you want to
register unsigned short crc=0;
while(len)
{
crc += *data++;
if( crc & 0x1 )
{
crc >>= 1;
crc |= 0x1000;
}
else
crc >>= 1;
len--;
}
return crc^=CRC32_GEN;
}
int CLicenseKeys::GenerateKey(
{
unsigned short sKeyNum = (unsigned short)dwKeyNum;
BYTE bKey[8];
ASSERT( sKeyNum!=-1 );
memset( bKey, 0, 8 );
DWORD dwKey= dwKeyNum;
// Encrypt the values --------------------------
// A simple XOR
dwKey ^= 0x84847463; // A value to XOR with, change if you want to (remember to change it to the same value in decode too!)
// An XOR roll using a table and offset
int iOffs = sKeyNum & 0xf;
DWORD dwVal;
for( int iPos = 0; iPos < 4; iPos++ )
{
dwVal = bEncTable[iOffs];
dwVal <<= (iPos*8);
dwKey += dwVal;
iOffs++;
if( iOffs > 15 )
iOffs = 0;
}
// --------------------------
sprintf( (char*)szKey, "%8.8X", dwKey );
BYTE szKeyEnd[3];
sprintf( (char*)szKeyEnd, "%2.2X", iOffs );
strcat( (char*)szKey, (char*)szKeyEnd ); // Add the table offset used to the end of the key, needed for decoding.
char szCRC[5];
unsigned short sCRC = CRC16(szKey,10);
_stprintf( szCRC, "%4.4X", sCRC ); // Add a CRC to the key (needed or the keys can be generated by the user by changing bytes)
strcat( (char*)szKey, (char*)szCRC );
return 0;
}
#endif
DWORD CLicenseKeys::DecodeKey( BYTE *szKey )
{
BYTE bKey[16];
char szCRC[5];
char *ptr = (char*)&szKey[10];
while( ptr[0] == '0' )
ptr++;
// Check the CRC --------------------------
DWORD crc;
strupr( (char*)szKey );
sscanf( ptr, "%x", &crc );
unsigned short calccrc = CRC16(szKey,10);
if( crc != calccrc )
return -1;
// --------------------------
BYTE szKeyDec[KEY_CHAR_LEN_S+1]
memcpy( szKeyDec, szKey, KEY_CHAR_LEN_S );
DWORD dwKey;
DWORD dwTemp;
int iOffs;
char szTemp[3];
szTemp[0] = szKey[8];
szTemp[1] = szKey[9];
szTemp[2] = '\0';
szKeyDec[8] = '\0';
sscanf( (TCHAR*)szKeyDec, "%X", &dwKey );
// Decode the values --------------------------
// Undo the XOR roll using the offsett
sscanf( (TCHAR*)szTemp, "%X", &iOffs);
DWORD dwVal;
for( int iPos = 3; iPos >= 0; iPos-- )
{
if( iOffs == 0 )
iOffs = 16;
iOffs--;
dwVal = bEncTable[iOffs];
dwVal <<= (iPos*8);
dwKey -= dwVal;
}
// Undo the XOR
dwKey ^= 0x84847463;
// --------------------------
dwTemp = dwKey;
dwTemp &= 0xffffffff00000000;
if( dwTemp!=0 )
return -1;
return (unsigned short)dwKey;
}
//////////////////////////
//////////////////////////
// The following is a sample routine to make 1000 keys
void MyDlg::OnBnClickedGenerate
{
CLicenseKeys LKeys;
unsigned short sDecoded, sKeyNum;
BYTE szKey[20];
for( sKeyNum = 0; sKeyNum<1000; sKeyNum++ )
{
LKeys.GenerateKey( sKeyNum, szKey );
sDecoded = m_LKeys.DecodeKey( szKey );
ASSERT( sDecoded!=-1 );
ASSERT( sKeyNum == sDecoded );
TRACE( "Key %i = %s\n", sKeyNum, szKey );
}
}
Business Accounts
Answer for Membership
by: AndyAinscowPosted on 2006-08-29 at 00:51:52ID: 17409854
1 + 1 = 2
1 + 2 = 3
... and so on to generate a series of numbers.