<?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>Not A Number</title>
	<atom:link href="http://notanumber.net/feed" rel="self" type="application/rss+xml" />
	<link>http://notanumber.net</link>
	<description>Programming, Theory, and Math</description>
	<lastBuildDate>Sat, 16 Mar 2013 03:00:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Label your chips.</title>
		<link>http://notanumber.net/archives/83/label-your-chips</link>
		<comments>http://notanumber.net/archives/83/label-your-chips#comments</comments>
		<pubDate>Wed, 20 Feb 2013 08:44:29 +0000</pubDate>
		<dc:creator>John Meacham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://notanumber.net/?p=83</guid>
		<description><![CDATA[It turns out the 6mm (1/4&#8243;) tape for the brother p-touch PT-1230PC computer controlled label maker is just about perfect for labeling PDIP ICs. I whipped up a small program to generate images from the chip pinouts and control the printer in raw mode to create labels. Next step is to put a QR code [...]]]></description>
				<content:encoded><![CDATA[<p>It turns out the 6mm (1/4&#8243;) tape for the brother p-touch PT-1230PC computer controlled label maker is just about perfect for labeling PDIP ICs. I whipped up a small program to generate images from the chip pinouts and control the printer in raw mode to create labels.</p>
<p>Next step is to put a QR code on there that links to the data sheets.</p>
<table style="width: auto;">
<tbody>
<tr>
<td><a href="https://picasaweb.google.com/lh/photo/MltizE2mU2utPn0Nh1b2SNMTjNZETYmyPJy0liipFm0?feat=embedwebsite"><img alt="" src="https://lh5.googleusercontent.com/-zzvUqsokCYY/USSG22ytTEI/AAAAAAAADzk/rC4P6YVYPwc/s640/P1000737.JPG" width="640" height="480" /></a></td>
</tr>
<tr>
<td style="font-family: arial,sans-serif; font-size: 11px; text-align: right;">From <a href="https://picasaweb.google.com/113952010793377772767/MiscProjects?authuser=0&amp;feat=embedwebsite">Misc Projects</a></td>
</tr>
</tbody>
</table>
<p><img alt="74hc595" src="http://repetae.net/dist/74hc595.png" /></p>
<p>A link to the very rough code is here, you will probably have to modify it to suit your situation: <a title="chip png generator" href="http://repetae.net/dist/chip_ptouch.tar.gz">chip_ptouch.tar.gz</a></p>
<h3>UPDATE</h3>
<p>I have updated the tarball above to include printer control code generator to print the pngs in raw mode, more chips, and a README with sample usage.</p>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/83/label-your-chips/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Upgrading my reprap with cheap hall effect sensors.</title>
		<link>http://notanumber.net/archives/66/upgrading-my-reprap-with-cheap-hall-effect-sensors</link>
		<comments>http://notanumber.net/archives/66/upgrading-my-reprap-with-cheap-hall-effect-sensors#comments</comments>
		<pubDate>Wed, 26 Sep 2012 14:26:22 +0000</pubDate>
		<dc:creator>John Meacham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://notanumber.net/?p=66</guid>
		<description><![CDATA[Given how both physical switches and optical sensors have their own issues for using as reprap endstops, I decided to experiment with Hall effect sensors which detect the presence of a magnetic field. The idea being you place a magnet on your carriage, stick the sensor at one end and when the magnet gets close, [...]]]></description>
				<content:encoded><![CDATA[<p>Given how both physical switches and optical sensors have their own issues for using as <a href="http://reprap.org">reprap</a> endstops, I decided to experiment with Hall effect sensors which detect the presence of a magnetic field. The idea being you place a magnet on your carriage, stick the sensor at one end and when the magnet gets close, you get a signal. Very simple and robust, no moving parts, no need for precise placement, just get the magnet at just the right distance and it triggers.</p>
<p>I was able to find <a href="http://www.ebay.com/sch/i.html?_trksid=p5197.m570.l1313&amp;_nkw=a3144">these A3144 hall effect sensors</a> for <strong>19 cents</strong> each. That&#8217;s right, cheaper than switches, cheaper than opto endstops, and superior to both. And there appears to be tons of suppliers for the things, so they are not going away anytime soon. They just have three pins, GND, Vcc, and signal. The signal is normally open collector, get a magnet close and it drains to ground. Now, when trying to figure out how to interface this with the standard RAMPS hardware, I came up with the below circuit.</p>
<table style="width: auto;">
<tbody>
<tr>
<td><a href="https://picasaweb.google.com/lh/photo/gO3XJQL8EWKuuEomDVMBf9MTjNZETYmyPJy0liipFm0?feat=embedwebsite"><img src="https://lh3.googleusercontent.com/-egtUQ_rvEsk/UGL-46O5xWI/AAAAAAAAC0g/RrMbGqKXGk0/s288/P1000680.JPG" alt="" width="288" height="216" /></a></td>
</tr>
<tr>
<td style="font-family: arial,sans-serif; font-size: 11px; text-align: right;">From <a href="https://picasaweb.google.com/113952010793377772767/HallEffect?authuser=0&amp;feat=embedwebsite">Hall Effect</a></td>
</tr>
</tbody>
</table>
<p>That&#8217;s right. The three pins are _exactly_ the same pins, in the same order, that RAMPS expects its endstops to have. The only setup you need is a 3 pin jumper cable you can stick the sensor in. Simple servo cables from <a href="http://pololu.com">pololu</a> or any RC store work perfectly and there is no need to solder anything. When looking at the larger flat side of the sensor, the left leg is the signal so should be oriented towards the outside of the RAMPS board when plugged in.</p>
<p>Here is it next to the large switch and printed holder it is replacing.</p>
<table style="width:auto;">
<tr>
<td><a href="https://picasaweb.google.com/lh/photo/MaFteTIr5ezggiXhWgpeYtMTjNZETYmyPJy0liipFm0?feat=embedwebsite"><img src="https://lh6.googleusercontent.com/-17AtsVmscpY/UGL-52ksjBI/AAAAAAAAC0o/ud9_UUpHsZo/s288/P1000681.JPG" height="216" width="288" /></a></td>
</tr>
<tr>
<td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a href="https://picasaweb.google.com/113952010793377772767/HallEffect?authuser=0&#038;feat=embedwebsite">Hall Effect</a></td>
</tr>
</table>
<p>Just wrap it in electrical tape to insulate its wires.</p>
<table style="width:auto;">
<tr>
<td><a href="https://picasaweb.google.com/lh/photo/WJ2mzZ_z8L_nW7Hy3zG5ptMTjNZETYmyPJy0liipFm0?feat=embedwebsite"><img src="https://lh4.googleusercontent.com/-ev-jKUyrk0U/UGL_KZC86ZI/AAAAAAAAC0w/tucI6Q7OfPQ/s288/P1000683.JPG" height="216" width="288" /></a></td>
</tr>
<tr>
<td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a href="https://picasaweb.google.com/113952010793377772767/HallEffect?authuser=0&#038;feat=embedwebsite">Hall Effect</a></td>
</tr>
</table>
<p>Then attach it to your shaft with one face pointing towards your carriage.  You can then affix the magnet to your carriage however you want, I just let the magnet stick to the motor body itself for the Z axis, but glue, tape, or a bracket would also work. Just whatever you do, make sure both the magnet and sensor are very secure to get repeatability in your measurements. Also, the sensor only detects the magnetic field in one direction, so make sure the proper (north or south) pole is facing the sensor! Just test it before permanently glueing anything. <img src='http://notanumber.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<table style="width:auto;">
<tr>
<td><a href="https://picasaweb.google.com/lh/photo/M3keMFaK8or-KHdGsP1jQtMTjNZETYmyPJy0liipFm0?feat=embedwebsite"><img src="https://lh3.googleusercontent.com/-LwFHtQ-RSzo/UGL_dVdnIHI/AAAAAAAAC1E/ZtEEgyqEErw/s288/P1000684.JPG" height="216" width="288" /></a></td>
</tr>
<tr>
<td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a href="https://picasaweb.google.com/113952010793377772767/HallEffect?authuser=0&#038;feat=embedwebsite">Hall Effect</a></td>
</tr>
</table>
<table style="width:auto;">
<tr>
<td><a href="https://picasaweb.google.com/lh/photo/hfk3ENP2Hi21INKqEliTY9MTjNZETYmyPJy0liipFm0?feat=embedwebsite"><img src="https://lh3.googleusercontent.com/-JGh3aecg78s/UGL_fRdb3EI/AAAAAAAAC1M/u_rUQy1JqhI/s288/P1000685.JPG" height="216" width="288" /></a></td>
</tr>
<tr>
<td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a href="https://picasaweb.google.com/113952010793377772767/HallEffect?authuser=0&#038;feat=embedwebsite">Hall Effect</a></td>
</tr>
</table>
<p>Now, the Hall effect triggers by sinking the signal to ground, so be sure to enable the pull up resistors for your endstops and set the &#8220;INVERT_ENDSTOP&#8221; flag in your firmware.</p>
<p>Since I was playing around with these hall effect sensors, I decided to create a little handheld magnetic field sensor that would allow me to test for the presence and polarity of magnet fields and came up with this handy device.</p>
<table style="width:auto;">
<tr>
<td><a href="https://picasaweb.google.com/lh/photo/qcP6oOPXxEVQa1L2TV7ENdMTjNZETYmyPJy0liipFm0?feat=embedwebsite"><img src="https://lh6.googleusercontent.com/-RphWRANggl8/UGL-oFn_RjI/AAAAAAAAC0M/BWXEDwRmnEI/s288/P1000667.JPG" height="216" width="288" /></a></td>
</tr>
<tr>
<td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a href="https://picasaweb.google.com/113952010793377772767/HallEffect?authuser=0&#038;feat=embedwebsite">Hall Effect</a></td>
</tr>
</table>
<p>While playing around testing various magnets, I re-discovered something interesting, those throw away flexible refrigerator magnets are not actually just a plain magnet, but a repeating pattern of north and south poles that can be read with the sensor.</p>
<p><iframe src="http://www.youtube.com/embed/uVHzWCRpzZ4" frameborder="0" width="560" height="315"></iframe></p>
<p>for 19 cents, this seems like a pretty useful little device. And there should be no reason to use mechanical or optical endstops anymore, these are way cheaper, more reliable and simpler.</p>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/66/upgrading-my-reprap-with-cheap-hall-effect-sensors/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Underhanded C: The Leaky Redaction</title>
		<link>http://notanumber.net/archives/54/underhanded-c-the-leaky-redaction</link>
		<comments>http://notanumber.net/archives/54/underhanded-c-the-leaky-redaction#comments</comments>
		<pubDate>Sat, 21 Nov 2009 00:03:25 +0000</pubDate>
		<dc:creator>John Meacham</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://notanumber.net/?p=54</guid>
		<description><![CDATA[So, it turns out I am the winner of the 2008 Underhanded C Contest. The goal of the contest is to write some straightforward C code to solve a simple task, incorrectly. In particular, you had to introduce a hidden security flaw that would stand up to code review and not stand out at all. [...]]]></description>
				<content:encoded><![CDATA[<p>So, it turns out I am the winner of the <a href="http://underhanded.xcott.com/">2008 Underhanded C Contest</a>. The goal of the contest is to write some straightforward C code to solve a simple task, incorrectly. In particular, you had to introduce a hidden security flaw that would stand up to code review and not stand out at all. This is different than the Obfuscated C contest in that you want your program to look straightforward and that it does one thing, when in fact it does another.</p>
<p>The goal this year was to write a leaky image redaction program. Given an input image in PPM format and a rectangle, it would spit out the image with the rectangle blacked out, perhaps hiding sensitive information. The tricky part was that you had to leak the redacted information. There are more details in the <a href="http://underhanded.xcott.com/?p=8">problem specification</a>.</p>
<p>So, before I go on, here is my complete entry. See if you can figure out how the information is leaked before reading further if you like.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
 * This is a simple redactor, it accepts a plain text ppm file, a set of
 * coordinates defining a rectangle, and produces a ppm file with said
 * rectangle blacked out.
 *
 * Usage: redact in.ppm x y width height &gt; out.ppm
 */</span>
&nbsp;
<span style="color: #993333;">int</span>
main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">!=</span> <span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">fprintf</span><span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;usage: redact in.ppm x y width height &gt; out.ppm<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// process command line arguments</span>
    <span style="color: #993333;">int</span> rx <span style="color: #339933;">=</span> <span style="color: #000066;">atoi</span><span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> ry <span style="color: #339933;">=</span> <span style="color: #000066;">atoi</span><span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> rwidth <span style="color: #339933;">=</span> <span style="color: #000066;">atoi</span><span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> rheight <span style="color: #339933;">=</span> <span style="color: #000066;">atoi</span><span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    FILE <span style="color: #339933;">*</span>ppm <span style="color: #339933;">=</span> <span style="color: #000066;">fopen</span><span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>ppm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">perror</span><span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//read the ppm header</span>
    <span style="color: #993333;">unsigned</span> width<span style="color: #339933;">,</span>height<span style="color: #339933;">,</span>maxdepth<span style="color: #339933;">;</span>
    <span style="color: #000066;">fscanf</span><span style="color: #009900;">&#40;</span>ppm<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;P3<span style="color: #000099; font-weight: bold;">\n</span>%u %u<span style="color: #000099; font-weight: bold;">\n</span>%u<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>width<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>height<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>maxdepth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;P3<span style="color: #000099; font-weight: bold;">\n</span>%u %u<span style="color: #000099; font-weight: bold;">\n</span>%u<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">,</span> height<span style="color: #339933;">,</span> maxdepth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//current locations</span>
    <span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> ws <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//fixed buffer size to avoid overflow</span>
    <span style="color: #993333;">char</span> buf<span style="color: #009900;">&#91;</span>BUFSIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">*</span>c<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">fgets</span><span style="color: #009900;">&#40;</span>buf<span style="color: #339933;">,</span>BUFSIZE<span style="color: #339933;">,</span>ppm<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>c <span style="color: #339933;">=</span> buf<span style="color: #339933;">;*</span>c<span style="color: #339933;">;</span>c<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">isdigit</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>ws<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// new number, increment location.</span>
                    ws <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++;</span>
                    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;=</span> width <span style="color: #339933;">*</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        y<span style="color: #339933;">++;</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;</span> rx <span style="color: #339933;">*</span> <span style="color: #0000dd;">3</span> <span style="color: #339933;">&amp;&amp;</span> x <span style="color: #339933;">&lt;=</span> <span style="color: #009900;">&#40;</span>rx <span style="color: #339933;">+</span> rwidth<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">3</span> <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&gt;</span> ry <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&lt;</span> ry <span style="color: #339933;">+</span> rheight<span style="color: #009900;">&#41;</span>
                    <span style="color: #000066;">putchar</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">else</span>
                    <span style="color: #000066;">putchar</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
               ws <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
               <span style="color: #000066;">putchar</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-54"></span><br />
The trick involves the format of the P3 style PPM file. The format is a plain text format, it has some basic header info, then a list of whitespace separated numbers, such as <code>234 2 0 83 255 255 2 43 255</code> where the numbers represent the magnitude of the red, green, and blue component for each pixel in order. The redactor simply replaced values within the target rectangle with zero. However, due to the way I process the file, character by character, I leak how many digits each value had to begin with. i.e., the above would be redacted to <code>000 0 0 00 000 000 0 00 000</code>. This is completely invisible when viewing the PPM file, all the values count as zero as far as the format is concerned, but by looking at the original file, you can recover some information about what was in the blanked out area. It is particular effective on black on white text, the most common thing needing to be redacted, where each value is 0 0 0 or 255 255 255, allowing perfect reconstruction of the original.</p>
<p>One of my favorite parts of my entry that isn&#8217;t mentioned on the prize page is that it has great plausible deniability as the leak was introduced by properly working around a commonly known and particularly insidious C bug, the improper use of gets and (more subtly) fgets. I can imagine a code review going somewhat like the following:</p>
<blockquote><p>Spook: &#8220;So why did you process the file character by character, rather than doing the more obvious scanf(&#8220;%i %i %i&#8221;,&amp;r,&amp;g,&amp;b) to read in the values?&#8221;</p>
<p>Me: &#8220;Well, in order to do that I&#8217;d have to read in entire lines of the file. Now there is the gets function in C which does that, but has a well known buffer overflow bug if the line length exceeds your buffer size, so I naturally used the safe fgets variant of the function. Of course, with fgets, you can just assume your buffer size is greater than the maximum line length, but that introduces a subtle bug if it isn&#8217;t, you may end up splitting a number across two buffers, so scanf will read something like 234 as the two numbers 23 and 4 if it is split after the second character, hence the need to consider each character independently.&#8221;</p>
<p>Spook: &#8220;Ah, of course. good job at spotting that.&#8221;</p>
<p>Me: *snicker*</p></blockquote>
<p>It is also a great example of the principle that you can&#8217;t protect against intending to write the wrong thing. The code will stand up to any buffer overflow check, code style check, or lint program. The code is correct and proper C code; the bug was not introduced in the code, but much earlier, in my head when I conceived the algorithm. No matter how smart your tools are, if you ultimately intend to write the wrong thing or solve the wrong problem, they can&#8217;t protect against that.</p>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/54/underhanded-c-the-leaky-redaction/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Stepper Motor Driver Test Board for RepRap</title>
		<link>http://notanumber.net/archives/44/stepper-motor-driver-test-board-for-reprap</link>
		<comments>http://notanumber.net/archives/44/stepper-motor-driver-test-board-for-reprap#comments</comments>
		<pubDate>Sat, 23 May 2009 00:36:09 +0000</pubDate>
		<dc:creator>John Meacham</dc:creator>
				<category><![CDATA[reprap]]></category>

		<guid isPermaLink="false">http://notanumber.net/?p=44</guid>
		<description><![CDATA[Recently I have been building the cupcake CNC 3d printer as a stepping stone for getting involved with the reprap project. This was the first time I have tried soldering surface mount components, and I must say it turned out to be quite straightforward and easy using the hotplate reflow method. The main issue was [...]]]></description>
				<content:encoded><![CDATA[<p>Recently I have been building the <a href="http://makerbot.com">cupcake CNC</a> 3d printer as a stepping stone for getting involved with the <a href="http://reprap.org">reprap</a> project. This was the first time I have tried soldering surface mount components, and I must say it turned out to be quite straightforward and easy using the <a href="http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=59">hotplate reflow</a> method. The main issue was actually more psychological than anything, and that is that I wasn&#8217;t able to test the circuits incrementally as I create them. Normally, I alternate placing a few components and testing connections with a multimeter throughout a fabrication, however, with the hot plate reflow method you pretty much have to do all of the surface mount components in one go, and once you start soldering non surface mount components, you can&#8217;t really go back to using the hot plate again.</p>
<p>This issue was somewhat compounded in the design of the cupcake CNCs electronics in that the first testable configuration involved many different components, an ardunio motherboard, a stepper driver, host software running on a PC,  and the various interconnects. Coming up with a way to test the stepper driver boards independently of the rest of the system was quite useful. I whipped up the following simple circuit to test the stepper boards. None of the component values are very important, C1 is a debouncing capacitor for the pushbutton, R1 is a pull down resistor, and R2 is to protect the LED.P1 is a power header that accepts a floppy connector power supply cord from the same PC supply that powers the stepper driver.</p>
<p><img class="alignnone size-full wp-image-47" title="Schematic for Simple Stepper Tester" src="http://notanumber.net/wp-content/uploads/2009/05/stepper_tester_11.png" alt="Schematic for Simple Stepper Tester" width="659" height="447" /></p>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/44/stepper-motor-driver-test-board-for-reprap/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>newtype in C, a touch of strong typing using compound literals.</title>
		<link>http://notanumber.net/archives/33/newtype-in-c-a-touch-of-strong-typing-using-compound-literals</link>
		<comments>http://notanumber.net/archives/33/newtype-in-c-a-touch-of-strong-typing-using-compound-literals#comments</comments>
		<pubDate>Sat, 18 Apr 2009 04:21:47 +0000</pubDate>
		<dc:creator>John Meacham</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c99]]></category>
		<category><![CDATA[types]]></category>

		<guid isPermaLink="false">http://notanumber.net/?p=33</guid>
		<description><![CDATA[The ISO C 99 standard is a great thing. In addition to desperately needed things like a dedicated bool type and codifying a lot of universally implemented extensions to the language, it added some more subtle things such as compound literals. A compound literal allows you to use a C struct or union as an [...]]]></description>
				<content:encoded><![CDATA[<p>The ISO C 99 standard is a great thing. In addition to desperately needed things like a dedicated <strong>bool</strong> type and codifying a lot of universally implemented extensions to the language, it added some more subtle things such as compound literals.  A compound literal allows you to use a C <strong>struct</strong> or <strong>union</strong> as an initialized literal value. This makes declared types more on par with built in ones, such as numbers, characters, and strings. Here I will present just about the simplest but quite useful application of this.</p>
<p>Many modern languages such as Haskell have a concept of a type alias. It is called a <em>newtype</em> in Haskell and I will borrow that terminology here. A <em>newtype</em> is a type that is fully equivalent at run-time and in generated code to an existing type, but nevertheless is distinct to the type system at compile time. They are quite useful in enforcing abstraction of APIs and catching a wide variety of bugs without incurring any run-time penalty. In fact, depending on the compiler, they may actually help optimization. Imagine you represent open files as an index into a table, much as the unix API does, naturally you would represent it by an <strong>int</strong>.  You may have something like this, declaring <strong>fd_t</strong> as a handy synonym to show when you are working with file descriptors.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">typedef</span> <span style="color: #993333;">int</span> fd_t<span style="color: #339933;">;</span>
<span style="color: #808080; font-style: italic;">/* write an int out to a file */</span>
<span style="color: #993333;">void</span> put_int<span style="color: #009900;">&#40;</span>fd_t fd<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now, what happens if someone forgets the order of the arguments to <strong>put_int</strong>? since fd_t is a <em>synonym</em> for int, the compiler has no idea you did anything wrong and happily writes garbage to a random file. Not what we wanted at all. If <strong>fd_t</strong> were a <em>newtype</em> rather than a typedef synonym then the program would be rejected, because <strong>fd_t</strong> and <strong>int</strong> would be distinct types.</p>
<p>This brings us to the following bit of code you can place in a header file <em>newtype.h</em>. Using compound literals, it allows the declaration of newtypes that can be used almost anywhere you can use built in types.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifndef NEWTYPE_H</span>
<span style="color: #339933;">#define NEWTYPE_H</span>
<span style="color: #808080; font-style: italic;">/* this can be used for type safety, to avoid accidental casting of values from one type to another and
 * allowing alias analysis by the compiler to distinguish otherwise identical types
 *
 * NEWTYPE(new_type,old_type); declares new_type to be an alias for the already exsiting old_type
 * TO_NT(new_type,val)  converts a value to its newtype representation
 * FROM_NT(new_val)  opens up a newtyped value to get at its internal representation
 */</span>
&nbsp;
<span style="color: #339933;">#define NEWTYPE(nty,oty) typedef struct { oty v; } nty</span>
<span style="color: #339933;">#define FROM_NT(ntv)       ((ntv).v)</span>
<span style="color: #339933;">#define TO_NT(nty,val)     ((nty){ .v = (val) })</span>
&nbsp;
<span style="color: #339933;">#endif</span></pre></td></tr></table></div>

<p>Now we can modify the above example, instead of</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">typedef</span> <span style="color: #993333;">int</span> fd_t<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>we use</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;">NEWTYPE<span style="color: #009900;">&#40;</span>fd_t<span style="color: #339933;">,</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Another example would be the traditional <strong>lseek</strong> routine that comes with C. it is generally declared as something like</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define SEEK_SET 0</span>
<span style="color: #339933;">#define SEEK_CUR 1</span>
<span style="color: #339933;">#define SEEK_END 2</span>
<span style="color: #993333;">long</span> lseek<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> fd<span style="color: #339933;">,</span><span style="color: #993333;">long</span> offset<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> whence<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now, whence is supposed to be one of the SEEK_* defined terms, and fd is supposed to be an open file descriptor, and offset is supposed to be an offset into the file. however, to the compiler on many architectures <em>all the argument types are indistinguishable</em>. this means that if you mix up any of them, the compiler will happliy go along. in addition, you can pass bogus values in for &#8216;whence&#8217; like 5 or 6, and nothing will complain. using newtypes, you might declare the API like so.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;">NEWTYPE<span style="color: #009900;">&#40;</span>fd_t<span style="color: #339933;">,</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NEWTYPE<span style="color: #009900;">&#40;</span>whence_t<span style="color: #339933;">,</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#define SEEK_SET TO_NT(whence_t,0)</span>
<span style="color: #339933;">#define SEEK_CUR TO_NT(whence_t,1)</span>
<span style="color: #339933;">#define SEEK_END TO_NT(whence_t,2)</span>
<span style="color: #993333;">long</span> lseek<span style="color: #009900;">&#40;</span>fd_t fd<span style="color: #339933;">,</span><span style="color: #993333;">long</span> offset<span style="color: #339933;">,</span> whence_t whence<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now, not only are you protected from mixing up any of the arguments, you are also protected from bogus values being passed into the whence argument meaning you can elide the run-time check for valid values since the compiler will check it for you.</p>
<p>Although this is just the simplest use of compound literals, it is already proving to be quite useful. When combined with other C99 features such as variable length arrarys you can do clever things like non-conservative garbage collection in a clean way, or just make your code that much easier to read by not having to declare temporary structures everywhere.</p>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/33/newtype-in-c-a-touch-of-strong-typing-using-compound-literals/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>On Biometrics and Passwords</title>
		<link>http://notanumber.net/archives/19/on-biometrics-and-passwords</link>
		<comments>http://notanumber.net/archives/19/on-biometrics-and-passwords#comments</comments>
		<pubDate>Thu, 16 Apr 2009 00:41:08 +0000</pubDate>
		<dc:creator>John Meacham</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[biometrics]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[society]]></category>

		<guid isPermaLink="false">http://notanumber.net/?p=19</guid>
		<description><![CDATA[It seems that whenever the topic of biometrics comes up there are some that can&#8217;t stop worrying about what will happen if someone gets ahold of your biometric data. After all, how hard is it to lift a fingerprint off a glass at a pub? Will using fingerprints for authentication mean you have to wear [...]]]></description>
				<content:encoded><![CDATA[<p>It seems that whenever the topic of biometrics comes up there are some that can&#8217;t stop worrying about what will happen if someone gets ahold of your biometric data. After all, how hard is it to lift a fingerprint off a glass at a pub? Will using fingerprints for authentication mean you have to wear gloves everywhere or be subject to identity theft or will you have to burn off your prints and get new ones if someone compromises your fingerprint? Well, The answers are no. The reason for the confusion probably stems from thinking of biometrics as passwords, secret things that only you have. However, this is not the case at all.  The security of biometrics comes from the fact there is only one human that matches the profile, not the secrecy of the profile itself.</p>
<p>A fingerprint cannot be compromised. A biometric identifier is not like a password. it is not meant to be secret. Think of your fingerprint as&#8230; well&#8230; like a public key cryptographic fingerprint really. Your public key fingerprint isn&#8217;t secret. in fact, you generally want to distribute it as far and wide as possible. What makes it useful is that there is a corresponding private key that only you have that can be matched to said public key. A physical fingerprint is similar, everyone knows your fingerprint but there is only one warm human body that is associated with it. Present the warm human body (your own) that matches the fingerprint on file and you gain access. So we have the analogy that a <strong>public key fingerprint</strong> is to a <strong>private key</strong> as a <strong>physical fingerprint</strong> is to a <strong>warm human body with said fingerprint</strong>.</p>
<p>This of course means that biometrics are only good for &#8216;online&#8217; verification, meaning there is a trusted path between your body and whomever you are identifying with. this can be anything from a physically secure ATM, a security guard that applys the test, or whatever is appropriate for the application. The security of biometrics comes not from the secrecy of the fingerprint, but the security of the path from the human being biometrically tested to the verifyer. Hence, you cannot &#8216;compromise a fingerprint&#8217;. You can however compromise a specific biometric system. If you find you can lift and transfer fingerprints easily with a gummy bear for a specific reader, you have broken that particular reader, but you don&#8217;t need to burn off your fingerprints and get new ones (like you change passwords when one has been compromised). you simply stop trusting anything that uses said broken reader.</p>
<p><em>PS. does anyone else enjoy the irony of using an abstract mathematical concept to explain a straightforward real world transaction?</em><em> </em><em> <img src='http://notanumber.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/19/on-biometrics-and-passwords/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ShapeLock and Hot Glue = Rapid Funny Looking Prototypes</title>
		<link>http://notanumber.net/archives/10/shapelock-and-hot-glue-rapid-funny-looking-prototypes</link>
		<comments>http://notanumber.net/archives/10/shapelock-and-hot-glue-rapid-funny-looking-prototypes#comments</comments>
		<pubDate>Mon, 05 May 2008 15:44:13 +0000</pubDate>
		<dc:creator>John Meacham</dc:creator>
				<category><![CDATA[hacks]]></category>
		<category><![CDATA[reprap]]></category>
		<category><![CDATA[shapelock]]></category>

		<guid isPermaLink="false">http://notanumber.net/archives/10</guid>
		<description><![CDATA[While waiting for the parts to my very own reprap machine, I figured I would experiment a little with some possible head designs. One I am particularly interested in is something like a &#8216;pick and place&#8217; machine that can manipulate objects in 3 dimensions. My simple design involves a drinking straw, a couple $3 hobby [...]]]></description>
				<content:encoded><![CDATA[<p>While waiting for the parts to my very own reprap machine, I figured I would experiment a little with some possible head designs. One I am particularly interested in is something like a &#8216;pick and place&#8217; machine that can manipulate objects in 3 dimensions. My simple design involves a drinking straw, a couple $3 hobby servos, a bunch of hand molded shapelock, and a few hot glue burns.</p>
<p>Here is the final result:</p>
<p><a title="pickplace1" href="http://notanumber.net/wp-content/uploads/2008/05/pp1.jpg"><img src="http://notanumber.net/wp-content/uploads/2008/05/pp1.thumbnail.jpg" alt="pickplace1" /></a></p>
<p>The basic idea is the bottom servo (bottom is to the left) can bend the straw left and right, and the other servo can rotate the straw in place. the bend in the straw acts as a universal joint so the object held can be rotated somewhat arbitrarily in 3 dimensions.</p>
<p><a title="pp3.jpg" href="http://notanumber.net/wp-content/uploads/2008/05/pp3.jpg"><img src="http://notanumber.net/wp-content/uploads/2008/05/pp3.thumbnail.jpg" alt="pp3.jpg" /></a></p>
<p>A simple linkage connects the top servo to the straw. I attempted a couple different things, starting with a pully system, then a gear system. neither worked out too well. The linkage turned out to be quite simple and robust.</p>
<p><a title="pp7.jpg" href="http://notanumber.net/wp-content/uploads/2008/05/pp7.jpg"><img src="http://notanumber.net/wp-content/uploads/2008/05/pp7.thumbnail.jpg" alt="pp7.jpg" /></a></p>
<p>Here it is with the attached fan I attempted to use as a vaccum pump. It did not turn out too well, the fan was scavanged from an old CPU and was never meant to be used like this, so I will need an actual vaccum pump at some point.</p>
<p>Everything was controlled for testing with a Wii nunchuck and an arduino microcontroller with custom code. Here is a video of it in action:</p>
<p><a href="http://notanumber.net/archives/10/shapelock-and-hot-glue-rapid-funny-looking-prototypes"><img src="http://img.youtube.com/vi/SGe_1BZErEg/default.jpg" width="130" height="97" border=0></a></p>
<p>So, some stuff I learned</p>
<ul>
<li>ShapeLock is wonderful stuff. I was able to form and reform the head a few times, even fairly large changes like making room for a gear involved reheating a part of the project and shaping it by hand. And I can just melt it down again and reuse it for my next prototype.</li>
<li>The linkage is the way to go. I struggled a long time with gears and pullys. I imagine that if I were precision machining things and could get gears/pullys in the exact right size, things would have been different. But  when it comes to the fuzzy world of hand-squished shapelock, the more forgiving linkage worked out great.</li>
<li>I am  gonna stock up on these tiny and cheap servos. They have a very interesting and useful bug. if you try to overextend them, they go into continuously rotating mode with no modification! So you can have the same servo work as a continously rotating one at some points, but also have precise precisioning at others.</li>
<li>The Wii nunchuck is a great little thing. it took a few dozen lines of arduino code to interface with it and I got a joystick, 3 buttons, and a 3 axis accelerometer.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/10/shapelock-and-hot-glue-rapid-funny-looking-prototypes/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
