<?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>// do something here &#187; Inspirational code</title>
	<atom:link href="http://www.dosomethinghere.com/category/inspirational-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dosomethinghere.com</link>
	<description>Turning impossibilities into 1s and 0s professionally since 0&#120;07C1</description>
	<lastBuildDate>Thu, 29 Jul 2010 14:46:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Highly useful Objective-C code</title>
		<link>http://www.dosomethinghere.com/2010/07/29/highly-useful-objective-c-code/</link>
		<comments>http://www.dosomethinghere.com/2010/07/29/highly-useful-objective-c-code/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 14:46:02 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=575</guid>
		<description><![CDATA[I just got the inspiration to add the following line of code to the app delegate header of my latest iPhone application:

#define  VERY_YES  YES

If you are wondering about the etymology of this, please check out the following informational message:
Where does the term &#8220;very yes&#8221; originate from?
I leave it to the imagination and creativity [...]]]></description>
			<content:encoded><![CDATA[<p>I just got the inspiration to add the following line of code to the app delegate header of my latest iPhone application:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#define  VERY_YES  YES</span></pre></div></div>

<p>If you are wondering about the etymology of this, please check out the following informational message:</p>
<p><a href="http://www.homestarrunner.com/sbemail118.html" target="_blank">Where does the term &#8220;very yes&#8221; originate from?</a></p>
<p>I leave it to the imagination and creativity of my fellow developers to adapt this code to run in other flavors of C.  Please make sure to credit me if you decide to use it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2010/07/29/highly-useful-objective-c-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Best way to not use an enumeration, ever!</title>
		<link>http://www.dosomethinghere.com/2009/11/10/best-way-to-not-use-an-enumeration-ever/</link>
		<comments>http://www.dosomethinghere.com/2009/11/10/best-way-to-not-use-an-enumeration-ever/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 00:38:46 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[C#.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=379</guid>
		<description><![CDATA[So here is some more interesting stuff found in some code that needed some emergency modifications.
The enumeration of this code starts on line 26 of the class file:

public enum City
&#123;
    CLINTON = 78,
    FRANKLIN = 1,
    FAIRVIEW = 59,
    GREENVILLE = 55,
  [...]]]></description>
			<content:encoded><![CDATA[<p>So here is some more interesting stuff found in some code that needed some emergency modifications.</p>
<p>The enumeration of this code starts on line 26 of the class file:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> City
<span style="color: #000000;">&#123;</span>
    CLINTON <span style="color: #008000;">=</span> <span style="color: #FF0000;">78</span>,
    FRANKLIN <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,
    FAIRVIEW <span style="color: #008000;">=</span> <span style="color: #FF0000;">59</span>,
    GREENVILLE <span style="color: #008000;">=</span> <span style="color: #FF0000;">55</span>,
    SALEM <span style="color: #008000;">=</span> <span style="color: #FF0000;">83</span>,
    MADISON <span style="color: #008000;">=</span> <span style="color: #FF0000;">81</span>,
    SPRINGFIELD <span style="color: #008000;">=</span> <span style="color: #FF0000;">14</span>,
    ARLINGTON <span style="color: #008000;">=</span> <span style="color: #FF0000;">84</span>,
    CLAYTON <span style="color: #008000;">=</span> <span style="color: #FF0000;">63</span>,
    GEORGETOWN <span style="color: #008000;">=</span> <span style="color: #FF0000;">85</span>,
    MARION <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span>,
    OXFORD <span style="color: #008000;">=</span> <span style="color: #FF0000;">65</span>,
    BURLINGTON <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And instead of using the MADISON enumeration, the if statement of this code starts on line 118 of the very same class file:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cityID <span style="color: #008000;">==</span> 0x51<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    actual <span style="color: #008000;">=</span> expected <span style="color: #008000;">-</span> actual<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The names were changed to protect the innocent, thanks to Wikipedia for having an easy to find <a href="http://en.wikipedia.org/wiki/List_of_the_most_common_U.S._place_names" target="_blank">list of common place names</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/11/10/best-way-to-not-use-an-enumeration-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Because you never know how many days could be between Monday and Friday</title>
		<link>http://www.dosomethinghere.com/2009/10/19/because-you-never-know-how-many-days-could-be-between-monday-and-friday/</link>
		<comments>http://www.dosomethinghere.com/2009/10/19/because-you-never-know-how-many-days-could-be-between-monday-and-friday/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 15:30:14 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[C#.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=350</guid>
		<description><![CDATA[Why do a couple of subtractions when two loops can do the same work?

while &#40;processDate.DayOfWeek != DayOfWeek.Monday&#41;
    processDate = processDate.AddDays&#40;-1&#41;;
&#160;
string mondayDate = processDate.ToShortDateString&#40;&#41;;
&#160;
while &#40;processDate.DayOfWeek != DayOfWeek.Friday&#41;
    processDate = processDate.AddDays&#40;1&#41;;
&#160;
string fridayDate = processDate.ToShortDateString&#40;&#41;;

]]></description>
			<content:encoded><![CDATA[<p>Why do a couple of subtractions when two loops can do the same work?</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>processDate.<span style="color: #0000FF;">DayOfWeek</span> <span style="color: #008000;">!=</span> DayOfWeek.<span style="color: #0000FF;">Monday</span><span style="color: #000000;">&#41;</span>
    processDate <span style="color: #008000;">=</span> processDate.<span style="color: #0000FF;">AddDays</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #FF0000;">string</span> mondayDate <span style="color: #008000;">=</span> processDate.<span style="color: #0000FF;">ToShortDateString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>processDate.<span style="color: #0000FF;">DayOfWeek</span> <span style="color: #008000;">!=</span> DayOfWeek.<span style="color: #0000FF;">Friday</span><span style="color: #000000;">&#41;</span>
    processDate <span style="color: #008000;">=</span> processDate.<span style="color: #0000FF;">AddDays</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #FF0000;">string</span> fridayDate <span style="color: #008000;">=</span> processDate.<span style="color: #0000FF;">ToShortDateString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/10/19/because-you-never-know-how-many-days-could-be-between-monday-and-friday/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The illusion&#8230;</title>
		<link>http://www.dosomethinghere.com/2009/09/22/the-illusion/</link>
		<comments>http://www.dosomethinghere.com/2009/09/22/the-illusion/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 02:26:11 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[C#.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=302</guid>
		<description><![CDATA[I have heard it said that the greatest danger is the illusion that all is well. This is sort of pessimistic, and I am not a pessimistic person by nature.
And then I start looking through the code and see something like this:

public Guid AddSomething&#40;Guid id1, Guid id2, bool useAlternateValue&#41;
&#123;
    // stuff removed [...]]]></description>
			<content:encoded><![CDATA[<p>I have heard it said that the greatest danger is the illusion that all is well. This is sort of pessimistic, and I am not a pessimistic person by nature.</p>
<p>And then I start looking through the code and see something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> Guid AddSomething<span style="color: #000000;">&#40;</span>Guid id1, Guid id2, <span style="color: #FF0000;">bool</span> useAlternateValue<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// stuff removed from here</span>
    <span style="color: #008080; font-style: italic;">// including the creation of the obj object, </span>
    <span style="color: #008080; font-style: italic;">// which conains a default and alternate value</span>
&nbsp;
    <span style="color: #FF0000;">string</span> s <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>useAlternateValue <span style="color: #008000;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>obj.<span style="color: #0000FF;">alternateValue</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        s <span style="color: #008000;">=</span> obj.<span style="color: #0000FF;">alternateValue</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>useAlternateValue<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>obj.<span style="color: #0000FF;">defaultValue</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        s <span style="color: #008000;">=</span> obj.<span style="color: #0000FF;">defaultValue</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// more stuff removed from here</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>One of the developers that I work with is confused by my hatred of compounding the not operator with ands, ors, and parentheses in decision statements, and of the use of the null object. This code appears to combine both of these things in a mishmash of non functional code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/09/22/the-illusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Brute force solution to a birthday riddle</title>
		<link>http://www.dosomethinghere.com/2009/08/17/brute-force-solution-to-a-birthday-riddle/</link>
		<comments>http://www.dosomethinghere.com/2009/08/17/brute-force-solution-to-a-birthday-riddle/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 00:37:15 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[C#.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=240</guid>
		<description><![CDATA[At one point a long time ago, one of my college professors asked our class how many people it would take to put in a room before the probability that two of the people had the same birthday was greater than or equal to 50 percent, took guesses from a few of us students, and [...]]]></description>
			<content:encoded><![CDATA[<p>At one point a long time ago, one of my college professors asked our class how many people it would take to put in a room before the probability that two of the people had the same birthday was greater than or equal to 50 percent, took guesses from a few of us students, and then told us the answer was 12. Coming from a professor, this had to be true.</p>
<p>That answer has not sat well with me lo these many years since my drinking days, so sitting here with nothing else to do, I decided to try a little Monte Carlo problem solving.</p>
<p>Here is my VS 2008 C# console application code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Birthdays
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">class</span> Program
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">int</span> numberOfRuns<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> numberOfPeople<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">static</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span> birthdays<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">static</span> Random rand<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">int</span> GetABirthday<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">int</span> b<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">int</span> maxDays <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>rand.<span style="color: #0000FF;">Next</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">367</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">366</span><span style="color: #008000;">;</span>
&nbsp;
            b <span style="color: #008000;">=</span> rand.<span style="color: #0000FF;">Next</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>, maxDays<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> b<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            rand <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Birthdays application&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Console.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;How many times would you like to run a birthday search? &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> s <span style="color: #008000;">=</span> Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            numberOfRuns <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            numberOfPeople <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">367</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">367</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                numberOfPeople<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            Boolean leaveLoop<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">int</span> b<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">int</span> leapDayMatches <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">int</span> leapDayBirthdays <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">int</span> totalBirthdays <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> numberOfRuns<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                birthdays <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                leaveLoop <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
                <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>leaveLoop<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    b <span style="color: #008000;">=</span> GetABirthday<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    totalBirthdays<span style="color: #008000;">++;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>b <span style="color: #008000;">==</span> <span style="color: #FF0000;">366</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        leapDayBirthdays<span style="color: #008000;">++;</span>
                    <span style="color: #000000;">&#125;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>birthdays.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>b<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        numberOfPeople<span style="color: #000000;">&#91;</span>birthdays.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">++;</span>
                        leaveLoop <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
                        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>b <span style="color: #008000;">==</span> <span style="color: #FF0000;">366</span><span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            leapDayMatches<span style="color: #008000;">++;</span>
                        <span style="color: #000000;">&#125;</span>
                    <span style="color: #000000;">&#125;</span>
                    <span style="color: #0600FF;">else</span>
                    <span style="color: #000000;">&#123;</span>
                        birthdays.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>b<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Breakdown of number of people required:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">int</span> ctr <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">366</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>numberOfPeople<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    ctr <span style="color: #008000;">+=</span> numberOfPeople<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
                    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0} people: {1} ({2:P})&quot;</span>, i, 
                                        numberOfPeople<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>, ctr <span style="color: #008000;">*</span> <span style="color: #FF0000;">1.0</span> <span style="color: #008000;">/</span> numberOfRuns<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Total birthdays generated: {0}&quot;</span>, 
                                                totalBirthdays<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Leap day birthdays: {0}&quot;</span>, 
                                                leapDayBirthdays<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Leap day matches: {0}&quot;</span>, 
                                                leapDayMatches<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Strike any key to end the program&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">ReadKey</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The answer yielded by the above code is 23, as any meaningful sample size plugged into the program above will demonstrate.</p>
<p>Of course, we did not have the internet back then, but now a quick Google search yields plenty of discussion of the theory and math behind the puzzle. If you are interested, <a href="http://lmgtfy.com/?q=birthday+paradox" target="_blank">click this link</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/08/17/brute-force-solution-to-a-birthday-riddle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Friends don&#8217;t let friends reinvent System.Security.Cryptography</title>
		<link>http://www.dosomethinghere.com/2009/07/19/friends-dont-let-friends-reinvent-system-security-cryptography/</link>
		<comments>http://www.dosomethinghere.com/2009/07/19/friends-dont-let-friends-reinvent-system-security-cryptography/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 14:23:07 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=189</guid>
		<description><![CDATA[A fellow coworker is upgrading one of our long time customer&#8217;s ASP.NET web site that was originally created in 2003, and all is going swimmingly. Alas, this project could not go gently into that good night.
He makes the web page and code changes, modifies the database, pushes all the changes up to the web site, and [...]]]></description>
			<content:encoded><![CDATA[<p>A fellow coworker is upgrading one of our long time customer&#8217;s ASP.NET web site that was originally created in 2003, and all is going swimmingly. Alas, this project could not go gently into that good night.</p>
<p>He makes the web page and code changes, modifies the database, pushes all the changes up to the web site, and the site is working well. Customers are placing orders on the web site, order e-mails are being sent to the site owners with encrypted credit card information, and all are happy.</p>
<p>But there is always a fly in the ointment. All of a sudden, an order is placed on the web site, but when the site owner tries to run a decrypt on the credit card information in the e-mail, the decryption routine is reporting a failure. So naturally, we assume that we broke the code somehow, so we started to dive into the project to see what we did to destabilize it.</p>
<p>He asked for my opinions on this problem, so I came over and we started to go through the VB.NET Framework v2.0 project. While investigating the area of the code containing the exact message that the customer was getting, my blood pressure started to go up right away as we started to see code that looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">If</span> intNumberLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">16</span> <span style="color: #FF8000;">Then</span>
    <span style="color: #008080; font-style: italic;">'go through each of the 16 numbers and</span>
    <span style="color: #008080; font-style: italic;">'add the code for them into the return string</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">6</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">6</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">8</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">9</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">10</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">11</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">11</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">12</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">13</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">13</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">14</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">14</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">15</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
    intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">15</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Mid</span><span style="color: #000000;">&#40;</span>strNumber, <span style="color: #FF0000;">16</span>, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">Integer</span><span style="color: #000000;">&#41;</span>
&nbsp;
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char1<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char2<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char3<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char4<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char5<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char6<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">6</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char7<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">6</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char8<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char9<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char10<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char11<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">11</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char12<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">11</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char13<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">13</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char14<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">13</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">14</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char15<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">14</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
    strCharCodes<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">15</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> encrypt_Char16<span style="color: #000000;">&#40;</span>intNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">15</span><span style="color: #000000;">&#41;</span>, intIndexCode<span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">'strReturnValue = strCharCodes.ToString</span>
<span style="color: #FF8000;">ElseIf</span> intNumberLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span> <span style="color: #FF8000;">Then</span>
    <span style="color: #008080; font-style: italic;">' you get the idea</span></pre></div></div>

<p>And this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'first char</span>
<span style="color: #0600FF;">Select</span> <span style="color: #0600FF;">Case</span> <span style="color: #0600FF;">Left</span><span style="color: #000000;">&#40;</span>strEncodeCard, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>    <span style="color: #008080; font-style: italic;">' these character constants were originally all different</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;0&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>    <span style="color: #008080; font-style: italic;">' I have masked them out for this blog posting</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;1&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;2&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;3&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;4&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;5&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;6&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;7&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;8&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #808080;">&quot;X&quot;</span>
        strCardNumber<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;9&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF8000;">Else</span>
        blnSuccess <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Select</span></pre></div></div>

<p>(The above code was repeated 32 times, once for each digit of a potential 16 digit credit card number, and there were two sets of these that were switched if the digit position was odd or even. There was definitely some thought put into this. I&#8217;m not saying it was good thought, just thought. Perhaps they were paid by the lines of code written?)</p>
<p>OK, I have done things like this from time to time, usually not to this extent, but the original designers and coders of this project at least had the good sense to encrypt the credit card information that was being e-mailed, so maybe it will get better.</p>
<p>Yeah, I was wrong about that, I should remember a tenet of code maintenance that I learned a long time ago: TWGW. (This stands for Things Will Get Worse.) As we stepped through the order that was confusing the system, we came upon this nugget.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'second, select the expiration year code</span>
<span style="color: #0600FF;">Select</span> <span style="color: #0600FF;">Case</span> intExpYear
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2003</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>    <span style="color: #008080; font-style: italic;">' these character constants were originally all different</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2004</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>    <span style="color: #008080; font-style: italic;">' I have masked them out for this blog posting</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2005</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2006</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2007</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2008</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2009</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2010</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2011</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
    <span style="color: #0600FF;">Case</span> <span style="color: #FF0000;">2012</span>
        cryptoExp_Year <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;X&quot;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Select</span></pre></div></div>

<p>Of course, the customer had a credit card that expired in 2013, and as such, no character was begin inserted into the encrypted string for the expiration year, and that was causing the problem.</p>
<p>I don&#8217;t even know where to begin, except to say that eventually this code was going to break, and that was the day. (System.Security.Cryptography was in .NET Framework v1.1, so they can&#8217;t use that as an excuse.) So the moral of the story is, if you are going to reinvent a Microsoft namespace, at least make it work more than six years.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/07/19/friends-dont-let-friends-reinvent-system-security-cryptography/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A whole year of more randomer-ness</title>
		<link>http://www.dosomethinghere.com/2009/06/02/a-whole-year-of-more-randomer-ness/</link>
		<comments>http://www.dosomethinghere.com/2009/06/02/a-whole-year-of-more-randomer-ness/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 18:55:19 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[Team building]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=87</guid>
		<description><![CDATA[Today is the 1 year anniversary of a snippet of our company&#8217;s code being featured on The Daily WTF web site.  Here is a direct link to the article so you too can bask in the goodness of real randomicity:
More Randomer
So I bought cupcakes for our dev team and decided to hack one of the [...]]]></description>
			<content:encoded><![CDATA[<p>Today is the 1 year anniversary of a snippet of our company&#8217;s code being featured on <a href="http://thedailywtf.com/" target="_blank">The Daily WTF</a> web site.  Here is a direct link to the article so you too can bask in the goodness of real randomicity:</p>
<p><a href="http://thedailywtf.com/Articles/More-Randomer.aspx" target="_blank">More Randomer</a></p>
<p>So I bought cupcakes for our dev team and decided to hack one of the cupcakes:</p>
<p><img class="alignnone size-full wp-image-88" title="More Randomer's First Birthday" src="http://www.dosomethinghere.com/wp-content/uploads/2009/06/more_randomer_1st_birthday.jpg" alt="More Randomer's First Birthday" width="320" height="372" /></p>
<p>By the way, the developer that created the code in question is no longer at the company.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/06/02/a-whole-year-of-more-randomer-ness/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>If at first you don&#8217;t succeed, try try (catch catch) again</title>
		<link>http://www.dosomethinghere.com/2009/05/13/if-at-first-you-dont-succeed-try-try-catch-catch-again/</link>
		<comments>http://www.dosomethinghere.com/2009/05/13/if-at-first-you-dont-succeed-try-try-catch-catch-again/#comments</comments>
		<pubDate>Thu, 14 May 2009 02:18:17 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Inspirational code]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=66</guid>
		<description><![CDATA[So I am cruising through the ASP.NET C# MVP web project we are working on, and happened upon this method (again, the names were changed to protect the not so innocent):

private void mView_LoadObjects&#40;object sender, EventArgs e&#41;
&#123;
    try
    &#123;
        try
    [...]]]></description>
			<content:encoded><![CDATA[<p>So I am cruising through the ASP.NET C# MVP web project we are working on, and happened upon this method (again, the names were changed to protect the not so innocent):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> mView_LoadObjects<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">try</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">try</span>
        <span style="color: #000000;">&#123;</span>
            BusinessLayer.<span style="color: #0000FF;">Class1</span> bizClass <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BusinessLayer.<span style="color: #0000FF;">Class1</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            mView.<span style="color: #0000FF;">objects</span> <span style="color: #008000;">=</span> bizClass.<span style="color: #0000FF;">GetObjects</span><span style="color: #000000;">&#40;</span>mView.<span style="color: #0000FF;">ID1</span>, mView.<span style="color: #0000FF;">ID2</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            throw<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        throw<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>However, the fun didn&#8217;t stop there.  A little further down the class, I found this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> mView_LoadOtherObjects<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">try</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Debug</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        throw<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I am thinking that the catch block on this second example was not hit very often.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/05/13/if-at-first-you-dont-succeed-try-try-catch-catch-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Brought to you by The Department Of Unnecessary Code</title>
		<link>http://www.dosomethinghere.com/2009/05/02/brought-to-you-by-the-department-of-unnecessary-code/</link>
		<comments>http://www.dosomethinghere.com/2009/05/02/brought-to-you-by-the-department-of-unnecessary-code/#comments</comments>
		<pubDate>Sat, 02 May 2009 19:49:52 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Inspirational code]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=44</guid>
		<description><![CDATA[Another nicety that I happened upon, this time from the C# realm. The names were changed to protect the innocent.

theClass.uniqueID = &#40;id != null&#41; ? id : null;

Looks like someone just figured out how to use the ternary operator and was determined to use it.
]]></description>
			<content:encoded><![CDATA[<p>Another nicety that I happened upon, this time from the C# realm. The names were changed to protect the innocent.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">theClass.<span style="color: #0000FF;">uniqueID</span> <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>id <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">?</span> id <span style="color: #008000;">:</span> null<span style="color: #008000;">;</span></pre></div></div>

<p>Looks like someone just figured out how to use the ternary operator and was determined to use it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/05/02/brought-to-you-by-the-department-of-unnecessary-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yet another software development blog</title>
		<link>http://www.dosomethinghere.com/2009/04/27/yet-another-software-development-blog/</link>
		<comments>http://www.dosomethinghere.com/2009/04/27/yet-another-software-development-blog/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 00:49:59 +0000</pubDate>
		<dc:creator>BP</dc:creator>
				<category><![CDATA[Inspirational code]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.dosomethinghere.com/?p=3</guid>
		<description><![CDATA[One thing that the internet doesn&#8217;t really need is a zillion and one software development blogs, one zillion software development blogs is just the right number.
However, I stumbled upon this Visual Basic .NET nugget at work one day and just couldn&#8217;t resist&#8230;

Private Function getCustomers&#40;&#41; As Array
&#160;
    'do something here
&#160;
End Function

This blog is [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that the internet doesn&#8217;t really need is a zillion and one software development blogs, one zillion software development blogs is just the right number.</p>
<p>However, I stumbled upon this Visual Basic .NET nugget at work one day and just couldn&#8217;t resist&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Function</span> getCustomers<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #0600FF;">Array</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">'do something here</span>
&nbsp;
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></pre></div></div>

<p>This blog is in honor of my discovery. Please stay tuned for lots more nuggets o&#8217; gold, random thoughts, and sometimes maybe even problems I have run across and how they were solved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dosomethinghere.com/2009/04/27/yet-another-software-development-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
