<?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>Parallel Interface &#187; Math</title>
	<atom:link href="http://www.paralint.com/blog/category/math/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.paralint.com/blog</link>
	<description>Programming security in Java and C++, one line at a time</description>
	<lastBuildDate>Thu, 26 Aug 2010 17:24:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Attaque mathématique des codes Bixi (vélo libre-service)</title>
		<link>http://www.paralint.com/blog/2009/06/17/attaque-mathematique-des-codes-bixi-velo-libre-service/</link>
		<comments>http://www.paralint.com/blog/2009/06/17/attaque-mathematique-des-codes-bixi-velo-libre-service/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 14:30:12 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[En français]]></category>
		<category><![CDATA[Life (the real one)]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/?p=119</guid>
		<description><![CDATA[J&#8217;étais au centre ville aujourd&#8217;hui et j&#8217;avais affaire pas très loin. Au lieu d&#8217;utiliser le métro, j&#8217;ai loué un Bixi, vélo en libre service. J&#8217;ai été surpris de constater que les codes Bixi ne comporte que 3 chiffres, sur 5 caractères, soit 3^5=243 codes possibles. Ça semble bien peu, mais si les codes ne sont [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;étais au centre ville aujourd&#8217;hui et j&#8217;avais affaire pas très loin. Au lieu d&#8217;utiliser le métro, j&#8217;ai loué un Bixi, vélo en libre service. J&#8217;ai été surpris de constater que les codes Bixi ne comporte que 3 chiffres, sur 5 caractères, soit 3^5=243 codes possibles.</p>
<div id="attachment_120" class="wp-caption aligncenter" style="width: 427px"><img class="size-full wp-image-120" title="bixi21213" src="http://www.paralint.com/blog/wp-content/uploads/2009/06/bixi21213.jpg" alt="Billet bixi portant le code 21213" width="417" height="283" /><p class="wp-caption-text">Billet bixi portant le code 21213</p></div>
<p>Ça semble bien peu, mais si les codes ne sont utilisables qu&#8217;au point de service où ils sont émis, et pour une durée limitée, avec peut-être une détection d&#8217;attaque en force brute, on devrais pouvoir dormir tranquille&#8230;</p>
<p>Je me suis rappellé une attaque mathémaitque sur des codes de ce genre. Avec une location de 24 heures à 5$, on peut prendre et remettre le vélo plusieurs fois, histoire de tester la théorie&#8230; Bonne nouvelle, Bixi n&#8217;est pas vulnérable. Mais j&#8217;écris quand même la démarche, c&#8217;est trop rare qu&#8217;on a l&#8217;occasion d&#8217;utiliser des math pour (tenter de) contourner les règles d&#8217;un système.</p>
<p><span id="more-119"></span>La vulnérabilité apparais lorsque l&#8217;implémentation utilise une fenêtre coulissante pour vérifier les codes entrés. Cette attaque a déjà été utilisée pour <a href="http://everything2.com/index.pl?node_id=1520430">dévérouiller une porte de voiture</a> à combinaison.</p>
<p>Pour les Bixi, les chiffres du codes de dévérouillage de vélo peuvent être 1, 2 ou 3. Le dictionnaire des valeurs possibles à une taille k=3. Il faut entrer 5 chiffres, on dit que n=5. Avec ces variables, une fenêtre coulissante fonctionne comme ceci :</p>
<ol>
<li>On entre n chiffres (par exemple 12222)</li>
<li>Ce ne sera pas le bon code</li>
<li>On entre un chiffre supplémentaire, disons 3</li>
<li>Pour accomoder le chiffre supplémentaire, l&#8217;implémentation décale les chiffres déjà entrés pour faire de la place. Dans notre exemple, c&#8217;est le 1 qui disparaît à gauche à la faveur du 3 à droite.</li>
<li>L&#8217;implémentation vérifie le nouveau code dans la fenêtre, soit 22223.</li>
</ol>
<p>On réussi ainsi à tester 2 codes en ne saisissant que 6 chiffres, au lieu de 10. Et ainsi de suite, à chaque fois qu&#8217;on ajoute un seul chiffre, on se trouve à tester un nouveau code de 5 chiffres. La première étape ne sert qu&#8217;à initialiser le processus, sans affecter la complexité de l&#8217;attaque.</p>
<p>C&#8217;est une vielle idée. Un mathématicien Hollandais, Nicolaas Govert de Bruijn, a formalisé une <a href="http://en.wikipedia.org/wiki/De_Bruijn_sequence">séquence de chiffres</a> dans laquelle n&#8217;importe quelle séquence de n chiffres n&#8217;apparait qu&#8217;une seule fois. Autrement dit, si vous <a href="http://www.hakank.org/comb/debruijn.cgi?k=3&amp;n=5">générez une séquence de Bruijn avec k=3 et n=5</a> (les codes Bixi) et que vous y cherchez votre code Bixi, il n&#8217;y sera qu&#8217;une seule fois. C&#8217;est la façon la plus optimale d&#8217;attaquer un système de codes comme celui de Bruijn.</p>
<p>Voici la séquence dans l&#8217;ordre. Elle se lit de gauche à droite, de haut en bas. 1111121111311&#8230;&#8230; Le 1111 de la fin de la séquence est en fait les premiers chiffres qui se répêtent.</p>
<pre>11111 21111 31112 21112 31113 21113 31121 21121 31122 21122</pre>
<pre>31123 21123 31131 21131 31132 21132 31133 21133 31212 21212</pre>
<pre>31213 21213 31221 31222 21222 31223 21223 31231 31232 21232</pre>
<pre>31233 21233 31313 21313 31322 21322 31323 21323 31332 21332</pre>
<pre>31333 21333 32222 23222 33223 23223 33232 33233 33311 11</pre>
<p>La protection contre cette attaque est heureusement toute simple : à l&#8217;étape 2, effacer tous les chiffres et en redemander n autres. C&#8217;est ce qu&#8217;on fait les designers de Bixi. L&#8217;histoire ne dit pas s&#8217;ils connaissaient l&#8217;attaque, ou s&#8217;ils ont été chanceux&#8230; Au moins il pourrons dire qu&#8217;il m&#8217;ont fais marcher et pédaler !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2009/06/17/attaque-mathematique-des-codes-bixi-velo-libre-service/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Easy test coverage with constant Hamming distance of 1</title>
		<link>http://www.paralint.com/blog/2008/08/21/easy-test-coverage-with-constant-hamming-distance-of-1/</link>
		<comments>http://www.paralint.com/blog/2008/08/21/easy-test-coverage-with-constant-hamming-distance-of-1/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 03:47:19 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Other technical]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2008/08/21/easy-test-coverage-with-constant-hamming-distance-of-1/</guid>
		<description><![CDATA[I left a terrible bug in version 1.3 of my replacement Gina. I didn&#8217;t want to miss any test case this time, so I wrote a batch file that tests every one of them. That batch file adds a user to a group and a group to the registry. There are two possible groups in [...]]]></description>
			<content:encoded><![CDATA[<p>I left a terrible bug in version 1.3 of my <a href="http://www.paralint.com/projects/aucun/" target="_blank">replacement Gina</a>. I didn&#8217;t want to miss any test case this time, so I wrote a batch file that tests every one of them. That batch file adds a user to a group and a group to the registry. There are two possible groups in the registry, and the user can be a member of either two groups, making 2^(2+2) possibilities, 16 use cases.</p>
<p>After a few lines in, I realized that I would be less work to order the tests in a way that would minimize the change to the configuration between any two tests. In other words, when a n+1 test case required a change to the registry, then the user group membership should not change, and vice-versa. That would also make it easy to investigate a failed test, because only one thing would change between any two tests.</p>
<p>Then it hit me.</p>
<p>Well actually, I had to stop and think for a while. Kind of like my mind restoring a dusty old tape archive&#8230; I remembered that mathematician Richard Hamming had a <a href="http://en.wikipedia.org/wiki/Hamming_distance" target="_blank">code for that</a>. It&#8217;s a numbering scheme where only 1 bit changes between any two numbers. The number of bits that change is the Hamming distance between two numbers. Using four information bits to represent each possible use case, I came up with the following table. The first two rows (MSB, in blue) are user membership to a group, and the two last rows (LSB, in green) is the presence of that group in the registry. Ordering my tests that way gave me a constant Hamming distance of 1.</p>
<table border="1" cellspacing="0" cellpadding="2" width="100%">
<tbody>
<tr>
<td width="23" align="middle" valign="top"><strong>Decimal value</strong></td>
<td width="23" align="middle" valign="top"><strong>0</strong></td>
<td width="23" align="middle" valign="top"><strong>1</strong></td>
<td width="23" align="middle" valign="top"><strong>3</strong></td>
<td width="23" align="middle" valign="top"><strong>2</strong></td>
<td width="23" align="middle" valign="top"><strong>6</strong></td>
<td width="23" align="middle" valign="top"><strong>7</strong></td>
<td width="23" align="middle" valign="top"><strong>5</strong></td>
<td width="23" align="middle" valign="top"><strong>4</strong></td>
<td width="23" align="middle" valign="top"><strong>12</strong></td>
<td width="23" align="middle" valign="top"><strong>13</strong></td>
<td width="23" align="middle" valign="top"><strong>15</strong></td>
<td width="23" align="middle" valign="top"><strong>14</strong></td>
<td width="23" align="middle" valign="top"><strong>10</strong></td>
<td width="23" align="middle" valign="top"><strong>11</strong></td>
<td width="23" align="middle" valign="top"><strong>9</strong></td>
<td width="23" align="middle" valign="top"><strong>8</strong></td>
</tr>
<tr style="background-color: #B7C9E3;">
<td width="23" align="middle" valign="top"><span style="color: #000000;">Unlock</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
</tr>
<tr style="background-color: #B7C9E3;">
<td width="23" align="middle" valign="top"><span style="color: #000000;">Logoff</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
</tr>
<tr style="background-color: #c6e88c;">
<td width="23" align="middle" valign="top"><span style="color: #000000;">Unlock</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
</tr>
<tr style="background-color: #c6e88c;">
<td width="23" align="middle" valign="top"><span style="color: #000000;">Logoff</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><strong><span style="color: #000000;">1</span></strong></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">1</span></td>
<td width="23" align="middle" valign="top"><span style="color: #000000;">0</span></td>
</tr>
<tr>
<td width="23" valign="top">Expected test result</td>
<td width="23" valign="top">Gina</td>
<td width="23" valign="top">Gina</td>
<td width="23" valign="top">Gina</td>
<td width="23" valign="top">Gina</td>
<td width="23" valign="top">Gina</td>
<td width="23" valign="top"><strong>Force logoff</strong></td>
<td width="23" valign="top"><strong>Force logoff</strong></td>
<td width="23" valign="top">Gina</td>
<td width="23" valign="top">Gina</td>
<td width="23" valign="top"><strong>Force logoff</strong></td>
<td width="23" valign="top"><strong>Unlock</strong></td>
<td width="23" valign="top"><strong>Unlock</strong></td>
<td width="23" valign="top"><strong>Unlock</strong></td>
<td width="23" valign="top"><strong>Unlock</strong></td>
<td width="23" valign="top">Gina</td>
<td width="23" valign="top">Gina</td>
</tr>
</tbody>
</table>
<p>The only drawback to this is that all the typing I saved writing my <a href="http://src.paralint.com/aucun/branches/force-logoff-bug/tests.cmd" target="_blank">test batch file</a>, I wasted on this blog post !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/08/21/easy-test-coverage-with-constant-hamming-distance-of-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Counting on your 1024 fingers</title>
		<link>http://www.paralint.com/blog/2007/09/24/counting-on-your-1024-fingers/</link>
		<comments>http://www.paralint.com/blog/2007/09/24/counting-on-your-1024-fingers/#comments</comments>
		<pubDate>Mon, 24 Sep 2007 18:52:12 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2007/09/24/counting-on-your-1024-fingers/</guid>
		<description><![CDATA[Last week I went to a conference given by Mathieu Hébert. He was showing off, and somewhat teaching, his ability to do mathematical operations on his fingers (article in French), using each one as a binary digit. Ten fingers makes for 1024 combinaisons, allowing to represent number as big as 1023 since it starts with [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I went to a conference given by Mathieu Hébert. He was showing off, and somewhat teaching, his <a href="http://www.cyberpresse.ca/article/20070127/CPACTUALITES/701270816/1019/CPACTUALITES" rel="acquaintance met"> ability to do mathematical operations on his fingers</a> (article in French), using each one as a binary digit. Ten fingers makes for 1024 combinaisons, allowing to represent number as big as 1023 since it starts with 0.</p>
<p class="important">Many numbers in the linked article are wrong, stick to your calculator for accuracy&#8230;</p>
<p>The idea is rather simple, though having thought of it in 1940 is really <span style="font-style: italic">avant-garde</span>. The <a href="http://en.wikipedia.org/wiki/Z1_%28computer%29">Z1 computer</a> was built only a few years before !</p>
<p>If you look on the Internet, you will find many resources showing how to represent a number on your fingers. What was cool was his ability to add, subtract, divide and multiply just by fiddling his fingers. He identified some patterns and he reproduces them at each calculation step, without really knowing what number he is at. When he is done, he just reads the  binary number back in decimal for a usable answer.</p>
<p>If you have <a href="http://www.gnu.org/software/bc/">bc</a>, set obase=2 and give a try. Start by reprenting easy, one-handed 2-bit numbers, like 10, 20 or 24. Then add one bit on your other hand, with numbers like 74, 84 or 88. You should see a pattern right about now&#8230;</p>
<p>Come up with a few numbers and represent them on your fingers. Aim for accuracy, not speed. Then start to look for numbers around you: license plates, subway car number, the time or date. You are surrounded by numbers&#8230;</p>
<p>I am at the point of trying to do simple operations. Subtracting looks like the easiest one to do. M. Hebert is 86, and he would like for his tricks to survive him. I will try to whip up a tutorial &#8211; my laptop was stolen, so all my other projects are on hold.</p>
<p>Until then, I give M. Hébert a 48 (that&#8217;s two thumbs up, in binary) <img src='http://www.paralint.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2007/09/24/counting-on-your-1024-fingers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
