<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brandon Staggs .Com &#187; misv</title>
	<atom:link href="http://www.brandonstaggs.com/tag/misv/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandonstaggs.com</link>
	<description>Software, Society, the Bible, Politics, and everything else.</description>
	<lastBuildDate>Fri, 18 Jun 2010 03:01:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Beat Programmer&#8217;s Block</title>
		<link>http://www.brandonstaggs.com/2009/04/03/how-to-beat-programmers-block/</link>
		<comments>http://www.brandonstaggs.com/2009/04/03/how-to-beat-programmers-block/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 22:23:40 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Software & Technology]]></category>
		<category><![CDATA[misv]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.brandonstaggs.com/?p=422</guid>
		<description><![CDATA[My own experiences programming are as a self-employed, generally self-motivated coder, designing software I want to design. If you are an employee writing code implementing someone else&#8217;s specifications, this may not be helpful.
For me, programming is usually a creative process.  Unless I am fixing small bugs or making minor tweaks, writing software is no [...]]]></description>
			<content:encoded><![CDATA[<p>My own experiences programming are as a self-employed, generally self-motivated coder, designing software I want to design. If you are an employee writing code implementing someone else&#8217;s specifications, this may not be helpful.</p>
<p>For me, programming is usually a creative process.  Unless I am fixing small bugs or making minor tweaks, writing software is no different from writing a story, a song, a poem, or drawing a picture. It is an abstract process by which I turn general ideas into something that doesn&#8217;t quite approach a true language. There is a purely creative process: coming up with ideas to implement. And there is a less creative, but often just as abstract a process: turning those ideas into little processes that a compiler can understand.</p>
<p>Since writing code is so much like writing anything else, a programmer is prone to &#8220;programmer&#8217;s block&#8221; just as an author of a novel can be afflicted with writer&#8217;s block.</p>
<p>Beating programmer&#8217;s block <em>while simultaneously staying productive</em> is something easily done as long as you keep these things in mind:</p>
<ul>
<li>When you&#8217;re stuck, do something else.</li>
<li>It&#8217;s easy to do something else if you have more than one project.</li>
</ul>
<p>It&#8217;s really that simple, at least for me. At any given time I have at least a half-dozen &#8220;things&#8221; I can do that constitute productive behavior.  If I experience programmer&#8217;s block when developing one application, I have several others I can go work on for a while. Or, I can write a blog entry or even read a business-related book.</p>
<p>The key is to have more than one thing to do at any given time, so that when project A gets stuck, you can go work on project B for a while.  It&#8217;s not hard. And for me, the goal is to take a break without becomming idle.  Sure, vacations and long-term breaks have their place, but with all those people on welfare counting on my taxes, I just can&#8217;t <em>relax</em> when I am truly doing <em>nothing</em> so I always have something else I can do when I hit a wall.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandonstaggs.com/2009/04/03/how-to-beat-programmers-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Has Limits</title>
		<link>http://www.brandonstaggs.com/2007/08/12/software-has-limits/</link>
		<comments>http://www.brandonstaggs.com/2007/08/12/software-has-limits/#comments</comments>
		<pubDate>Sun, 12 Aug 2007 20:58:25 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Software & Technology]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[misv]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.brandonstaggs.com/2007/08/12/software-has-limits/</guid>
		<description><![CDATA[As I write this, somewhere around 8,000 people are stuck in LAX waiting to go through customs because of a computer glitch.
Frankly, I am amazed this doesn&#8217;t happen more often. This reminds me of a book I recently read called The Limits of Software. Anyone who is curious about why computers and software so frequently don&#8217;t work [...]]]></description>
			<content:encoded><![CDATA[<p>As I write this, somewhere around 8,000 people are stuck in LAX waiting to go through customs because of a <a href="http://abclocal.go.com/kabc/story?section=local&amp;id=5561125" target="_blank">computer glitch</a>.</p>
<p>Frankly, I am amazed this doesn&#8217;t happen more often. This reminds me of a book I recently read called <em><a href="http://www.amazon.com/gp/product/0201433230?ie=UTF8&amp;tag=utopianreject-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0201433230" target="_blank">The Limits of Software</a></em>. Anyone who is curious about why computers and software so frequently don&#8217;t work properly would benefit from reading it.</p>
<p><em>The Limits of Software</em> is a sort of docu-drama in book form about the massive failed attempt at upgrading the Federal Aviation Administration&#8217;s ancient computer systems. The event is a case-study proving that all the money in the world can&#8217;t make the impossible happen. But since the government can just spend, spend, spend, they sure did give the impossible a try. I highly recommend this book for programmers or anyone who wants to understand what kind of problems programmers are always trying to solve.</p>
<p>What it all boils down to is that software is a means of describing abstract human thought for computers to understand and implement in reality. It will never be perfect.</p>
<p>No consolation for the 8,000 poor folks stranded in LAX, I know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandonstaggs.com/2007/08/12/software-has-limits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing a Partial Serial Number Verification System in Delphi</title>
		<link>http://www.brandonstaggs.com/2007/07/26/implementing-a-partial-serial-number-verification-system-in-delphi/</link>
		<comments>http://www.brandonstaggs.com/2007/07/26/implementing-a-partial-serial-number-verification-system-in-delphi/#comments</comments>
		<pubDate>Thu, 26 Jul 2007 15:07:25 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Software & Technology]]></category>
		<category><![CDATA[delphi]]></category>
		<category><![CDATA[misv]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.brandonstaggs.com/2007/07/26/implementing-a-partial-serial-number-verification-system-in-delphi/</guid>
		<description><![CDATA[Most micro-ISVs use a serial number/registration code system to allow end users to unlock or activate their purchase.  The problem most of us have run into is that a few days or weeks after our software is released, someone has developed a keygen, a crack, or has leaked a serial number across the internet.
There are [...]]]></description>
			<content:encoded><![CDATA[<p>Most micro-ISVs use a serial number/registration code system to allow end users to unlock or activate their purchase.  The problem most of us have run into is that a few days or weeks after our software is released, someone has developed a keygen, a crack, or has leaked a serial number across the internet.</p>
<p>There are several possible solutions to this problem. You could license a system like Armadillo/Software Passport or ASProtect, or you could distribute a separate full version as a download for your paying customers. Each option has advantages and disadvantages. What I am going to show you is a way to keep &#8220;rolling your own&#8221; license key system while making working cracks harder for crackers to produce, and working keygens a thing of the past.</p>
<p><span id="more-337"></span></p>
<p>Aside: If you think it&#8217;s crazy to post this publicly where crackers can see it, don&#8217;t worry about that. I&#8217;m not posting anything they haven&#8217;t seen before. The entire point of partial key verification is that your code never includes enough information to reverse engineer a key generation algorithm. Also, I offer no warranty of any kind &#8212; this is for your information only! Now, on with things.</p>
<p><strong>Our license key system must meet some basic requirements.</strong></p>
<ol type="1">
<li>License keys must be easy enough to type in.</li>
<li>We must be able to blacklist (revoke) a license key in the case of chargebacks or purchases with stolen credit cards.</li>
<li>No &#8220;phoning home&#8221; to test keys.  Although this practice is becoming more and more prevalent, I still do not appreciate it as a user, so will not ask my users to put up with it.</li>
<li>It should not be possible for a cracker to disassemble our released application and produce a working &#8220;keygen&#8221; from it. This means that our application will <em>not</em> fully test a key for verification. Only <em>some</em> of the key is to be tested. Further, each release of the application should test a <em>different</em> portion of the key, so that a phony key based on an earlier release will not work on a later release of our software.</li>
<li>Important: it should not be possible for a legitimate user to accidentally type in an invalid key that will appear to work but fail on a future version due to a typographical error.</li>
</ol>
<p>The solution is called a <em>Partial Key Verification System</em> because your software never tests the full key. Since your application does not include the code to test every portion of the key, it is impossible for a cracker to build a working valid key generator just by disassembling your executable code.</p>
<p>This system is <em>not</em> a way to prevent cracks entirely. It will still be possible for a cracker to edit your executable to jump over verification code. But such cracks only work on one specific release, and I&#8217;ll suggest a couple of tricks to make their job harder to complete successfully.</p>
<p>Let&#8217;s jump right in.  I&#8217;ll show you the system with Delphi code. (Given the readable nature of Delphi Pascal, you should be able to use these examples to build your own system in any language.)</p>
<p>An aside: if you think it&#8217;s crazy to post this publicly where crackers can see it, don&#8217;t worry! I&#8217;m not posting anything they don&#8217;t know. The whole point of this system is that your code never contains enough information for a cracker to reverse-engineer your key system. My blog post here doesn&#8217;t give them any information they don&#8217;t already have. Also, I&#8217;m not offering <em>any</em> kind of warranty with this information. This is for your information only, and all that. Now, on with things!</p>
<p><strong>1. The Key Format</strong></p>
<p>This example will create and test keys of 20 characters (with hyphens added for user convenience). A valid key will look like this:<br />
<tt>A279-1717-7D7A-CA2E-7154</tt></p>
<p>Once the hyphens are stripped, this is how the key breaks down:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="98" valign="top">
<p style="text-align: center">Seed value</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">Key Byte 0</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">Key Byte 1</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">Key Byte 2</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">Key Byte 3</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">Checksum</p>
</td>
</tr>
<tr>
<td width="98" valign="top">
<p style="text-align: center">A2791717</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">7D</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">7A</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">CA</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">2E</p>
</td>
<td width="98" valign="top">
<p style="text-align: center">7154</p>
</td>
</tr>
</tbody>
</table>
<p>This sample system only uses four bytes for key verification, but a real system should use many more and larger values, so keep that in mind if you begin implementing your own PKVS.</p>
<p><strong>2. The Seed Value</strong></p>
<p>This sample system uses a 64-bit integer as a &#8220;seed&#8221; to generate the &#8220;Key Bytes&#8221; from.  The example project just generates random values for seeds, but when you implement a system like this, you must ensure that the seeds are always unique, because the seed is used when blacklisting a key. The seed could itself be a hash of a user name and time of generation, or any number of things</p>
<p><strong>3. Computing Key Bytes</strong></p>
<p>Here is the heart of the PKVS. Each &#8220;byte&#8221; of the key is a result of an operation on the seed value.  Here is a simple &#8220;byte&#8221; value computation function. It performs some bit twiddling based on the supplied parameters:</p>
<pre><strong><span>function</span></strong><span> PKV_GetKeyByte<strong>(const</strong> Seed <strong>:</strong> Int64<strong>;</strong> a<strong>,</strong> b<strong>,</strong> c <strong>:</strong> Byte<strong>)</strong> <strong>:</strong> Byte<strong>;
</strong></span><strong><span>begin
</span></strong><span>  a <strong>:=</strong> a <strong>mod</strong> <span style="color: #e00000">25</span><strong>;
</strong></span><span>  b <strong>:=</strong> b <strong>mod</strong> <span style="color: #e00000">3</span><strong>;</strong></span></pre>
<pre><span>  <strong>if</strong> a <strong>mod</strong> <span style="color: #e00000">2</span> <strong>=</strong> <span style="color: #e00000">0</span> <strong>then
</strong></span><span>    result <strong>:=</strong> <strong>((</strong>Seed <strong>shr</strong> a<strong>)</strong> <strong>and</strong> <strong>$</strong><span style="color: #e00000">000000FF</span><strong>)</strong> <strong>xor</strong> <strong>((</strong>Seed <strong>shr</strong> b<strong>)</strong> <strong>or</strong> c<strong>)
</strong></span><span>  <strong>else
</strong></span><span>    result <strong>:=</strong> <strong>((</strong>Seed <strong>shr</strong> a<strong>)</strong> <strong>and</strong> <strong>$</strong><span style="color: #e00000">000000FF</span><strong>)</strong> <strong>xor</strong> <strong>((</strong>Seed <strong>shr</strong> b<strong>)</strong> <strong>and</strong> c<strong>);
</strong></span><strong><span>end;</span></strong></pre>
<p>We&#8217;ll see in a moment how this function is used in the key generation and checking algorithms. Please keep in mind that this example function is very simplistic. A more effective function would use larger values than bytes and employ a more complex hashing system.</p>
<p><strong>4. We need a checksum</strong></p>
<p>Once we have our seed and bytes formed into a string of characters, we need to add a checksum to it. This way we can know when a user makes a mistake entering their key, without having to actually check each portion of the key for validity.</p>
<pre><strong><span>function</span></strong><span> PKV_GetChecksum<strong>(const</strong> s <strong>:</strong> <strong>String)</strong> <strong>:</strong> <strong>String;</strong></span></pre>
<pre><strong><span>var
</span></strong><span>  left<strong>,</strong> right<strong>,</strong> sum <strong>:</strong> Word<strong>;
</strong></span><span>  i <strong>:</strong> Integer<strong>;
</strong></span><strong><span>begin
</span></strong><span>  left <strong>:=</strong> <strong>$</strong><span style="color: #e00000">0056</span><strong>;
</strong></span><span>  right <strong>:=</strong> <strong>$</strong><span style="color: #e00000">00AF</span><strong>;</strong></span></pre>
<pre><span>  <strong>if</strong> Length<strong>(</strong>s<strong>)</strong> <strong>&gt;</strong> <span style="color: #e00000">0</span> <strong>then
</strong></span><span>    <strong>for</strong> i <strong>:=</strong> <span style="color: #e00000">1</span> <strong>to</strong> Length<strong>(</strong>s<strong>)</strong> <strong>do
</strong></span><span>    <strong>begin
</strong></span><span>      right <strong>:=</strong> right <strong>+</strong> Byte<strong>(</strong>s<strong>[</strong>i<strong>]);
</strong></span><span>      <strong>if</strong> right <strong>&gt;</strong> <strong>$</strong><span style="color: #e00000">00FF</span> <strong>then
</strong></span><span>        Dec<strong>(</strong>right<strong>,</strong> <strong>$</strong><span style="color: #e00000">00FF</span><strong>);
</strong></span><span>      Inc<strong>(</strong>left<strong>,</strong> right<strong>);
</strong></span><span>      <strong>if</strong> left <strong>&gt;</strong> <strong>$</strong><span style="color: #e00000">00FF</span> <strong>then
</strong></span><span>        Dec<strong>(</strong>left<strong>,</strong> <strong>$</strong><span style="color: #e00000">00FF</span><strong>);
</strong></span><span>    <strong>end;</strong></span></pre>
<pre><span>  sum <strong>:=</strong> <strong>(</strong>left <strong>shl</strong> <span style="color: #e00000">8</span><strong>)</strong> <strong>+</strong> right<strong>;
</strong></span><span>  result <strong>:=</strong> IntToHex<strong>(</strong>sum<strong>,</strong> <span style="color: #e00000">4</span><strong>);
</strong></span><strong><span>end;</span></strong></pre>
<p>This function computes a simple 8-bit value from the supplied string and returns it as a hexidecimal string, which we tack on to the end of our key.</p>
<p>Note that because this routine is always used to check a key in your application, a would-be keygen coder will be able to generate keys that pass the checksum test.  That&#8217;s okay.  The point of the checksum is only to prevent your users from mistyping their own valid license keys, and it will aid in determining if a key was deliberately forged.</p>
<p><strong>5. Putting it together: generating a valid key</strong></p>
<p>For our key generation program, we&#8217;re going to need a single function we can call to get a license key string from a seed value. Here it is:</p>
<pre><strong><span>function</span></strong><span> PKV_MakeKey<strong>(const</strong> Seed <strong>:</strong> Int64<strong>)</strong> <strong>:</strong> <strong>String;
</strong></span><strong><span>var
</span></strong><span>  KeyBytes <strong>:</strong> <strong>array[</strong><span style="color: #e00000">0..3</span><strong>]</strong> <strong>of</strong> Byte<strong>;
</strong></span><span>  i <strong>:</strong> Integer<strong>;
</strong></span><strong><span>begin
</span></strong><span>  <span style="color: blue">// Fill KeyBytes with values derived from Seed.
</span></span><span>  <span style="color: blue">// The parameters used here must be extactly the same
</span></span><span>  <span style="color: blue">// as the ones used in the PKV_CheckKey function.
</span></span><span>  <span style="color: blue">// A real key system should use more than four bytes.</span></span></pre>
<pre><span>  KeyBytes<strong>[</strong><span style="color: #e00000">0</span><strong>]</strong> <strong>:=</strong> PKV_GetKeyByte<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">24</span><strong>,</strong> <span style="color: #e00000">3</span><strong>,</strong> <span style="color: #e00000">200</span><strong>);
</strong></span><span>  KeyBytes<strong>[</strong><span style="color: #e00000">1</span><strong>]</strong> <strong>:=</strong> PKV_GetKeyByte<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">10</span><strong>,</strong> <span style="color: #e00000">0</span><strong>,</strong> <span style="color: #e00000">56</span><strong>);
</strong></span><span>  KeyBytes<strong>[</strong><span style="color: #e00000">2</span><strong>]</strong> <strong>:=</strong> PKV_GetKeyByte<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">1</span><strong>,</strong> <span style="color: #e00000">2</span><strong>,</strong> <span style="color: #e00000">91</span><strong>);
</strong></span><span>  KeyBytes<strong>[</strong><span style="color: #e00000">3</span><strong>]</strong> <strong>:=</strong> PKV_GetKeyByte<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">7</span><strong>,</strong> <span style="color: #e00000">1</span><strong>,</strong> <span style="color: #e00000">100</span><strong>);</strong></span></pre>
<pre><span> </span><span>  <span style="color: blue">// the key string begins with a hexidecimal string of the seed
</span></span><span>  result <strong>:=</strong> IntToHex<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">8</span><strong>);</strong></span><span> </span></pre>
<pre><span>  <span style="color: blue">// then is followed by hexidecimal strings of each byte in the key
</span></span><span>  <strong>for</strong> i <strong>:=</strong> <span style="color: #e00000">0</span> <strong>to</strong> <span style="color: #e00000">3</span> <strong>do
</strong></span><span>    result <strong>:=</strong> result <strong>+</strong> IntToHex<strong>(</strong>KeyBytes<strong>[</strong>i<strong>],</strong> <span style="color: #e00000">2</span><strong>);</strong></span></pre>
<pre><span>  <span style="color: blue">// add checksum to key string
</span></span><span>  result <strong>:=</strong> result <strong>+</strong> PKV_GetChecksum<strong>(</strong>result<strong>);</strong></span></pre>
<pre><span>  <span style="color: blue">// Add some hyphens to make it easier to type
</span></span><span>  i <strong>:=</strong> Length<strong>(</strong>result<strong>)</strong> <strong>-</strong> <span style="color: #e00000">3</span><strong>;
</strong></span><span>  <strong>while</strong> <strong>(</strong>i <strong>&gt;</strong> <span style="color: #e00000">1</span><strong>)</strong> <strong>do
</strong></span><span>  <strong>begin
</strong></span><span>    Insert<strong>(</strong><span style="color: #00a000">'-'</span><strong>,</strong> result<strong>,</strong> i<strong>);
</strong></span><span>    Dec<strong>(</strong>i<strong>,</strong> <span style="color: #e00000">4</span><strong>);
</strong></span><span>  <strong>end;
</strong></span><strong><span>end;</span></strong></pre>
<p>Important: <em>never</em> compile this valid key generator function into your release application! It is only to be used on your end to generate valid keys. The success of a PKVS is based on keeping the parameters used in the PKV_GetKeyByte call <em>secret</em> and away from the prying eyes of crackers.  Remember: if it&#8217;s in your compiled executable, a cracker can see it!</p>
<p><strong>6. Testing a key in your application</strong></p>
<p>Your application needs two functions for testing a key.</p>
<p>The first is a function for testing <em>only</em> the checksum value.  You&#8217;ll use this to test the key when a user types it in.  To make it harder for a cracker, this is <em>all</em> you want to test at first. More on this later.</p>
<p>The second function actually verifies portions of the key to see if they are valid, and also checks against the blacklist to see if a key should be rejected based on its seed value.</p>
<p>First we need to define the constants:</p>
<pre><strong><span>const
</span></strong><span>  KEY_GOOD <strong>=</strong> <span style="color: #e00000">0</span><strong>;
</strong></span><span>  KEY_INVALID <strong>=</strong> <span style="color: #e00000">1</span><strong>;
</strong></span><span>  KEY_BLACKLISTED <strong>=</strong> <span style="color: #e00000">2</span><strong>;
</strong></span><span>  KEY_PHONY <strong>=</strong> <span style="color: #e00000">3</span><strong>;</strong></span><span> </span></pre>
<pre><span>  BL <strong>:</strong> <strong>array[</strong><span style="color: #e00000">0..0</span><strong>]</strong> <strong>of</strong> <strong>String</strong> <strong>=</strong> <strong>(
</strong></span><span>                                <span style="color: #00a000">'11111111'
</span></span><span>                               <strong>);</strong></span></pre>
<p>Above, BL is an array of blacklist strings. Important: only include the seed portion. Remember: if you put it in your program, a cracker can see it.  So do not put an entire key in the blacklist. That just makes it easier for a cracker to see what a valid key should look like.</p>
<p>Here is the checksum check function:</p>
<pre><strong><span>function</span></strong><span> PKV_CheckKeyChecksum<strong>(const</strong> Key <strong>:</strong> <strong>String)</strong> <strong>:</strong> Boolean<strong>;
</strong></span><strong><span>var
</span></strong><span>  s<strong>,</strong> c <strong>:</strong> <strong>String;
</strong></span><strong><span>begin
</span></strong><span>  result <strong>:=</strong> False<strong>;</strong></span></pre>
<pre><span>  <span style="color: blue">// remove cosmetic hypens and normalize case
</span></span><span>  s <strong>:=</strong> UpperCase<strong>(</strong>StringReplace<strong>(</strong>Key<strong>,</strong> <span style="color: #00a000">'-'</span><strong>,</strong> <span style="color: #00a000">''</span><strong>,</strong> <strong>[</strong>rfReplaceAll<strong>]));
</strong></span><span>  <strong>if</strong> Length<strong>(</strong>s<strong>)</strong> <strong>&lt;&gt;</strong> <span style="color: #e00000">20</span> <strong>then
</strong></span><span>    exit<strong>;</strong> <span style="color: blue">// Our keys are always 20 characters long</span></span></pre>
<pre><span>  <span style="color: blue">// last four characters are the checksum
</span></span><span>  c <strong>:=</strong> Copy<strong>(</strong>s<strong>,</strong> <span style="color: #e00000">17</span><strong>,</strong> <span style="color: #e00000">4</span><strong>);
</strong></span><span>  SetLength<strong>(</strong>s<strong>,</strong> <span style="color: #e00000">16</span><strong>);</strong></span></pre>
<pre><span>  <span style="color: blue">// compare the supplied checksum against the real checksum for
</span></span><span>  <span style="color: blue">// the key string.
</span></span><span>  result <strong>:=</strong> c <strong>=</strong> PKV_GetChecksum<strong>(</strong>s<strong>);
</strong></span><strong><span>end;</span></strong></pre>
<pre></pre>
<p>And finally, we come to the function that tests keys for validity. In the sample code, I am using conditional defines to allow me to easily exclude &#8220;key bytes&#8221; from the checking function, but you could just as easily comment them out.  My advice is to only include one or two checks in a release, and to change which ones are checked for each release. Again, our example only has four &#8220;check bytes&#8221; but you should use many more.</p>
<pre><strong><span>function</span></strong><span> PKV_CheckKey<strong>(const</strong> S <strong>:</strong> <strong>String)</strong> <strong>:</strong> Integer<strong>;
</strong></span><strong><span>var
</span></strong><span>  Key<strong>,</strong> kb <strong>:</strong> <strong>String;
</strong></span><span>  Seed <strong>:</strong> Int64<strong>;
</strong></span><span>  i <strong>:</strong> Integer<strong>;
</strong></span><span>  b <strong>:</strong> Byte<strong>;
</strong></span><strong><span>begin
</span></strong><span>  result <strong>:=</strong> KEY_INVALID<strong>;
</strong></span><span>  <strong>if</strong> <strong>not</strong> PKV_CheckKeyChecksum<strong>(</strong>S<strong>)</strong> <strong>then
</strong></span><span>    exit<strong>;</strong> <span style="color: blue">// bad checksum or wrong number of characters</span></span></pre>
<pre><span>  <span style="color: blue">// remove cosmetic hypens and normalize case
</span></span><span>  Key <strong>:=</strong> UpperCase<strong>(</strong>StringReplace<strong>(</strong>S<strong>,</strong> <span style="color: #00a000">'-'</span><strong>,</strong> <span style="color: #00a000">''</span><strong>,</strong> <strong>[</strong>rfReplaceAll<strong>]));</strong></span></pre>
<pre><span>  <span style="color: blue">// test against blacklist
</span></span><span>  <strong>if</strong> Length<strong>(</strong>BL<strong>)</strong> <strong>&gt;</strong> <span style="color: #e00000">0</span> <strong>then
</strong></span><span>    <strong>for</strong> i <strong>:=</strong> Low<strong>(</strong>BL<strong>)</strong> <strong>to</strong> High<strong>(</strong>BL<strong>)</strong> <strong>do
</strong></span><span>      <strong>if</strong> StartsStr<strong>(</strong>BL<strong>[</strong>i<strong>],</strong> Key<strong>)</strong> <strong>then
</strong></span><span>      <strong>begin
</strong></span><span>        result <strong>:=</strong> KEY_BLACKLISTED<strong>;
</strong></span><span>        exit<strong>;
</strong></span><span>      <strong>end;</strong></span></pre>
<pre><span>  <span style="color: blue">// At this point, the key is either valid or forged,
</span></span><span>  <span style="color: blue">// because a forged key can have a valid checksum.
</span></span><span>  <span style="color: blue">// We now test the "bytes" of the key to determine if it is
</span></span><span>  <span style="color: blue">// actually valid.</span></span></pre>
<pre><span>  <span style="color: blue">// When building your release application, use conditional defines
</span></span><span>  <span style="color: blue">// or comment out most of the byte checks!  This is the heart
</span></span><span>  <span style="color: blue">// of the partial key verification system. By not compiling in
</span></span><span>  <span style="color: blue">// each check, there is no way for someone to build a keygen that
</span></span><span>  <span style="color: blue">// will produce valid keys.  If an invalid keygen is released, you
</span></span><span>  <span style="color: blue">// simply change which byte checks are compiled in, and any serial
</span></span><span>  <span style="color: blue">// number built with the fake keygen no longer works.</span></span></pre>
<pre><span>  <span style="color: blue">// Note that the parameters used for PKV_GetKeyByte calls MUST
</span></span><span>  <span style="color: blue">// MATCH the values that PKV_MakeKey uses to make the key in the
</span></span><span>  <span style="color: blue">// first place!</span></span></pre>
<pre><span>  result <strong>:=</strong> KEY_PHONY<strong>;</strong></span></pre>
<pre><span>  <span style="color: blue">// extract the Seed from the supplied key string
</span></span><span>  <strong>if</strong> <strong>not</strong> TryStrToInt64<strong>(</strong><span style="color: #00a000">'$'</span> <strong>+</strong> Copy<strong>(</strong>Key<strong>,</strong> <span style="color: #e00000">1</span><strong>,</strong> <span style="color: #e00000">8</span><strong>),</strong> Seed<strong>)</strong> <strong>then
</strong></span><span>    exit<strong>;</strong></span><span> </span></pre>
<pre><span>  <span style="color: blue">{$IFDEF KEY00}
</span></span><span>  kb <strong>:=</strong> Copy<strong>(</strong>Key<strong>,</strong> <span style="color: #e00000">9</span><strong>,</strong> <span style="color: #e00000">2</span><strong>);
</strong></span><span>  b <strong>:=</strong> PKV_GetKeyByte<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">24</span><strong>,</strong> <span style="color: #e00000">3</span><strong>,</strong> <span style="color: #e00000">200</span><strong>);
</strong></span><span>  <strong>if</strong> kb <strong>&lt;&gt;</strong> IntToHex<strong>(</strong>b<strong>,</strong> <span style="color: #e00000">2</span><strong>)</strong> <strong>then
</strong></span><span>    exit<strong>;
</strong></span><span>  <span style="color: blue">{$ENDIF}</span></span></pre>
<pre><span>  <span style="color: blue">{$IFDEF KEY01}
</span></span><span>  kb <strong>:=</strong> Copy<strong>(</strong>Key<strong>,</strong> <span style="color: #e00000">11</span><strong>,</strong> <span style="color: #e00000">2</span><strong>);
</strong></span><span>  b <strong>:=</strong> PKV_GetKeyByte<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">10</span><strong>,</strong> <span style="color: #e00000">0</span><strong>,</strong> <span style="color: #e00000">56</span><strong>);
</strong></span><span>  <strong>if</strong> kb <strong>&lt;&gt;</strong> IntToHex<strong>(</strong>b<strong>,</strong> <span style="color: #e00000">2</span><strong>)</strong> <strong>then
</strong></span><span>    exit<strong>;</strong></span></pre>
<pre><span>  <span style="color: blue">{$ENDIF}</span></span></pre>
<pre><span>  <span style="color: blue">{$IFDEF KEY02}
</span></span><span>  kb <strong>:=</strong> Copy<strong>(</strong>Key<strong>,</strong> <span style="color: #e00000">13</span><strong>,</strong> <span style="color: #e00000">2</span><strong>);
</strong></span><span>  b <strong>:=</strong> PKV_GetKeyByte<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">1</span><strong>,</strong> <span style="color: #e00000">2</span><strong>,</strong> <span style="color: #e00000">91</span><strong>);
</strong></span><span>  <strong>if</strong> kb <strong>&lt;&gt;</strong> IntToHex<strong>(</strong>b<strong>,</strong> <span style="color: #e00000">2</span><strong>)</strong> <strong>then
</strong></span><span>    exit<strong>;
</strong></span><span>  <span style="color: blue">{$ENDIF}</span></span><span> </span></pre>
<pre><span>  <span style="color: blue">{$IFDEF KEY03}
</span></span><span>  kb <strong>:=</strong> Copy<strong>(</strong>Key<strong>,</strong> <span style="color: #e00000">15</span><strong>,</strong> <span style="color: #e00000">2</span><strong>);
</strong></span><span>  b <strong>:=</strong> PKV_GetKeyByte<strong>(</strong>Seed<strong>,</strong> <span style="color: #e00000">7</span><strong>,</strong> <span style="color: #e00000">1</span><strong>,</strong> <span style="color: #e00000">100</span><strong>);
</strong></span><span>  <strong>if</strong> kb <strong>&lt;&gt;</strong> IntToHex<strong>(</strong>b<strong>,</strong> <span style="color: #e00000">2</span><strong>)</strong> <strong>then
</strong></span><span>    exit<strong>;
</strong></span><span>  <span style="color: blue">{$ENDIF}</span></span><span> </span></pre>
<pre><span>  <span style="color: blue">// If we get this far, then it means the key is either good, or was made
</span></span><span>  <span style="color: blue">// with a keygen derived from "this" release.</span></span></pre>
<pre><span>  result <strong>:=</strong> KEY_GOOD<strong>;
</strong></span><strong><span>end;</span></strong></pre>
<p><strong>6. Making it harder for crackers</strong></p>
<p>So far you have the tools you need to make a license key system that is virtually impervious to being &#8220;keygenned,&#8221; as far as valid keys go.  It is still possible for a cracker to alter your executable to skip key verification, and a cracker will still be able to create a keygen that works for whatever version of your application he has.  So what else is there to do?</p>
<ol type="A">
<li>The first step I suggest is <em>inlining</em> the PKV_GetKeyByte, PKV_GetChecksum, PKV_CheckKeyChecksum, and PKV_CheckKey functions. Recent versions of Delphi support the <strong>inline</strong> compiler directive that forces the compiler to &#8220;unroll&#8221; the function in-place rather than actually make a function call. This results in larger code, but also gives the cracker that many more places to examine while he is dissecting your executable. It also prevents him from finding the single entry point for PKV_CheckKey and making it always return KEY_GOOD.</li>
<li>When your application tests the stored key at startup, and when the user enters the key, <em>only check the checksum</em>. If your program immediately goes into its &#8220;key byte&#8221; verification code when it starts up or when the key is entered by the user, it&#8217;s just <em>asking</em> the cracker to watch carefully and see how it&#8217;s done!Just verify the checksum first, and give a polite error message if it is invalid (remember, this is where your customer is putting in his key that he gave you money for!). Elsewhere in your code, sprinkle the <em>real</em> checks into various operations.  User clicks File&gt;Save? There&#8217;s a good time to <em>really</em> check the key, instead of just the checksum. Perhaps set up a timer and check it a full minute after the code is entered.  The possibilities are endless, and any unique ideas you come up with will make your program that much more tedious for a cracker to work on.  Crackers have lots of programs to fool around with, and if yours gets to be too frustrating, they may get sloppy and release only a partially working crack, or skip your application altogether.</li>
<li>Keep on top of cracks, phony keygens, and leaked keys. Even though it isn&#8217;t possible for a cracker to create a <em>fully</em> valid key based on what you compiled into your program, he can (and probably will) release a keygen that works with whatever version he downloaded.  Set up a Google Alert for &#8220;Your_program keygen serial crack&#8221; and when one is released, immediately change which &#8220;key bytes&#8221; your program checks, or add the leaked key to the blacklist, and recompile. Suddenly none of the keys, keygens, and cracks released work anymore. Also, do a &#8220;silent&#8221; update of your download file when you are just recompiling for this reason. No need to announce to the cracker that their keygen suddenly doesn&#8217;t work any more.</li>
</ol>
<p><strong>7</strong><strong>. Further development</strong></p>
<p>This PKVS example is very simple in its implementation. There are several things that could be added to make it more powerful.</p>
<ol type="A">
<li>Replace PKV_GetKeyByte with a more robust version. There are many hashing algorithms available that can be used as a starting point for calculating the portions of your key used to determine if it is valid.  Using the sample function presented here would be a mistake as it could be reverse engineered with valid leaked keys and brute-force algorithms.</li>
<li>Instead of using hexidecimal, use the entire alphabet. This will let you pack a lot more data into the key string without making it too long. Note that the comparisons and byte generation checks in this example will have to be re-written to work with any other base numbering system.</li>
<li>The example implementation is a simple &#8220;serial number&#8221; system and does not tie the key to a user name or other information. However, it would be trivial to make the seed itself a checksum value of another string, such as the user&#8217;s name.</li>
<li>Anything could be added to the key string. You could add additional values to store activation or expiration dates, for example.</li>
<li>Your key generation system should maintain a database of issued keys. You should always test your key check function against every key you have issued.  Also, keep a database of blacklisted or leaked keys, and always test your check function against them to ensure it returns the expected results.</li>
</ol>
<p><strong>Concluding remarks</strong></p>
<p>Whatever you do, don&#8217;t focus all of your energy on your licensing system.  It is important, but creating usable software that customers need is more important. A good license key system will certainly improve your sales, but you can&#8217;t hope to convert every one searching for &#8220;MyProgram Serialz&#8221; into a customer.  A system like the one described here can be implemented in a day or two, but constantly trying to outsmart crackers is a never-ending battle.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandonstaggs.com/2007/07/26/implementing-a-partial-serial-number-verification-system-in-delphi/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How to get super rich and never have to work again</title>
		<link>http://www.brandonstaggs.com/2007/07/21/how-to-get-super-rich-and-never-have-to-work-again/</link>
		<comments>http://www.brandonstaggs.com/2007/07/21/how-to-get-super-rich-and-never-have-to-work-again/#comments</comments>
		<pubDate>Sat, 21 Jul 2007 14:56:01 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Software & Technology]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[misv]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.brandonstaggs.com/2007/07/21/how-to-get-super-rich-and-never-have-to-work-again/</guid>
		<description><![CDATA[(Well, not really. Keep in mind that you&#8217;re reading a post by someone who is not rich and works like a dog almost every day.)
Here&#8217;s an interesting book if you&#8217;re curious about how successful technology companies get started: Founders at Work: Stories of Startups&#8217; Early Days by Jessica Livingston.
Founders at Work is a collection of interviews [...]]]></description>
			<content:encoded><![CDATA[<p>(Well, not really. Keep in mind that you&#8217;re reading a post by someone who is not rich and works like a dog almost every day.)</p>
<p>Here&#8217;s an interesting book if you&#8217;re curious about how successful technology companies get started: <em>Founders at Work: Stories of Startups&#8217; Early Days</em> by Jessica Livingston.</p>
<p><em>Founders at Work</em> is a collection of interviews with 32 people who started, or helped start, super-successful companies like Adobe, TiVo, Blogger, Yahoo!, and more. It also includes interviews with people who founded not-very-successful-but-made-the-founders-super-rich companies, like Hotmail and Lycos. (Yes, I know, some people will disagree with me about those companies not being successful. Hotmail has had serious problems, and I think Lycos&#8217; domain name expired yesterday. Just be glad I didn&#8217;t put Apple on that list!)</p>
<p>These types of books always interest me, because I am one of those individualist entrepreneur types. I don&#8217;t ever expect to &#8220;hit it big,&#8221; because my focus is always on narrow niches, but it&#8217;s still fun to read about people who, often enough, created extremely successful businesses without really trying to.</p>
<p>For example, PayPal began as a PDA application and initially told customers they didn&#8217;t want it to be used to pay for auctions. They eventually abandoned the initial goals of PayPal and now everybody uses it to pay for auctions.</p>
<p>Then there are the companies that almost collapse under their own initial success, like Blogger. Prya Labs didn&#8217;t set out to create a new &#8220;sphere&#8221; (as in blogo-), but when it did, had lots of users and no way to make any money off them. They had to lay off practically the entire company and run on fumes until someone with lots of money (Google) came in and made the one guy who stuck around super wealthy.</p>
<p>There are, of course, several companies represented in the book who did exactly what they set out to do. But that&#8217;s boring.</p>
<p>And there&#8217;s the occasional founder who was so wrapped up in what was happening to him that he doesn&#8217;t know what was going on <em>around</em> him: like Steve Wozniak (aka <em>the Woz</em>) who is still convinced that the Apple II set all sorts of records that it didn&#8217;t, and thinks Commodore passed on acquiring Apple when in fact Steve Jobs tried to push Jack Tramiel too hard and lost the chance. But I digress.</p>
<p>I can certainly recommend reading this book. At the very least, you&#8217;ll learn that nobody ever got rich because of a book or blog post they read, and most of the ones who do get rich <em>don&#8217;t</em> stop working after their bank accounts overflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandonstaggs.com/2007/07/21/how-to-get-super-rich-and-never-have-to-work-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Industry Conference 2007 Mini-Review</title>
		<link>http://www.brandonstaggs.com/2007/07/18/software-industry-conference-2007-mini-review/</link>
		<comments>http://www.brandonstaggs.com/2007/07/18/software-industry-conference-2007-mini-review/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 16:13:34 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Software & Technology]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[misv]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.brandonstaggs.com/2007/07/18/software-industry-conference-2007-mini-review/</guid>
		<description><![CDATA[Last week, we packed up the family and drove to Denver for SIC 2007. The Software Industry Conference is an annual conference geared towards independent software developers and vendors.
As usual, there were some very helpful sessions. Dave Collins and Thomas Wetzel convinced me to give Google AdWords yet another try with their insights. There were several sessions [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, we packed up the family and drove to Denver for <a title="Software Industry Conference" href="http://www.sic.org/" target="_blank">SIC</a> 2007. The Software Industry Conference is an annual conference geared towards independent software developers and vendors.</p>
<p>As usual, there were some very helpful sessions. <a href="http://www.davetalks.com/" target="_blank">Dave Collins</a> and <a href="http://www.wisco.de/" target="_blank">Thomas Wetzel</a> convinced me to give Google AdWords yet another try with their insights. There were several sessions about blogging, newsletters, and podcasting as marketing vehicles, with <a href="http://www.47hats.com/wp-trackback.php?p=372" target="_blank">Bob Walsh</a>, Phil Schnyder, and <a href="http://blogs.msdn.com/mglehman/" target="_blank">Michael Lehman</a> making several appearances on these topics. <a href="http://nick.typepad.com/blog/2007/07/really-simple-s.html" target="_blank">Nick Bradbury</a>, author of the excellent TopStyle, had a great presentation on effective user interface design and the difficulties of keeping software simple while still satisfying the needs of power users.</p>
<p><a href="http://blogs.codegear.com/davidi/" target="_blank">David Intersimone</a> of CodeGear had a session on native code development. I have to say I was a bit disappointed that he didn&#8217;t make more of a pitch for using Delphi. He showed off some of Delphi&#8217;s features, but his session seemed to be more of an overview of the development options for Windows, rather than one really driving home the benefits of native code development with Delphi. But it was great to see CodeGear at SIC, because it shows that they understand the importance of reaching out to independent developers rather than just focusing on enterprise customers like Borland has been doing for the last several years. Spending time talking with David was a highlight of the conference for me.</p>
<p>There are plenty of sessions I didn&#8217;t mention simply because there are too many for one person to attend.</p>
<p>SIC isn&#8217;t just about sessions, it&#8217;s also about networking and schmoozing.  It&#8217;s nice to have an opportunity to spend time with people in the same industry, as being an independent software developer often means spending your days behind a computer without &#8220;realspace&#8221; interaction with your colleagues. I had a great time meeting new people, and especially catching up with people I&#8217;ve met at previous conferences.</p>
<p><strong>Industry Awards at SIC</strong></p>
<p>The <a href="http://www.siavoting.com/index.php" target="_blank">Shareware Industry Awards Foundation</a> presents several awards each year at SIC during an awards banquet. Last year, my wife and I attended the banquet and decided that we could save some money by skipping it the next time and eating out at a restaurant instead. So this year, a group of us drove out to Ruth&#8217;s Chris Steakhouse where we enjoyed some good steak and excellent company.</p>
<p>Upon our return, I was informed that I missed my own award presentation! I didn&#8217;t believe it at first, because I assumed Bible Software was too much of a niche market to even put me in the running. But nobody was pulling my leg &#8212; <a title="SwordSearcher Bible Software" href="http://www.swordsearcher.com" target="_blank">SwordSearcher</a> received the <a href="http://www.siavoting.com/pcwinners.php" target="_blank">People&#8217;s Choice Award</a> for the Hobby &amp; Personal Interest category. I was stunned &#8212; I didn&#8217;t ask anyone to vote for me, I didn&#8217;t mention it in a single newsletter. I didn&#8217;t even vote for myself! The People&#8217;s Choice Awards are voted on by thousands of people across the internet on major websites like CNet, Tucows, and PC World. So that was exciting.</p>
<p><img style="width: 150px; height: 182px;" title="SwordSearcher People's Choice Award" src="http://www.swordsearcher.com/pr/SIAF2007-150x182.jpg" alt="SwordSearcher People's Choice Award" hspace="10" vspace="10" width="150" height="182" align="left" />Here&#8217;s a picture of the award. It&#8217;s much heavier than it looks and takes up a good deal of space on a shelf. Always thinking about getting the word out, I promptly wrote a <a href="http://www.swordsearcher.com/pr/070717.html" target="_blank">press release</a> announcing the award.</p>
<p>A big thank-you to the folks who put on the conference. I hope to be able to attend again next year in Boston.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandonstaggs.com/2007/07/18/software-industry-conference-2007-mini-review/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
