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

The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »

Price Scanner via MacPrices.net

Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more

Jobs Board

Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.