TweetFollow Us on Twitter

Serial Number Generator

Volume Number: 13 (1997)
Issue Number: 2
Column Tag: Programming Techniques

Serial Killer

By Jamie McCornack

Easy and effective serial number management for electronic game distributors

This material isn't rocket science - it is just an easy way to do something that you need to do. The computer game business is a dog and pony show, and this is about how to deal with pony poop. I am offering no glamour here, but I might save you a couple of day's work.

An Important Part of Every Breakfast

Games need serial numbers more than any other software. They also need individual serial numbers for individual customers because

• People play games for fun, and paying for things isn't much fun. Given a choice, the average game player will say, "It's only a game," and never think twice about ethics. These people would never go to their Porsche dealer and take off with a red one, saying, "It's only a Porsche," even though Porsches are supposed to be fun too.

• People will respond positively to paying for games if they are reminded gently and given the opportunity to pay at their own pace. Ambrosia recently bought a company, Humm-V, from voluntary contributions - folks who were willing to send in $15 to $20 for a serial number.

• The reward for having a serial number need not be big, but there must be some reward. Ambrosia (to use the most successful example in the Mac electronic distribution world) offers contests and the like to registered users. However, the main reward is that the game stops asking for a serial number every time you play it. While the reward need not be big, it needs to be immediate. So, the game itself needs to respond to serial number input.

• Having a single serial number hard-wired into your program doesn't work. It will immediately find its way onto the Internet, and the folks who "crack" your program will think that they belong in the next William Gibson novel.

The glossy box people do not have this problem as much, since they publish mostly on CD-ROM which costs peanuts to reproduce, but much more to copy. To copy protect a CD-ROM, all you have to do is insist that the CD be present (or some 200meg file on the CD) before the program runs. At the current state of the art, your CD costs you under a buck to produce, and a copy costs the freelance pirates about $10 - so, they might as well buy an original.

However, if distributing games on floppies, compilation CDs, or via modem, the economies of scale work against you.

A floppy loaded with your data and labeled costs more to produce than a blank floppy (purchased in boxes of 20) costs a potential pirate. Imagine what the book business would be like if books cost publishers six cents a page to print, and every person in the country had a nickel-per-page copy machine at home.

Compilation CD's (One Thousand Great Games for $19.95) are an effective way spread around demos and shareware games. However, the buyer has my game (and 999 other games), the distributor has $19.95, and I have nothing. Now I need to encourage the buyer to spend a little more. Electronic distribution is the same scenario, except the buyer receives a bill from AOL at the end of the month, and I still have nothing.

Well, not quite nothing. What I have is a marketing opportunity. The opportunity to sell something - an end to the "please register" reminder, a game enhancement, and early access to my next game. The easiest and most effective item for this market is a serial number. Here are some serial number guidelines.

• The serial number should be unique, and the gratification should be immediate. The game program needs to accept and reward any valid serial number, and spurn any invalid serial number.

• There should be more invalid numbers possible than valid numbers. There should be a minimum of 1000 wrong numbers for every right number or the "Hunt and Peck Hackers" will perform brute force solutions instead of doing their history homework.

• The system should be easy for you, easy for the registered user, and easy for the folks that answer your 800 line, fill out the MasterCard slips, and give out the serial numbers.

What does Generator Generate?

Generator cranks out a couple thousand serial numbers per second, and saves them as a tab delineated Excel file. Most databases can import Excel data. You can select start and end numbers from 1 to 999999. I recommend that you generate a reasonable quantity of numbers - you probably don't need a million serial numbers yet, nor do you want to devote 25meg to storing the file. Note that Generator is a 68k Mac program, but since it produces about 120,000 serial numbers per minute, it is probably not worth writing an Accelerated for PowerMac version.

I import my serial numbers into a FileMaker Pro document. FileMaker garbles the first record in the list because it stumbles on the Excel header, so I start my list with 0. I delete the first record, which leaves me with serial number 1 heading the list.

Generator's first function, CalculateValues(), names the file, sets the Excel header, forces tabs into the data where needed, and saves the serial numbers and customer numbers.

Making the numbers unique

For clarity, the twelve digit numbers generated by Generator are grouped in four clumps of three; xxx-xxx-xxx-xxx. They look just like Bonkhead's numbers, but they're not. The uniquifying algorithms used herein are different from theirs, and yours should be different too. You'll have to write your own unique ProduceValues() function if you want your own unique serial numbers, but this version of ProduceValues() will give you some ideas.

Idea #1: ProduceValues() does much of its work with strings, with numerical input converted via LongToStr(). With minor changes, your version can output numbers with characters (both upper and lowercase) and symbols as well as digits (yes, the results are still called serial numbers).

Idea #2: LongToStr() places a string length value in str[0], and a nul value in str[last char + 1], creating a string that is both a Pascal string and a C string. Why? Someday you might be programming cross-platform, and the Mac prefers Pascal strings, and Wintel prefers C strings, and I don't know what Nintendo or the PlayStation use. However, there are a lot of potential customers out there, and they don't all use Macs. Sure, it costs us a character, but who is going to key in a 255 character serial number?

ProduceValues() briefly converts the string values ‘0' through ‘9' back to single-digit numbers, this is purely for the sake of clarity. For example, if you want to use uppercase letters instead of digits, convert

d1 = valStr[i++] - ‘0';

to

uL1 = valStr[i++] - ‘A';

and the number-stirring line (which converts 123 to 321, in this example), from

val1 = (d3*100)+(d2)+(d1/100);

to

val1 = (uL3*676)+(uL2)+(uL1/676);

This converts ABC to CBA. Using uppercase letters makes the serial "number" digital in base 26, giving 676 possible two letter combinations. Using uppercase and lowercase letters, plus the ten numerical digits, gives a base 62, with 3844 two character combinations and about 15 billion four character combinations. No wonder Apple hasn't run out of owner resource ID numbers yet.

In this example, the first and fourth three digit number groups reflect the customer number; 000-xxx-xxx-001 is customer #1, 076-xxx-xxx-345 is customer number 76,345, etc. The second number group is a random-appearing response to number group one, and the third number group is a random-appearing response to number group four. So, the first 999 customers are customers #1 through #999

Why don't we have a customer #0? We are #0. #0 is for in-house testing.

Customers #1 through #999 all have the same second number group (930, in this example) and customers #1 and #4,001 and #38,001 all have the same third number group (it happens to be 228).

The algorithm for generating response numbers is pretty simple in this example.

  • Get a three digit number group (e.g. 123).
  • Add 13 (e.g. 136).
  • Swap the first and third digits (e.g. 631).
  • Multiply by 3 (e.g. 1893).
  • Subtract the original * 2 (e.g. 1893 - 246 = 1647).
  • If the result is negative, convert it to its absolute value.
  • Discard all but the last three digits (e.g. 647).

In real life you will want to use different seed numbers to add (or subtract) in step 2, different swap patterns, different multipliers, and you may want to swap and/or mingle digits from the first and fourth number groups. There are many ways to make your particular serial numbers your own.

Simon says play

The game program requests serial number input from the player, and confirms or denies the validity of that number. Does it run Generator backwards? Nope.

The game generates second and third number groups in response to the first and fourth number groups using exactly the same code as Generator, and checks them against the second and third number groups entered by the player. Are the generated and keystroked numbers identical?

If you are a believer in the heavy-handed school of registration numbers, the game can refuse to run until a suitable number is entered. A lot of glossy-box software uses this system. The only value I see from it is that if the buyer sends in a registration card with the number thereon, you know who to yell at if that number shows up on a BBS or on the pirates.com home page (my apologies if there really is a pirates.com out there).

If you are light-handed, a simple "thank you" splash screen might well suffice, and deactivate the gentle registration reminders that keep popping up. Also, flag this copy of the game as registered, either in the prefs file or in the application itself - do not demand the number be keyed in before every game.

The Number of the Beast - Simon Beeblebrox, #958331

One thing electronic distributors can do that glossy box distributors cannot, is personalize serial numbers. If someone buys a game off the shelf, they expect to be able to go straight home and play it with no further hassle. However, a customer who is mailing in a registration fee for the enhanced version of an electronically distributed game, or is phoning you with a pencil in one hand and a VISA card in the other, is going to give you their name. If you like, you can integrate that name into their serial number.

NameNumerator converts the first 24 characters of a name to a six digit decimal number. The six digit number (e.g. 958331) could be combined with the previous serial number generator (e.g. 958-xxx-xxx-331) to create a real challenge for the crackers.

Let's take a look at NameNumerator's most significant function.


Get Value
GetValue() takes a string up to 255 chars long, and returns a six digit decimal number, in the form of a six 
character string.

void GetValue(Str255 valStr, Str255 retStr)
{
 long i;
 
 for (i=1; i <= 6; i++)   //Load first six char codes
 retStr[i] = (valStr[i] % 10);
 for (i=1; i <= 6; i++)   //Load next six char codes(7 through 12)
 retStr[i] = ((retStr[i] + valStr[i+6]) % 10);
 for (i=1; i <= 6; i++)   //Load third six char codes (13 through 18)
 retStr[i] = ((retStr[i] + valStr[i+12]) % 10);
 for (i=1; i <= 6; i++)   //Load fourth six char codes (19 through 24)
 retStr[i] = ((retStr[i] + valStr[i+18]) % 10);

 //Add 257458 (kinda ) and ‘0' 
 retStr[1] = ((retStr[1] + 2) % 10) + ‘0';
 retStr[2] = ((retStr[2] + 5) % 10) + ‘0';
 retStr[3] = ((retStr[3] + 7) % 10) + ‘0';
 retStr[4] = ((retStr[4] + 4) % 10) + ‘0';
 retStr[5] = ((retStr[5] + 5) % 10) + ‘0';
 retStr[6] = ((retStr[6] + 8) % 10) + ‘0';
}

The first half of GetValue() takes the individual characters of a Str255 (the registrant's name), strips all but the last digit of that character's ASCII code, and places that digit in another Str255. After the first six digits are placed (valStr [1] placed in retStr[1], valStr [2] placed in retStr[2], etc.), the next six are added to the first six (valStr [7] added to retStr[1], valStr [8] added to retStr[2] etc.) and all but the last digit is stripped from the resultant. This process is repeated through 24 characters. However, to distinguish Clifford Hummel Throckmorton-Whitney from Clifford Hummel Throckmorton-Whitfield, you can repeat as necessary.

The second half of GetValue() adds the arbitrary seed number 257458, sorta

Well, it's not quite addition. Actually, we are adding the digit from the hundred thousands column to retStr[1] and stripping off all but the least significant digit from the result, adding the digit from the ten thousands column to retStr[2], and so on. Then we add the ASCII value of the character ‘0', so instead of having the actual digit values in the string, we get the ASCII values of the digits. 0 + ‘0' = ‘0'; that is, 0 + 48 = 48, which is the ASCII code for the character ‘0'. 1 + ‘0' = ‘1'; that is, 1 + 48 = 49, which is the ASCII code for the character ‘1'.

So you have your telemarketing people with NameNumerator up and running on their Macs, and when folks call in their orders, they can say, "How do you spell your name, Mr. McCornack? Your serial number is " and that is why you need to use genuinely arbitrary seed numbers.

For example,

 for (i=1; i <= 6; i++)   //Load first six char codes
 retStr[i] = (valStr[i] % 13);//In base 13

will throw a Spaniard in the works, and

 
for (i=1; i <= 6; i++)    //Load first six char codes
 retStr[i] = (valStr[i] % (10 + i)); //In base (10 + i)

will scramble things even further.

Or perhaps you'd like to use alphabet characters. To start the above six digit example with an uppercase letter, change the first line of the second half of the routine to

 retStr[1] = ((retStr[1] + 2) % 26) + ‘A';

which adds a random-like number from 0 and 25 to the ASCII code for ‘A', giving the full range of capital letters (since ‘A' + 25 = ‘Z').

Conclusion - Big Brother, #964752, is Watching

What is the advantage of personalized serial numbers? Many people who would otherwise distribute a generic serial number will balk at distributing a serial number which only works with their name, thus exposing them as the culprit. However, the typical game pirate is not worth harassing - what are you going to do, have your lawyer's mom call the pirate's mom to tell her she has a naughty kid?

You could build a serial number from a name and phone number, and verify the phone number by having your telemarketers say, "We will call you back in three minutes with your serial number" when the order is placed. However, if I were publishing a high-bucks 3D animation program, I would want to discourage folks from buying one copy and putting it on every workstation in the art department. I could say, "You don't like dongles? Then I will give you a serial number. However, it will only work in conjunction with your name, your credit card number, and its expiration date. If your system isn't secure enough for your credit card data, maybe it isn't secure enough for our program, either. Are you sure you don't want a dongle?"

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.