#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP

3D
3D Photo Gallery (Part 1)
3D Photo Gallery (Part 2)

Audio
Poor Man's MIDI
Make A Metronome
iPod Tricks (Part 1)
iPod Tricks (Part 2)
iPod Tricks (Part 3)
Laugh Track Machine
Audio Player with Reverb
Shepard Melody
RB Phone Home
Build a Drum Machine

Custom Controls and Windows
Double Click Listbox
Draggable Metal Window
Double Click Canvas
Custom Buttons
Custom Buttons Part II
iTunes-style Listboxes
Custom Controls


General RB
Scrolling Windows
Using Mesage Dialogs
Case-Sensitive Word Finder
Introduction to Stacks
Wiggle Window
JPEG in PDF
Listbox Checkboxes
Background Applications
Listbox Auto-Find
Virtual Volumes
Time Tracker
Software Distribution (Part 1)
Software Distribution (Part 2)
Software Distribution (Part 3)
Software Distribution (Part 4)
Exceptions
Tips and Tricks
Text Clippings Made Easy

Graphics
Drawing a Simple Gradient
The SpriteSurface: Space Game
Image Spinner
Cropping Graphics (Part 1)
Cropping Graphics (Part 2)
Cropping Graphics (Part 3)
Cropping Graphics (Part 4)
Shimmer Graphics
Lissajous Figures
Simple Screen Capture
Vector Graphics
Kaleidoscope Images
Stegonography
Spirals!
Image Table
RB Magnifying Lens
Screen Capture
Color Picker Tutorial

Hacks
Ghost Grab
Speedy Mouse Extension
iTunes Plugins
iTunes Skinner

Mac OS X
Global Hot Key Event (Carbon Events)
Login Welcomer (Carbon Events)
Add/Remove Buttons
Resizable Sheets
Mac OS X Preferences Window
Using Sheets in REALbasic
Build a Bundle (Part 1)
Build a Bundle (Part 2)
Dock Your Passwords
Mac OS X Debugging
REALbasic Mac OS X Icon Tutorial
Animate Your Dock
RB and the Command Line

Menus
Window Menu
Templates Menu
Listbox Menu

Novelty
Guessing Game
Calendar Trivia
Tile Mixer
Zip Code Finder
Happy Valentine's Day
Merlin Simulator (Part 1)
Merlin Simulator (Part 2)
Merlin Simulator (Part 3)
Buzzword Machine
AppleSoft BASIC

Printing
Print to PDF

Registration
Registration Code Validation
Network Registration Codes

Resources
Picture Extractor (Part 1)
Picture Extractor (Part 2)

Serial
Caller ID (Part 1)
Caller ID (Part 2)
Caller ID (Part 3)

Speech
Speech Recognition

Socket Communication
Easy Peer-to-Peer File Sharing
MacPAD Version Checking
Display Web Image In Canvas
HTML IMG Tags
Version Tracking
Even Smarter Instant Messaging
Web Tiler
JavaScript and REALbasic
Stock Ticker (Part I)
Stock Ticker (Part 2)
AIM Mate

XML Manipulation
Simple XML Introduction

Video
Big Brother Video Capture

Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.

resexc2.gif (20k)




REALbasic for Dummies
by Erick Tejkowski

$19.99 @ Amazon





Files are in Stuffit 6.5 or earlier, or ZIP format.
Download Stuffit Expander

Tell us about a bad link.

Software Distribution Part III
04-19-02




04-19_money.jpg (2746bytes) Today we conclude our discussion about releasing software by examining some code for protecting your software. This time we'll look at some code to get you started on a software protection scheme.

Introduction

As I mentioned last week, there are many possible ways for you to "protect" your software. I put "protect" in quotation marks, because in reality, your best efforts in software protection will be thwarted. Don't fret, though. With a little creativity, you can stop casual pirates (i.e. keep the honest folks honest) and slow down the pirates.

Code Examples

Last week we looked as some possible tools you can use to protect your software. Some of these include:

  • Registration Key
  • Nagware
  • Partial features
  • Time-limited demo
  • CD-ROM required

Registration Key Perhaps the most common prevention tool is the registration key. In this scheme you issue some sort of key to clients and customers. The user enters the key when prompted and the software is registered for use. As you might imagine, there are many ways to approach this problem. The main idea is to make a registration key algorithm that produces keys that are difficult to reproduce from thin air. Usually this means a string containing letters and numbers, often combined into groups of 4 or 5 characters at a time. For example, you might construct a registration key like this:

  dim name,s as string 
  dim code as string
  dim i,v,value1,value2 as integer
  
  //normally we'd assign this
  //from an editfield or some such
  name = NameKeyField.text
  
  //we will construct a registration key
  //of three groups
  //that looks like this
  //XXXX-XXXX-XXXX-XXXX
  
  //1. XXXX - number of characters in the name
  //2. XXXX - the sum of the ASCII value of each character
  //3. XXXX - a checksum (1st set + 2nd set)
  
  //1. we want four characters when this is all over
  //so just tack on four zeroes to the name now
  //we may not need it, but we'll chop off what we don't
  //with the "right" statement
  s = "0000"+str(len(name))
  s = right(s,4)
  value1 = val(s)
  code = s+"-"
  
  //2. add up all the ascii values for each character
  // watch out! if the name is too long, values over 9999 will be a problem
  //not a problem for most names :-)
  v=0
  for i=1 to len(name)
    v = v+asc(mid(name,i,1))
  next
  s = "0000"+str(v)
  s = right(s,4)
  value2 = val(s)
  code=code+s+"-"
  
  //3. - calculate the checksum
  s = "0000"+str(value1+value2)
  s = right(s,4)
  code=code+s
  staticText1.text = code

This is a rudimentary example for creating registration keys, but it illustrates an important point or two. First off, there are many ways you can combine characters and digits to form a registration key. Be creative here. Any little twist you can add will throw the casual software pirate. Secondly, the final segment being a checksum is important. Checksums lower the probability that a pirate can randomly produce valid keys. This stems from the fact that information in the checksum is dependent on information elsewhere in the key. This makes it harder for the crackers that are trying to defeat your protection by automatically generating random registration keys in search of a valid one. Some other things to consider about registration keys:

  • Registration Keys are most often "cracked" by brute force methods (randomly generated keys) or legitimate users sharing their codes
  • Don't permit users to attempt registration more than a few times. After 3 or 4 failed attempts, force the application to quit (in a friendly manner of course). This helps thwart brute force methods, because the pirate has to repeatedly restart your application to try more keys.
  • Don't tell anyone your registration scheme (duh!)

The above code showed you how to create a registration key. To use the key, simply test it in reverse.

  dim key,name,s as string
  dim group1,group2,group3 as string
  dim i,v as integer
  
  key = KeyField.text 
  name = NameField.text 
  
  if len(key)<>14 then
    MsgBox "Invalid key"
    return
  end if
  
  group1 = mid(key,1,4)
  group2 = mid(key,6,4)
  group3 = mid(key,11,4)
  
  //test group 1
  if len(name)<>val(group1) then
    MsgBox "Invalid key"
    return
  end if
  
  //test group 2
  v=0
  for i=1 to len(name)
    v = v+asc(mid(name,i,1))
  next
  s = "0000"+str(v)
  s = right(s,4)
  if s<>group2 then
    MsgBox "Invalid key"
    return
  end if
  
  //test group 3
  if val(group3)<>(val(group1)+val(group2)) then
    MsgBox "Invalid key"
    return
  end if
  
  MsgBox "Valid key"

Conclusion

We've looked at some of the issues you are up against when trying to sell software, but when it comes down to it creativity, fortitude, and good code are your best weapons. You can download the code used in this tutorial to help you get started. Have fun and see you next week!






Please support ResExcellence by Visiting our Sponsors. One click makes a difference.


Download REALbasic and create your own software!

#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP