License Key Generator

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only




Problem Description

Here's a "proof of concept" demo program implementing my ideas far an algorithm to  generate program license keys when a product is purchased.  The is then   that can be used by the program when the program is activated or run

The algorithm used here is original with me and, as far as I know, will NOT generate keys for any existing commercial programs!

Background & Techniques

Overview  A user recently requested a model to create a license to include purchaser's name, licensing date, and license period.   Here's first cut at a method to accomplish this.  I have generalized the technique by including a field definition table which provides field names, lengths, and whether the field is fixed or variable length.   License keys consist of upper case letters and numbers separated by hyphen "-" characters into a fixed number of fixed size segments. 

Below is a screen shot of   sample key definition input parameters  and encryption key generation (left side) and test controls for building and decoding License Keys  for a specific license (right side).


Note that generated keys are restricted to uppercase letters and digits 0 to 9.  This seems to be the case in professionally generated keys I have observed.  If all of these 36 symbols are to be allowed in the input fields, then special characters cannot be encoded.  I can think of ways around this at the expense of key length, (See "Suggestions" section below).   Variable length fields are padded with random characters to reach the maximum length.  Fields longer than the specified length are truncated. 

If the size of the defined data (field length sum + variable field count) is less than the desired license key length (segment size X  # of segments) then consider adding additional "dummy" unused fields  or expanding fixed fields by making them larger variable length fields.

Encryption Key and License Key Generation

The encryption algorithm is a simple substitution process.  The 36 allowed character are randomly shuffled to generate the encryption key.   The License Key generation process finds the position of each input character in the Master Key and replaces it with the character from the same position in the Encryption Key.   For variable length fields, the initial character represents the number of characters required to pad the field to its  specified maximum length ("A"=0, "B"-1, etc.). Than number of random characters is then added to the License Key before the encrypted field data is appended.   A hyphen character is inserted every "SegSize" characters in the displayed key for ease of user entry.

License Key Decryption

In the application registration processing, the License key from the user is decoded to recreate the original data fields. These can be used to validate the license conditions and approve or deny access to the application itself.   The process simply reverses the role of the Master Key and the Encryption Key.  So if  "A" in position 1 of the Master Key was converted to a "4"  at encryption time, then a "4" in the license will be found in the 1st position of the Encryption Key and changed back to the  "A" in the Master Key.      


Testing steps:

1. Define the fields: Enter lines with formatted as "Field name"="Field Size".  Precede a field size with the letter "V"
to indicate that it is variable length. Each variable length field will take up 1 character of the License keys generated.
The sum of sizes + the number of "V" fields must equal the product of the specified key segment size and the number of segments in the key.

2.Specify key segment size and number of segments based on field definitions.

3.Generate an encryption key.

4.For each license key to be generated, .enter the appropriate field names values and click "Make License Key" button

5. The "Decrypt" button will use the field definition data and the encryption key to convert License Key back to the original input data fields.

Addendum June 16, 2015:  Version 1.1 corrects a few spelling errors and improves screen formatting.  As the result of being flagged as a Trojan by  the "Webroot Secure Anywhere" program, I also added the disclaimer stating that the program will not generate a valid key for any existing commercial program that i know of.      

September September 29, 2015: Someone actually playing with the demo program uncovered a few bugs leading to the creations of Version 2.0 posted today.   Errors corrected are as follows:

bullet There was no scrollbar on the decoded display data and it did not scroll the top back into view making it appear that fields were missing when there were more than four  of them.  The "ScrollToTop" procedure in the DFFUtils unit will require that the DFF Library zip file be downloaded to use this fix. 
bullet Special characters were dropped without warning but causing misleading length mismatch error messages.  Special characters are now dropped but lengths are adjusted and the user is notified that they were dropped.
bullet Long License keys are displayed on multiple lines but only the first line was used,  when decoding causing an error.        
bullet Formatting errors when entering field definitions were not well diagnosed.

Encoding special characters is still a problem which might be somewhat accommodated by breaking fields containing them into multiple parts.  For example "FirstName" and "LastName" in stead of a "Name" field containing both names and an embedded space.    Seldom used letters or letter combinations might be implemented in a future version if they are required. 

September 18, 2016:  Version 2.1 was posted a couple of weeks ago to add the ability to encode and decode the letter M, accidentally omitted from the previous version.  So Mary Doe can now register her software  just like Joe could.   Version 2.2, posted today, expands data entry by removing the requirement that all defined fields be entered in the same order as they were defined.  A subset of defined fields may be entered in any order.      

Running/Exploring the Program 

bulletDownload executable
bullet Download source   
bulletDownload current DFF Library Source   (DFFLibV15 )  or earlier version required to recompile this program.

Suggestions for Further Explorations

Enhance security by interleaving selected fields into the key - for example make the 3 digit "days remaining" field occupy the 3rd, 5th, and 7th positions of the displayed key, then move this those three characters back to the end  of the key before doing the current decryption process.
September 18, 2016: Suggestion implemented by defining an EncryptionVersion field as the first  field in the License Key.  Enhance security and reliability by prefixing or appending a character representing the current processing algorithm version.   The programs could then handle changes if the processing of License Keys to accommodate changes without invalidating existing keys.
 Could extra characters be accepted by  replacing an unused character with a desired character, e.g. Q= space character.       

Created: December 23, 2014

Modified: May 31, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.