<?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>Kris Bailey</title>
	<atom:link href="http://www.krisbailey.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.krisbailey.com</link>
	<description>Useful code that sometimes get invaded by my life.</description>
	<lastBuildDate>Thu, 19 Feb 2009 13:32:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WPThemesFree.com &#8211; Decoding the footers</title>
		<link>http://www.krisbailey.com/2009/02/wpthemesfreecom-decoding-the-footers/</link>
		<comments>http://www.krisbailey.com/2009/02/wpthemesfreecom-decoding-the-footers/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 12:55:22 +0000</pubDate>
		<dc:creator>Kris Bailey</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[WordPress Themes]]></category>

		<guid isPermaLink="false">http://www.krisbailey.com/?p=190</guid>
		<description><![CDATA[Recently a friend asked for help setting up a website.  When this happens I normally just throw a few minutes of time in to help set up a WordPress site and install a theme.  I do a few minutes of customization to the theme to make it fit what they want and then [...]]]></description>
			<content:encoded><![CDATA[<p>Recently a friend asked for help setting up a website.  When this happens I normally just throw a few minutes of time in to help set up a WordPress site and install a theme.  I do a few minutes of customization to the theme to make it fit what they want and then go on my merry way.</p>
<p>This time the person decided they wanted <a href="http://test.wpthemesfree.com/?preview_theme=rainbow-trance-10" target="_blank">this theme</a> from wpthemesfree.com.  It looks nice, I like color, and it fit what she was doing well enough.  So, I downloaded the theme and installed it for her.  I started to do my customizations ... changing some wording here and there to make it sound more business like instead of personal.  She was doing the site for a business after all.  Thats where the I ran into an issue...<br />
<span id="more-190"></span></p>
<p>Everything was going fine until I tried to remove the placeholder ad image in the right sidebar.  It turns out that WPThemesFree.com encodes the footers of all of their themes (or at least all that I checked) so you can't edit them.  I guess this is to keep advertising links inserted by the theme authors from being removed or something.  Regardless of the reason, the theme was useless to my friend if they couldn't change the "blogroll" wording and take out the example ad space, so I needed to do something.</p>
<p>The content of the encoded files looks like this:</p>
<pre class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/eval"><span style="color: #000066;">eval</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/gzinflate"><span style="color: #000066;">gzinflate</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/base64_decode"><span style="color: #000066;">base64_decode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'NdI3kptQAADQfk/hzrtDAR8JBGOPdz5RIHKGxkM</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">(... I cut out a lot of encoded junk here ...)</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">zeDb3rdKHAZf5MKoaBFlvtD7QxrqhHtoLFPrz6+vr18f3/7A//gE='</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">?&gt;</span></div></li></ol></pre>
<p>So, being that I don't like waiting on people I decided I would just decode it myself instead of emailing someone and hoping they decide to notice me sometime later.  I wrote a small program to do the decoding, decoded the file, and made the small alterations I needed.</p>
<p>I thought that my hack to decode this might be useful to other people too so I put up an easy to use web interface for it here:<br />
<a href="/demos/wpthemesfree">http://www.krisbailey.com/demos/wpthemesfree</a></p>
<p>Please keep in mind that the point of this decoder is to allow you to edit things the theme creator designed to be changed, like example ad space, or a sidebar that happens to be in the footer instead of a separate file.  Please don't use it to remove ad links that the theme creators use to pay for their development time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krisbailey.com/2009/02/wpthemesfreecom-decoding-the-footers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating Code 39 Barcodes in Pure Javascript</title>
		<link>http://www.krisbailey.com/2009/01/creating-code-39-barcodes-in-pure-javascript/</link>
		<comments>http://www.krisbailey.com/2009/01/creating-code-39-barcodes-in-pure-javascript/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 22:11:38 +0000</pubDate>
		<dc:creator>Kris Bailey</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krisbailey.com/?p=155</guid>
		<description><![CDATA[There are many different barcode standards and code 39 is one that is easy to use, supported by most scanners, and can encode letters, numbers, spaces, and some punctuation.  For these reasons it makes it a good choice for many different scenarios.
There are a lot of ways you can create barcodes on your own. [...]]]></description>
			<content:encoded><![CDATA[<p>There are many different barcode standards and code 39 is one that is easy to use, supported by most scanners, and can encode letters, numbers, spaces, and some punctuation.  For these reasons it makes it a good choice for many different scenarios.</p>
<p>There are a lot of ways you can create barcodes on your own.  You can get a special font for it.  You can get special software.  You can write server side generation logic in a host of different languages. The server side generators can use a font, or generate it manually.  Continue on to learn how to do it on the fly in javascript.</p>
<p><span id="more-155"></span></p>
<p><script type="text/javascript" src="/demos/javascript/code39.js"></script><br />
Example:</p>
<input type=text name=bcode value="" onkeyup="document.getElementById('barCodeContainer').innerHTML=print_html_code39_barcode(this.value, 30, false, true, 8);"> &lt;-- type here</p>
<div id="barCodeContainer">Type something in the box above.</div>
<hr />
<strong>Images</strong><br />
The the url's for the black and white gif images are pointing to the images on this site, to guarantee that whatever you use this for does not unexpectedly stop working you will want to download the images and put them on your own server.  Here they are:</p>
<p><a href="http://www.krisbailey.com/images/white.gif" target="_blank">White</a><br />
<a href="http://www.krisbailey.com/images/black.gif" target="_blank">Black</a></p>
<p><strong>Code</strong></p>
<pre class="javascript"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> print_html_code39_barcode<span style="color: #66cc66;">&#40;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	content,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	height,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	insertCheckDigit,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	printContent,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	fontPointSize,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	thinBarWidth,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	barWidthRatio<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	content = content.<span style="color: #006600;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>isNaN<span style="color: #66cc66;">&#40;</span>thinBarWidth<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> thinBarWidth = <span style="color: #CC0000;">1</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>isNaN<span style="color: #66cc66;">&#40;</span>barWidthRatio<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> barWidthRatio = <span style="color: #CC0000;">3</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> thin = thinBarWidth;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> thick = thinBarWidth*barWidthRatio;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> last = thick*<span style="color: #CC0000;">0.66</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> whiteImageURL = <span style="color: #3366CC;">'http://www.krisbailey.com/images/white.gif'</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> blackImageURL = <span style="color: #3366CC;">'http://www.krisbailey.com/images/black.gif'</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> thinWhiteBar = <span style="color: #3366CC;">&quot;&lt;img src='&quot;</span>+whiteImageURL+<span style="color: #3366CC;">&quot;' height='&quot;</span>+height+<span style="color: #3366CC;">&quot;' width='&quot;</span>+thin+<span style="color: #3366CC;">&quot;'&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> thinBlackBar = <span style="color: #3366CC;">&quot;&lt;img src='&quot;</span>+blackImageURL+<span style="color: #3366CC;">&quot;' height='&quot;</span>+height+<span style="color: #3366CC;">&quot;' width='&quot;</span>+thin+<span style="color: #3366CC;">&quot;'&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> thickWhiteBar = <span style="color: #3366CC;">&quot;&lt;img src='&quot;</span>+whiteImageURL+<span style="color: #3366CC;">&quot;' height='&quot;</span>+height+<span style="color: #3366CC;">&quot;' width='&quot;</span>+thick+<span style="color: #3366CC;">&quot;'&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> thickBlackBar = <span style="color: #3366CC;">&quot;&lt;img src='&quot;</span>+blackImageURL+<span style="color: #3366CC;">&quot;' height='&quot;</span>+height+<span style="color: #3366CC;">&quot;' width='&quot;</span>+thick+<span style="color: #3366CC;">&quot;'&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> lastBar = <span style="color: #3366CC;">&quot;&lt;img src='&quot;</span>+whiteImageURL+<span style="color: #3366CC;">&quot;' height='&quot;</span>+height+<span style="color: #3366CC;">&quot;' width='&quot;</span>+last+<span style="color: #3366CC;">&quot;'&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// this is the definition array for what bar</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// combinations correspond to what characters.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// definition is as follows:</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// 0 = thin white (blank) bar</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// 1 = thin black bar</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// 2 = thick white (blank) bar</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// 3 = thick black bar</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// the 10th digit is for calculating the check digit</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// so, the letter A is:</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// [3,0,1,0,1,2,1,0,3,10]</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// which means:</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thick black bar</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thin white</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thin black</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thin white</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thin black</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thick white</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thin black</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thin white</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">//	thick black</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #009900; font-style: italic;">// and the check digit calculation value is 10</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> codes = <span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'0'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'1'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'2'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'3'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">3</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'4'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">4</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'5'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">5</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'6'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">6</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'7'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">7</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'8'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">8</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'9'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">9</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'A'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">10</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #009900; font-style: italic;">// &lt;-- used in the example above</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'B'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">11</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'C'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">12</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'D'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">13</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'E'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">14</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'F'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">15</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'G'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">16</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'H'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">17</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'I'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">18</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'J'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">19</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'K'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">20</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'L'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">21</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'M'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">22</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'N'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">23</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'O'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">24</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'P'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">25</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'Q'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">26</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'R'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">27</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'S'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">28</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'T'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">29</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'U'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">30</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'V'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">31</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'W'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">32</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'X'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">33</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'Y'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">34</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'Z'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">35</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'-'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">36</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'.'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">37</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">' '</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">38</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'*'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">3</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">39</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'$'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">40</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'/'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">41</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'+'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">42</span><span style="color: #66cc66;">&#93;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #3366CC;">'%'</span> : <span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">2</span>,<span style="color: #CC0000;">1</span>,<span style="color: #CC0000;">43</span><span style="color: #66cc66;">&#93;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> tw = <span style="color: #CC0000;">0</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> sum = <span style="color: #CC0000;">0</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> ee=<span style="color: #CC0000;">0</span>; ee&lt;content.<span style="color: #006600;">length</span>; ee++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #003366; font-weight: bold;">var</span> tcodes = codes<span style="color: #66cc66;">&#91;</span>content.<span style="color: #006600;">charAt</span><span style="color: #66cc66;">&#40;</span>ee<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> tcodes!=<span style="color: #3366CC;">'undefined'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			sum += tcodes<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">9</span><span style="color: #66cc66;">&#93;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>insertCheckDigit<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #003366; font-weight: bold;">var</span> checksum = sum%<span style="color: #CC0000;">43</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span>x <span style="color: #000066; font-weight: bold;">in</span> codes<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>codes<span style="color: #66cc66;">&#91;</span>x<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">9</span><span style="color: #66cc66;">&#93;</span>==checksum<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				content = content+x;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	content = <span style="color: #3366CC;">'*'</span>+content+<span style="color: #3366CC;">'*'</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #003366; font-weight: bold;">var</span> htmlout = <span style="color: #3366CC;">&quot;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;table border='0' cellpadding='1' cellspacing='1'&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	htmlout += <span style="color: #3366CC;">&quot;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;tr&gt;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;td align='center'&gt;&lt;nobr&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i=<span style="color: #CC0000;">0</span>; i&lt;content.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		tcodes = codes<span style="color: #66cc66;">&#91;</span>content.<span style="color: #006600;">charAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> tcodes!=<span style="color: #3366CC;">'undefined'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> xi=<span style="color: #CC0000;">0</span>; xi&lt;<span style="color: #CC0000;">9</span>; xi++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #66cc66;">&#40;</span>tcodes<span style="color: #66cc66;">&#91;</span>xi<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">0</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">						htmlout += thinWhiteBar;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					<span style="color: #000066; font-weight: bold;">break</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">1</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">						htmlout += thinBlackBar;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					<span style="color: #000066; font-weight: bold;">break</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">2</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">						htmlout += thickWhiteBar;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					<span style="color: #000066; font-weight: bold;">break</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">3</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">						htmlout += thickBlackBar;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">					<span style="color: #000066; font-weight: bold;">break</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		htmlout += lastBar;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	htmlout += <span style="color: #3366CC;">&quot;&lt;/nobr&gt;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;/td&gt;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;/tr&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>printContent<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		htmlout += <span style="color: #3366CC;">&quot;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;tr&gt;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;td align='center' style='font-size: &quot;</span>+fontPointSize+<span style="color: #3366CC;">&quot;pt;'&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		htmlout += <span style="color: #3366CC;">&quot;&lt;nobr&gt;&quot;</span>+content+<span style="color: #3366CC;">&quot;&lt;/nobr&gt;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;/td&gt;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;/tr&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	htmlout += <span style="color: #3366CC;">&quot;&lt;&quot;</span>+<span style="color: #3366CC;">&quot;/table&gt;&quot;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #000066; font-weight: bold;">return</span> htmlout;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div></li></ol></pre>
<p><strong>Arguments</strong></p>
<ul>
<li>content - This is the string you want to have encoded</li>
<li>height - The height in pixels of the barcode</li>
<li>insertCheckDigit - true or false, whether to insert a check digit or not<br /><small>(not needed for most scanners)</small></li>
<li>printContent - true or false, whether or not to print the content string below the barcode</li>
<li>fontPointSize - The size of the font to use if printing the content</li>
<li>thinBarWidth - The width in pixels of thin bars, default is 1</li>
<li>barWidthRatio - The ratio of thin to thick bar widths.  A good value of 2.8-3.0, default is 3</li>
</ul>
<p><strong>Use</strong><br />
Include the javascript function in your page somehow, then you can do something as simple as:</p>
<pre class="javascript"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script type=<span style="color: #3366CC;">&quot;text/javascript&quot;</span>&gt;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #66cc66;">&#40;</span>print_html_code39_barcode<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'this is a barcode'</span>, <span style="color: #CC0000;">30</span>, <span style="color: #003366; font-weight: bold;">false</span>, <span style="color: #003366; font-weight: bold;">true</span>, <span style="color: #CC0000;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/script&gt;</div></li></ol></pre>
<hr />
That would output the following:<br />
<script type="text/javascript">document.write(print_html_code39_barcode('this is a barcode', 30, false, true, 8));</script></p>
<hr />
For the best scanning results make sure you print using a laser printer, or if you are scanning directly from a display, use an LCD instead of a CRT.</p>
<hr />
NOTE: While it is easily possible to do the same thing without the use of images, I chose to use images so I would not have to worry about the interference of CSS styles that might already be associated with DIV or other tags that could have been used instead.  Feel free to convert it to using DIV's instead of images if it suits your purpose.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krisbailey.com/2009/01/creating-code-39-barcodes-in-pure-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Circular Bit Shifting in PHP</title>
		<link>http://www.krisbailey.com/2009/01/circular-bit-shifting-in-php/</link>
		<comments>http://www.krisbailey.com/2009/01/circular-bit-shifting-in-php/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 02:40:28 +0000</pubDate>
		<dc:creator>Kris Bailey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krisbailey.com/?p=122</guid>
		<description><![CDATA[In PHP there is bit shifting to the right and bit shifting to the left, but they just shift bits off of the end of the bytes.  At one point in the past for reasons I don't remember I had the need to have the ability to circularly shift bits instead of just shifting [...]]]></description>
			<content:encoded><![CDATA[<p>In PHP there is bit shifting to the right and bit shifting to the left, but they just shift bits off of the end of the bytes.  At one point in the past for reasons I don't remember I had the need to have the ability to circularly shift bits instead of just shifting them off of a byte.  Continue for the explanation and code... </p>
<p><span id="more-122"></span><br />
Example:<br />
The binary representation of the letter 'Y' is:</p>
<pre class="php"><span style="color: #cc66cc;">01011001</span></pre>
<p>&nbsp;<br />
If you shift that 1 bit to the right then you end up with:</p>
<pre class="php"><span style="color: #cc66cc;">00101100</span></pre>
<p>&nbsp;<br />
which is the binary representation of a comma (",").  So, if instead of bit shifting one to the right, you circularly bit shifted one bit to the right, you would end up with:</p>
<pre class="php"><span style="color: #cc66cc;">10101100</span></pre>
<p>&nbsp;<br />
which is not a displayable character, and has a hex value of 0xAC.  Understand the difference?</p>
<p>So I have written a function that does circular bit shifting in PHP.  Circular bit shifting on a single byte is relatively easy and nothing special, but this function will also do circular bit shifting on a string of bytes as a whole.  So if you passed it the string 'YZ' which has a binary representation of:</p>
<pre class="php"><span style="color: #cc66cc;">01011001</span> <span style="color: #cc66cc;">01011010</span></pre>
<p>&nbsp;<br />
And told it to shift it 4 bits to the right, then it would return a string with the binary representation of:</p>
<pre class="php"><span style="color: #cc66cc;">10100101</span> <span style="color: #cc66cc;">10010101</span></pre>
<p>&nbsp;</p>
<p>Here is the function:</p>
<pre class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">function</span> circularBitShift<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span>, <span style="color: #0000ff;">$hm</span>, <span style="color: #0000ff;">$direction</span>=<span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #0000ff;">$ret</span> = <span style="color: #ff0000;">''</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #0000ff;">$ords</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #0000ff;">$hm</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$hm</span>%<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #0000ff;">$xhm</span> = <span style="color: #cc66cc;">8</span>-<span style="color: #0000ff;">$hm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">&#41;</span>==<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #0000ff;">$x</span> = <a href="http://www.php.net/ord"><span style="color: #000066;">ord</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$direction</span>==<span style="color: #ff0000;">&quot;r&quot;</span>?<a href="http://www.php.net/chr"><span style="color: #000066;">chr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span>&gt;&gt;<span style="color: #0000ff;">$hm</span>|<span style="color: #0000ff;">$x</span>&lt;&lt;<span style="color: #0000ff;">$xhm</span><span style="color: #66cc66;">&#41;</span>:<a href="http://www.php.net/chr"><span style="color: #000066;">chr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span>&lt;&lt;<span style="color: #0000ff;">$hm</span>|<span style="color: #0000ff;">$x</span>&gt;&gt;<span style="color: #0000ff;">$xhm</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">&#41;</span>==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">''</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span>=<span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span>&lt;strlen<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #0000ff;">$i</span>++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #0000ff;">$ords</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <a href="http://www.php.net/ord"><span style="color: #000066;">ord</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$direction</span>==<span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ords</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$i</span>=&gt;<span style="color: #0000ff;">$c</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span>==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$orwith</span> = <span style="color: #0000ff;">$ords</span><span style="color: #66cc66;">&#91;</span><a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ords</span><span style="color: #66cc66;">&#41;</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#93;</span>&lt;&lt;<span style="color: #0000ff;">$xhm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$c</span> = <span style="color: #0000ff;">$c</span>&gt;&gt;<span style="color: #0000ff;">$hm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$ret</span> .= <a href="http://www.php.net/chr"><span style="color: #000066;">chr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$orwith</span>|<span style="color: #0000ff;">$c</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$orwith</span> = <span style="color: #0000ff;">$ords</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#93;</span>&lt;&lt;<span style="color: #0000ff;">$xhm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$c</span> = <span style="color: #0000ff;">$c</span>&gt;&gt;<span style="color: #0000ff;">$hm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$ret</span> .= <a href="http://www.php.net/chr"><span style="color: #000066;">chr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$orwith</span>|<span style="color: #0000ff;">$c</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ords</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$i</span>=&gt;<span style="color: #0000ff;">$c</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span>==<a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ords</span><span style="color: #66cc66;">&#41;</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$orwith</span> = <span style="color: #0000ff;">$ords</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>&gt;&gt;<span style="color: #0000ff;">$xhm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$c</span> = <span style="color: #0000ff;">$c</span>&lt;&lt;<span style="color: #0000ff;">$hm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$ret</span> .= <a href="http://www.php.net/chr"><span style="color: #000066;">chr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$orwith</span>|<span style="color: #0000ff;">$c</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$orwith</span> = <span style="color: #0000ff;">$ords</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#93;</span>&gt;&gt;<span style="color: #0000ff;">$xhm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$c</span> = <span style="color: #0000ff;">$c</span>&lt;&lt;<span style="color: #0000ff;">$hm</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">				<span style="color: #0000ff;">$ret</span> .= <a href="http://www.php.net/chr"><span style="color: #000066;">chr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$orwith</span>|<span style="color: #0000ff;">$c</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">			<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">		<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$ret</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div></li></ol></pre>
<p>The use is circularBitShift(STRING, HOWMANYTOSHIFT, DIRECTION).  DIRECTION can be "l" or "r" and HOWMANYTOSHIFT can be anything between 0 and 8 exclusively.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krisbailey.com/2009/01/circular-bit-shifting-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP States Array</title>
		<link>http://www.krisbailey.com/2009/01/php-states-array/</link>
		<comments>http://www.krisbailey.com/2009/01/php-states-array/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 22:06:41 +0000</pubDate>
		<dc:creator>Kris Bailey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krisbailey.com/?p=111</guid>
		<description><![CDATA[Today a co-worker of mind asked me if I had an array of states handy so he didn't have to go create one.  I did, and gave it to him, and thought that maybe someone else could benefit from it.  So, continue on to get a copy/paste PHP array of states.

$statesFull = array&#40; [...]]]></description>
			<content:encoded><![CDATA[<p>Today a co-worker of mind asked me if I had an array of states handy so he didn't have to go create one.  I did, and gave it to him, and thought that maybe someone else could benefit from it.  So, continue on to get a copy/paste PHP array of states.<br />
<span id="more-111"></span></p>
<pre class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$statesFull</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;AL&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Alabama&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;AK&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Alaska&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;AZ&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Arizona&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;AR&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Arkansas&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;CA&quot;</span> =&gt; <span style="color: #ff0000;">&quot;California&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;CO&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Colorado&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;CT&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Connecticut&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;DE&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Delaware&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;DC&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Washington DC&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;FL&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Florida&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;GA&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Georgia&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;HI&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Hawaii&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;ID&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Idaho&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;IL&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Illinois&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;IN&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Indiana&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;IA&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Iowa&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;KS&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Kansas&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;KY&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Kentucky&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;LA&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Louisiana&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;ME&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Maine&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;MD&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Maryland&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;MA&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Massachusetts&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;MI&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Michigan&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;MN&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Minnesota&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;MS&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Mississippi&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;MO&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Missouri&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;MT&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Montana&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;NE&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Nebraska&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;NV&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Nevada&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;NH&quot;</span> =&gt; <span style="color: #ff0000;">&quot;New Hampshire&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;NJ&quot;</span> =&gt; <span style="color: #ff0000;">&quot;New Jersey&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;NM&quot;</span> =&gt; <span style="color: #ff0000;">&quot;New Mexico&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;NY&quot;</span> =&gt; <span style="color: #ff0000;">&quot;New York&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;NC&quot;</span> =&gt; <span style="color: #ff0000;">&quot;North Carolina&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;ND&quot;</span> =&gt; <span style="color: #ff0000;">&quot;North Dakota&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;OH&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Ohio&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;OK&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Oklahoma&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;OR&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Oregon&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;PA&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Pennsylvania&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;RI&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Rhode Island&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;SC&quot;</span> =&gt; <span style="color: #ff0000;">&quot;South Carolina&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;SD&quot;</span> =&gt; <span style="color: #ff0000;">&quot;South Dakota&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;TN&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Tennessee&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;TX&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Texas&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;UT&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Utah&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;VT&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Vermont&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;VA&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Virginia&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;WA&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Washington&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;WV&quot;</span> =&gt; <span style="color: #ff0000;">&quot;West Virginia&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;WI&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Wisconsin&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff0000;">&quot;WY&quot;</span> =&gt; <span style="color: #ff0000;">&quot;Wyoming&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$statesShort</span> = <a href="http://www.php.net/array_keys"><span style="color: #000066;">array_keys</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$statesFull</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$statesLong</span> = <a href="http://www.php.net/array_values"><span style="color: #000066;">array_values</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$statesFull</span><span style="color: #66cc66;">&#41;</span>;</div></li></ol></pre>
<p>There ya go <img src='http://www.krisbailey.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>As a side note, I have noticed that search engines like it more when you make pulldown menus for state choices that have the display value of each state in the form of "KY - Kentucky", regardless of what the option value is.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krisbailey.com/2009/01/php-states-array/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Manually Parsing an x509 Certificate in PHP</title>
		<link>http://www.krisbailey.com/2009/01/manually-parsing-an-x509-certificate-in-php/</link>
		<comments>http://www.krisbailey.com/2009/01/manually-parsing-an-x509-certificate-in-php/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 04:08:23 +0000</pubDate>
		<dc:creator>Kris Bailey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.krisbailey.com/?p=73</guid>
		<description><![CDATA[One might ask why you would ever need to manually parse an x509 certificate in PHP when there are handy functions like openssl_x509_parse just laying around.  The answer? To verify the certificate's signature.  Why can't you just use openssl_x509_checkpurpose you say?  Well, because there are bugs in certain combinations of PHP and [...]]]></description>
			<content:encoded><![CDATA[<p>One might ask why you would ever need to manually parse an x509 certificate in PHP when there are handy functions like <a href="http://www.php.net/openssl_x509_parse" target="_blank">openssl_x509_parse</a> just laying around.  The answer? To verify the certificate's signature.  Why can't you just use <a href="http://www.php.net/openssl_x509_checkpurpose" target="_blank">openssl_x509_checkpurpose</a> you say?  Well, because there are bugs in certain combinations of PHP and openssl pertaining to this function and the 'any' purpose.  The PHP and openssl that come with centos by default just so happen to have these bugs and I write software that has to run on centos with it's defaults.</p>
<p>If you are brave enough, read on...<br />
<span id="more-73"></span><br />
So now that we are past the why, lets talk about the what.  What is it that I need to do?  I need to parse an x509 certificate and verify that it is signed by a certain certificate authority.  The process of doing this is:</p>
<ol>
<li>base64 decode the certificate</li>
<li><strong>decode the ASN.1 BER formatted data</strong></li>
<li>get the signature element from the decoded data</li>
<li>decrypt the signature element based on the specified algorithm</li>
<li>parse the ASN.1 BER formatted signature data</li>
<li>compare the signature value (hash of the type specified in the certificate) with the hash of the DER encoded certificate data</li>
</ol>
<p>Step number 2 above is what this article is going to deal with.  First things first, if you want a pretty good explaination of ASN.1 and related topics, go here: <a href="http://luca.ntop.org/Teaching/Appunti/asn1.html" target="_blank">http://luca.ntop.org/Teaching/Appunti/asn1.html</a>.  One thing to note is that my class for parsing only really deals with universal types.  I had no need to write code to deal with application, private, or context specific types.</p>
<p>So we need to know what we have and what we want.  We have a string of bytes, we want a PHP array that represents what is stored in those bytes.  Yes, I said array, not object.  I chose to have the output of my parsing engine be an array for simplicity.  For my purposes there is no reason to represent the output as a complicated structure of objects and nested objects, a simple array will do.</p>
<p>Our string of bytes to parse is of the form "&lt;tag&gt;&lt;length&gt;&lt;data&gt;".  Where:</p>
<ul>
<li>&lt;tag&gt; is a single byte that tells the type of data to expect</li>
<li>&lt;length&gt; is 1 or more bytes that express the length of the data to expect</li>
<li>&lt;data&gt; is the data (didn't see that one coming did you?)</li>
</ul>
<p>There are a multitude of data types but there are really only a few that you need to worry about.  Those are integer, bit string, octet string, null, object identifier, sequence, set, printable string, t61 string, ia5 string, and utc time.</p>
<p>Using this knowledge you can determine that you basically need to read the tag, then read the length, then read the data and process the data, then start over.  The byte that comes after the data is the tag for the next piece of data.  For sequences and sets, the data is just another ASN.1 BER encoded set of items, using these you can create nested structures.</p>
<p>So on to the parsing <img src='http://www.krisbailey.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .  If we were to describe in english what the parsing is going to do, it would be:</p>
<ol>
<li> read the first byte to determine data type</li>
<li>read the second byte to determine LENGTH</li>
<li>if the length byte is greater than 127 then read the next x many bytes where x is determined by the length byte - 128</li>
<li>convert those to an int value and that is your LENGTH</li>
<li>read LENGTH bytes from our string and that is your data</li>
<li>use the type of data to process that data as needed: If the data type is a sequence or set then run our decoding routines on that data and put the return value in place of this data (recursion).</li>
</ol>
<p>There is one really tricky data type that you will run into called an Object Identifier, or OID.  The basic idea is that you have a sequence with 1 or more values where the first value is the OID and the rest are pieces of data pertaining to what the OID represents.  To see a pretty good list of OID's and what they represent, you can go here: <a href="http://www.oid-info.com/search.htm" target="_blank">http://www.oid-info.com/search.htm</a>.</p>
<p>The data that we have is a byte string that we need to change into a dot-notated OID.  An example of a dot-notated OID is "1.2.840.113549.1.1.5" which is the OID for "sha1WithRSAEncryption".  Section 5.9 of <a href="http://luca.ntop.org/Teaching/Appunti/asn1.html" target="_blank">http://luca.ntop.org/Teaching/Appunti/asn1.html</a> has a much better explaination of how to decode OID's than I could ever write so if you want to know more you can go read that. The short description is that the first two pieces of the OID are represented in the first byte, and the rest follow that as one or more bytes each. The first piece = floor(first byte / 40), the second piece = first byte % 40.</p>
<p>As a side note, the signature data in XML documents that use xmlSecurity is an ASN.1 BER encoded string.  I have had need to manually parse and verify the signatures on some XML documents that use xmlSecurity before and I use this parsing code for that as well as for regular x509 cerificate parsing.</p>
<p>So now that I have described what is going to happen, here is how to do it in PHP.  </p>
<ol>
<li>Download my ASN.1 parsing class <a href="/downloads/asn1.tgz" target="_self">from here</a>.<br /><small>(Note that the class also contains functions to DER encode data that produce output that is binary compatible with what openssl produces when doing DER encoding, but that is not what this article is about, save some for another day!)</small></li>
<li>include it in your PHP file somewhere.</li>
<li>insert this code:
<pre class="php"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$cert</span> = <a href="http://www.php.net/file_get_contents"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/path/to/certificate.crt&quot;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$rawCertData</span> = <a href="http://www.php.net/base64_decode"><span style="color: #000066;">base64_decode</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/str_replace"><span style="color: #000066;">str_replace</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color: #ff0000;">&quot;-----BEGIN CERTIFICATE-----&quot;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color: #ff0000;">&quot;-----END CERTIFICATE-----&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">''</span>, <span style="color: #0000ff;">$cert</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$parsedCert</span> = ASN1::<span style="color: #006600;">parseASNString</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rawCertData</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$parsedCert</span><span style="color: #66cc66;">&#41;</span>;</div></li></ol></pre>
</li>
</ol>
<p>If you run this and put a valid path to a certificate then you will get a large array printed on the screen.  The output is of the format:</p>
<p>array([data type], [data])</p>
<p>Where the data can be an array of nested data, where each item can also have nested data.  This can go on infinitly of course.  If you do not want to build this class into a system that you have already, there is an example file included in the archive named test.php that you can just run to see the output.  It uses GEO Trust's root certificate as the input.</p>
<p>To see that demo go here: <a href="http://krisbailey.com/demos/asn1/test.php" target="_blank">http://krisbailey.com/demos/asn1/test.php</a></p>
<p>Any questions? Corrections?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krisbailey.com/2009/01/manually-parsing-an-x509-certificate-in-php/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>XD Triggers 1.0 Beta</title>
		<link>http://www.krisbailey.com/2009/01/xd-triggers-10-beta/</link>
		<comments>http://www.krisbailey.com/2009/01/xd-triggers-10-beta/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 02:29:57 +0000</pubDate>
		<dc:creator>Kris Bailey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://www.krisbailey.com/?p=62</guid>
		<description><![CDATA[Ok, so, I am far from done with putting all of my content on the site but I have some done now.  Love this theme too.  If you are a WordPress nerd then check out XDTriggers  
]]></description>
			<content:encoded><![CDATA[<p>Ok, so, I am far from done with putting all of my content on the site but I have some done now.  Love this theme too.  If you are a WordPress nerd then check out <a href="/wp-plugins/xdtriggers">XDTriggers <img src='http://www.krisbailey.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.krisbailey.com/2009/01/xd-triggers-10-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
