<?xml version="1.0"?>
<!-- name="generator" content="blosxom/2.0" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>null program   </title>
    <link>http://www.nullprogram.com/index.cgi</link>
    <description>Hobby Computing</description>
    <language>en</language>

  <item>
    <title>Play NetHack</title>
    <link>http://www.nullprogram.com/index.cgi/2008/09/17#nethack</link>
    <description>&lt;!-- 17 September 2008 --&gt;
&lt;p&gt;
  &lt;img src=&quot;http://www.nullprogram.com/img/nethack-cat.jpg&quot;
       alt=&quot;Your ally in your search for The Amulet&quot;
       align=&quot;right&quot; border=&quot;0&quot; hspace=&quot;10&quot; width=&quot;250&quot; /&gt;

Patience. NetHack is all about patience. Never be too hasty, as the
game is extremely unforgiving. If you let your guard down for just a
few turns, you can easily lose everything. Death is permanent
(with &lt;a href=&quot;http://nethack.wikia.com/wiki/Amulet_of_life_saving&quot;&gt;
some exceptions&lt;/a&gt;), so dying means starting it all over with a new
character.
&lt;/p&gt;
&lt;p&gt;
I got into &lt;a href=&quot;http://www.nethack.org/&quot;&gt;NetHack&lt;/a&gt; a couple of
years ago. I play is in cycles, playing heavily for a couple of months
at a time, then take a break for a couple months after I tire of
getting stuck at the same point each game. I generally return a better
player. The game is very complex, taking probably a hundred hours of
play just to nail down the basic gameplay and techniques.
&lt;/p&gt;
&lt;p&gt;
This is what my typical session looks like. I like it almost as simple
as it comes. By default, color is off, but I like to have it on (a lot
more information is available with color). The graphics may seem
crappy, but
&lt;a href=&quot;http://www.battlereports.com/users/johnny_vegas2/artius1/Report/report.html&quot;&gt;
it is said&lt;/a&gt;,
&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;
    While the graphics may seem primitive by today's standards,
    today's gameplay seems primitive by NetHack standards.
  &lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre style=&quot;background-color: #000000; color: #FFFFFF;&quot;&gt;
The dingo is blinded by the flash!  The dingo turns to flee!

                                                                       -------
                                                                       |&lt;span style=&quot;color: #0000FF;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #00FF00;&quot;&gt;+&lt;/span&gt;...|
       --------------                               ----------         |.+...|
       |............|              --------         |&amp;gt;........#        ---|---
       |............|              |......|         |........|#           #
       |.........&amp;lt;...#            #.......|         |........|#         ###
       |...&lt;span style=&quot;color: #0000FF;&quot;&gt;^&lt;/span&gt;........|           ###|......|         --.-------#         #
       --.----.------           #  ------.-#          #       ###       #
         #######              ###        ###          ###       #       #
            ####              #           #             #       ###     #
               ###          ###           ####          ###       #     #
                 #          #               #  #          #       ###---.----
                 ##       ###               #########     #         #.......|
                 -.----   #                      # -.-----&lt;span style=&quot;color: #AA5500;&quot;&gt;|&lt;/span&gt;--        |@.....|
                 |.`...####                      ##&lt;span style=&quot;color: #AA5500;&quot;&gt;-&lt;/span&gt;........|        |...&lt;span style=&quot;color: #0000FF;&quot;&gt;[&lt;/span&gt;..|
                 |....|                            |........|        |......|
                 |&lt;span style=&quot;color: #0000FF;&quot;&gt;{&lt;/span&gt;...|         0##################&lt;span style=&quot;color: #AA5500;&quot;&gt;-&lt;/span&gt;........|########-......|
                 ------                            |........|#       --------
                                                   ----------#

wellons the Sightseer       St:12 Dx:12 Co:18 In:12 Wi:8 Ch:16  Neutral S:1967
Dlvl:6  $:1329 HP:48(48) Pw:17(17) AC:7  Xp:5/185 T:3717
&lt;/pre&gt;
&lt;p&gt;
Like most rogue-like games, playing NetHack is a rewarding experience,
so if you never tried it out before, I suggest taking a look at
the &lt;a href=&quot;http://www.nethack.org/v343/Guidebook.html&quot;&gt;NetHack
Guidebook&lt;/a&gt; and firing it up for yourself! If you don't want to
install it, but you have a telnet client available, you can connect to
the &lt;a href=&quot;http://www.alt.org/nethack/&quot;&gt;nethack.alt.org&lt;/a&gt; server
to play and watch others play, which is a good way to learn
more. Building it from source can be a little tricky (took me a little
while to figure it out the first time), so using your package manager
is advised if you do choose to install it to try it out.
&lt;/p&gt;
&lt;p&gt;
Another good resource is the NetHack
wiki &lt;a href=&quot;http://nethack.wikia.com/&quot;&gt;Wikihack&lt;/a&gt;. However, if you
don't want to &quot;spoil&quot; yourself, don't go there. Learning things about
the game outside of the game is not considered cheating, but rather
spoiling. I don't mind spoiling myself. I will run into plenty of
things I have not yet spoiled myself on. The game is hard enough as it
is!
&lt;/p&gt;
&lt;p&gt;
There is a theory that if someone ever completely beats NetHack under
the hardest conditions, the source code will be thrown out and
replaced with something even harder and more unforgiving. There is
another theory which states that this has already happened.
&lt;/p&gt;
&lt;p&gt;
When play for the first time, start with a Valkyrie or a Barbarian as
these classes are pretty tough against baddies, simpler to play, and
more foolproof than some of the squishier classes, like wizards.
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;WARNING: SPOILERS FOLLOW&lt;/b&gt;
&lt;/p&gt;
&lt;p&gt;
To give an idea of some of the interesting gameplay, I have a couple
examples.
&lt;/p&gt;
&lt;pre style=&quot;background-color: #000000; color: #FFFFFF;&quot;&gt;
               #
          -----.--
          |....&lt;span style=&quot;color: #FFFF00;&quot;&gt;y&lt;/span&gt;.|     ## 
          |......|     #
          |.&lt;span style=&quot;color: #0000FF;&quot;&gt;n&lt;/span&gt;....@f######
          |......|
          |....&lt;span style=&quot;color: #00FF00;&quot;&gt;n&lt;/span&gt;.|
          --------
&lt;/pre&gt;
&lt;p&gt;
I am the &lt;code&gt;@&lt;/code&gt; symbol, which is how NetHack represents the
player. I am entering the room with two
awakened &lt;a href=&quot;http://nethack.wikia.com/wiki/Nymph&quot;&gt;nymphs&lt;/a&gt;
(&lt;code&gt;n&lt;/code&gt;) and a
&lt;a href=&quot;http://nethack.wikia.com/wiki/Yellow_light&quot;&gt;yellow light&lt;/a&gt;
(&lt;code&gt;y&lt;/code&gt;). Behind me is my cat who fights alongside me and
assists me. Nymphs do not do damage, but rather steal your
equipment. They approach you, charm you into giving them something
from your inventory, which includes weapons and armor, and teleport
away. This means that you generally want to kill them before they
close in.
&lt;/p&gt;
&lt;p&gt;
Yellow lights also do no damage. They run up to you and explode,
causing you to be blind for a number of turns. Normally, this can be a
really bad situation if you do not have the right tools available to
you, which is typical for early in the game. In the worst case, which
also happens to be the most likely, while I work on the nymphs the
yellow light will run up to be blinding me. Now, since I cannot see
the nymphs, I cannot attack them at range and they run up to me each
stealing one item. If I remain blind for long enough, they may find me
again and steal something else while I am helpless. They would rob me
blind! It would be up to my cat to dispatch them.
&lt;/p&gt;
&lt;p&gt;
However, I did have some good tools available. I happened to get
extremely lucky
(the &lt;a href=&quot;http://nethack.wikia.com/wiki/RNG&quot;&gt;Random Number God&lt;/a&gt;
was nice to me that day) and find both
a &lt;a href=&quot;http://nethack.wikia.com/wiki/Cloak_of_displacement&quot;&gt;cloak
of displacement&lt;/a&gt; and
&lt;a href=&quot;http://nethack.wikia.com/wiki/Jumping_boots&quot;&gt;jumping
boots&lt;/a&gt; at a store at dungeon level 1. The cloak makes me appear to
be in a different place than I really am while the jumping boots let
me travel several squares in a single turn. I was also playing a
rogue, so my main attack was already a ranged one: throwing daggers.
&lt;/p&gt;
&lt;p&gt;
The yellow light ran up to my displaced image and exploded, causing no
blindness to me. One down. Next, I threw my plentiful supply of
daggers at the nymphs, keeping my distance by jumping around the
room. I managed to prevent a deadly situation, being stuck naked with
no weapon, by applying my resources well. With NetHack, I had plenty
of time to plan out each move I made. There is no timer. NetHack moves
at &lt;i&gt;my&lt;/i&gt; pace.
&lt;/p&gt;
&lt;p&gt;
There was a another situation a couple months ago (which I will not
bother drawing) where I was attacked in the middle of a room by a
&lt;a href=&quot;http://nethack.wikia.com/wiki/Canine&quot;&gt;werewolf&lt;/a&gt;. The
werewolf summoned help immediately and I was surrounded by winter
wolves and coyotes and such. Winter wolves can be dangerous because
they shoot deadly frost bolts, and I had not yet have the
&lt;a href=&quot;http://nethack.wikia.com/wiki/Cold_resistance&quot;&gt;cold
resistance&lt;/a&gt; intrinsic.
&lt;/p&gt;
&lt;p&gt;
I cut a hole through the canines towards the hallway where I could
fight them one at a time, and I lost most of my health in the
process. Then
I &lt;a href=&quot;http://nethack.wikia.com/wiki/Prayer&quot;&gt;prayed&lt;/a&gt; to recover
my health. Then I starting hacking away at the canines. Again, I was
low on health and running out of options. The winter wolves were
firing bolts down the hallway at
me. Engraving &lt;a href=&quot;http://nethack.wikia.com/wiki/Elbereth&quot;&gt;Elbereth&lt;/a&gt;
on the floor was not going to save me from the ranged frost
bolts. Things were looking quite grim for me. The end seemed near.
&lt;/p&gt;
&lt;p&gt;
I did the only thing I could think to do at this point: I reached down
and took a bite into one of the dead frost wolves that was resting on
the floor beneath me.
&lt;/p&gt;
&lt;p&gt;
Take a moment and picture this. Frost bolts are zipping down a dark
cold hallway at a nearly dead Valkyrie. There are shattered potions
and frozen liquids all over the floor. The winter wolves have caused
the temperature to plummet. Her breath hangs visibly in the air. She
quickly crouches down and shoves her face into a dead wolf, taking a
nasty bite right into its furry, bloodied side. Between her clenched
teeth she tears off a piece dripping with blood. Desperately, she
stuffs her face with the fresh kill, trying to eat as much as fast as
she can as she dodges more frost bolts.
&lt;/p&gt;
&lt;p&gt;
At this moment, the Random Number God blessed me with good fortune,
and I was granted the cold resistance intrinsic just before the next
frost bolt was going to kill me, allowing me to harmlessly absorb it
and continue hacking away the remaining canines. Her reward for
victory was a canine feast!
&lt;/p&gt;
&lt;p&gt;
So, yes, the simple looking NetHack can be quite exciting. :-)
&lt;/p&gt;</description>
  </item>
  <item>
    <title>A GNU Octave Feature</title>
    <link>http://www.nullprogram.com/index.cgi/2008/08/29#octave-vs-matlab</link>
    <description>&lt;!-- 29 August 2008 --&gt;
&lt;p&gt;
At work they recently moved me to a new project. It is a Matlab-based
data analysis thing. I haven't really touched Matlab in over a year
(the last time I used Matlab at work), and, instead, use GNU Octave at
home when the language is appropriate. I got so used to Octave that I
found a pretty critical feature missing from Matlab's implementation:
treat an expression as if it were of the type of its output.
&lt;/p&gt;
&lt;p&gt;
Let's say we want to index into the result of a function. Take, for
example, the magic square function, &lt;code&gt;magic()&lt;/code&gt;. This spits
out a
&lt;a href=&quot;http://en.wikipedia.org/wiki/Magic_square&quot;&gt;magic square&lt;/a&gt;
of the given size. In Octave we can generate a 4x4 magic square and
chop out the middle 2x2 portion in one line.
&lt;/p&gt;
&lt;pre&gt;
octave&gt; magic(4)(2:3,2:3)
ans =

   11   10
    7    6
&lt;/pre&gt;
&lt;p&gt;
Or more possibly clearly,
&lt;/p&gt;
&lt;pre&gt;
octave&gt; [magic(4)](2:3,2:3)
ans =

   11   10
    7    6
&lt;/pre&gt;
&lt;p&gt;
Try this in Matlab and you will get a big, fat error. You have to
assign the magic square to a temporary variable to do the same
thing. I kept trying to do this sort of thing in Matlab and was
thinking to myself, &quot;I &lt;i&gt;know&lt;/i&gt; I can do this somehow!&quot;. Nope, I
was just used to having Octave.
&lt;/p&gt;
&lt;p&gt;
Where this really shows is when you want to reshape a matrix into a
nice, simple vector. If you have a matrix &lt;code&gt;M&lt;/code&gt; and want to
count the number of NaN's it has, you can't just apply
the &lt;code&gt;sum()&lt;/code&gt; function over &lt;code&gt;isnan()&lt;/code&gt; because it
only does sums of columns. You can get around this with a special
index, &lt;code&gt;(:)&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
So, to sum all elements in &lt;code&gt;M&lt;/code&gt; directly,
&lt;/p&gt;
&lt;pre&gt;
octave&gt; sum(M(:))
&lt;/pre&gt;
&lt;p&gt;
In Octave, to count NaN's with &lt;code&gt;isnan()&lt;/code&gt;,
&lt;/p&gt;
&lt;pre&gt;
octave&gt; sum(isnan(M)(:))
&lt;/pre&gt;
&lt;p&gt;
Again, Matlab won't let you index the result of &lt;code&gt;isnan()&lt;/code&gt;
directly. Stupid. I guess the Matlab way to do this is to
apply &lt;code&gt;sum()&lt;/code&gt; twice.
&lt;/p&gt;
&lt;p&gt; Every language I can think of handles this properly. C, C++, Perl,
Ruby, etc. It is strange that Matlab itself doesn't have it. Score one
more for Octave.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>The Arcfour Stream Cipher</title>
    <link>http://www.nullprogram.com/index.cgi/2008/08/09#arcfour</link>
    <description>&lt;!-- 9 August 2008 --&gt;
&lt;p&gt;
&lt;a href=&quot;http://en.wikipedia.org/wiki/Stream_cipher&quot;&gt;Stream
ciphers&lt;/a&gt; are one of the two types
of &lt;a href=&quot;http://en.wikipedia.org/wiki/Symmetric_key_algorithm&quot;&gt;
symmetric key algorithms&lt;/a&gt;, which is when the same key is used for
encryption and decryption. They follow this simple concept: take a
good pseudo-random number generator and combine, usually by XOR, its
output with your plaintext stream. This is very similiar to
the &lt;a href=&quot;http://www.nullprogram.com/index.cgi/2008/07/08#otp&quot;&gt;
one-time pad&lt;/a&gt;, but the random pad is pseudo-random rather than
truly random. The key is the seed (or part of one) for
the &lt;acronym title=&quot;pseudo-random number generator&quot;&gt;PRNG&lt;/acronym&gt;.
&lt;/p&gt;
&lt;p&gt;
Probably the most well known stream cipher is the extremely simple,
yet cryptographically
strong, &lt;a href=&quot;http://en.wikipedia.org/wiki/RC4&quot;&gt;Arcfour
algorithm&lt;/a&gt;. The official name is actually RC4, which comes from RSA
Security where it was developed. It was a trade secret until someone
anonymously leaked the algorithm to the public. The name RC4 is still
trademarked, though, so Arcfour is generally used instead, meaning
&quot;Alleged RC4&quot; (alleged because RSA Security never confirmed the
algorithm as &lt;i&gt;being&lt;/i&gt; RC4). You have almost certainly used the
cipher yourself, because it is used in applications such as WEP and
SSL.
&lt;/p&gt;
&lt;p&gt;
The algorithm has two parts: the key schedule algorithm and
pseudo-random generation algorithm. The key schedule uses the key,
and possible a non-secret initialization vector, to set up the state
of the PRNG. The state is an array of length 256 holding all of the
values from 0 to 255 in some order, along with two integers
(initialized to 0 after the key schedule). The algorithm looks like
this,
&lt;/p&gt;
&lt;pre&gt;
for i from 0 to 255
    S[i] := i
endfor
j := 0
for i from 0 to 255
    j := (j + S[i] + key[i mod keylength]) mod 256
    swap(S[i],S[j])
endfor
&lt;/pre&gt;
&lt;p&gt;
The PRNG deals with one byte at a time, emitting a stream of bytes,
&lt;/p&gt;
&lt;pre&gt;
i := 0
j := 0
while GeneratingOutput:
    i := (i + 1) mod 256
    j := (j + S[i]) mod 256
    swap(S[i],S[j])
    output S[(S[i] + S[j]) mod 256]
endwhile
&lt;/pre&gt;
&lt;p&gt;
If you implement this in C and use the &lt;code&gt;char&lt;/code&gt; type, you can
toss the modulus parts because they will just work automatically.
&lt;/p&gt;
&lt;p&gt;
Now you just XOR your message with the output of the PRNG. The
&lt;a href=&quot;http://en.wikipedia.org/wiki/RC4&quot;&gt; Wikipedia article&lt;/a&gt;
probably explains it better than I can, so check it out if you still
don't follow.
&lt;/p&gt;
&lt;p&gt;
Now, Arcfour has some flaws. Specifically, the algorithm itself
doesn't specify how an initialization vector is applied, which is
important. Using a plan key twice is bad it allows an adversary to get
information easily. For example, Lets say you have two
messages &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt;. You use the same
key &lt;code&gt;k&lt;/code&gt;, which will produce the same keystream K. Now, you
create your two ciphertexts &lt;code&gt;C&lt;sub&gt;A&lt;/sub&gt;&lt;/code&gt;
and &lt;code&gt;C&lt;sub&gt;B&lt;/sub&gt;&lt;/code&gt;
&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;C&lt;sub&gt;A&lt;/sub&gt;&lt;/code&gt; = A ^ K
&lt;code&gt;C&lt;sub&gt;B&lt;/sub&gt;&lt;/code&gt; = B ^ K
&lt;/pre&gt;
&lt;p&gt;
But notice if the adversary has both ciphertexts,
&lt;/p&gt;
&lt;pre&gt;
&lt;b&gt;&lt;code&gt;C&lt;sub&gt;A&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;C&lt;sub&gt;B&lt;/sub&gt;&lt;/code&gt;&lt;/b&gt; = A ^ K ^ B ^ K = &lt;b&gt;A ^ B&lt;/b&gt;
&lt;/pre&gt;
&lt;p&gt;
They are left with your two original messages XORed together. Let me
illustrate: we have two messages as bitmap images (here as PNGs for
the web),
&lt;/p&gt;
&lt;p&gt;
  &lt;img src=&quot;http://www.nullprogram.com/img/arcfour/blank.png&quot;
       alt=&quot;Plain pattern&quot; /&gt;
  &lt;img src=&quot;http://www.nullprogram.com/img/arcfour/head.png&quot;
       alt=&quot;GNU Head&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;
Encrypt them using the same key. In this case, my key was &quot;somekey&quot;.
&lt;/p&gt;
&lt;p&gt;
  &lt;img src=&quot;http://www.nullprogram.com/img/arcfour/blank-rc4.png&quot; 
       alt=&quot;Plain pattern encrypted&quot; /&gt;
  &lt;img src=&quot;http://www.nullprogram.com/img/arcfour/head-rc4.png&quot;
       alt=&quot;GNU Head encrypted&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;
If the adversary has both of these second &quot;images&quot;, she can XOR them
together (having &lt;i&gt;no&lt;/i&gt; knowledge of the key!) and get this,
&lt;/p&gt;
&lt;p&gt;
  &lt;img src=&quot;http://www.nullprogram.com/img/arcfour/both.png&quot;
       alt=&quot;Images superimposed&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;
An initialization vector (IV) is a set of bytes we combine with the
key. The IV is not a secret, as it is sent plaintext with the
ciphertext. If different IVs were used above with the same key, XORing
the ciphertext would result in nothing, because the keystreams are
totally different for each message.
&lt;/p&gt;
&lt;p&gt;
However, the &lt;i&gt;way&lt;/i&gt; the IV is combined is important too. Simply
concatenating the IV and the key can lead to weaknesses due to the way
the key schedule algorithm works. Something more secure would be a
cryptographic hash of the key and the IV. The reason WEP is broken is
because in its design the IV wasn't used properly.
&lt;/p&gt;
&lt;p&gt;
Another weakness is that the initial bytes of the keystream have low
entropy. That is, some bits tend to be 0's or 1's consistently, which
can leak information to an adversary. This can be countered by tossing
the first few bytes of the keystream. Often the first 768 bytes are
dropped, but a conservative amount would be 3072 bytes. Another way to
deal with this is running the key schedule algorithm 10 or 20 times
(not reinitializing the S array between them of course) rather than
just once, which is the way &lt;a href=&quot;http://ciphersaber.gurus.org/&quot;&gt;
CipherSaber-2&lt;/a&gt; does it.
&lt;/p&gt;
&lt;p&gt;
Yet another weakness is that the keystream
becomes &lt;a href=&quot;http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/FluhrerMcgrew.pdf&quot;&gt;
distinguishable from random data&lt;/a&gt; after about a gigabyte of
output. That is, after about a gigabyte, the entropy of the overall
stream can become too low and compromise the security of the
message. A solution might be to change the IV each gigabyte.
&lt;/p&gt;
&lt;p&gt;
I wrote an implementation of Arcfour in C, which you can get from my
&lt;a href=&quot;http://git.or.cz/&quot;&gt;Git&lt;/a&gt; repostiory with,
&lt;/p&gt;
&lt;pre&gt;
git clone &lt;a href=&quot;http://git.nullprogram.com/?p=arcfour.git;a=summary&quot;&gt;http://git.nullprogram.com/arcfour.git&lt;/a&gt;
&lt;/pre&gt;
&lt;p&gt;
Or grab
a &lt;a href=&quot;http://git.nullprogram.com/?p=arcfour.git;a=snapshot;h=refs/heads/master;sf=tgz&quot;&gt; snapshot&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
It is written as a library that can be used in different
applications. Included are a couple programs that make use of it. I
strongly suggest writing your own implementation. It is really easy to
do, and you will automatically have the algorithm memorized once you
do it. The Wikipedia article has some test vectors you can use to test
it.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Two-Man Double Blind Coke vs. Pepsi Taste Test</title>
    <link>http://www.nullprogram.com/index.cgi/2008/07/25#double-blind</link>
    <description>&lt;!-- 25 July 2008 --&gt;
&lt;p&gt;
&lt;a href=&quot;http://www.nullprogram.com/img/double-blind/setup.jpg&quot;&gt;
  &lt;img src=&quot;http://www.nullprogram.com/img/double-blind/setup-thumb.jpg&quot;
       alt=&quot;The Setup: 6 labeled cups, 2 drinks, and a 20-sided die&quot;
       align=&quot;right&quot; border=&quot;0&quot; hspace=&quot;10&quot; /&gt;
&lt;/a&gt;
My fiancee, Kelsey, claimed that she could tell the difference between
Coke and Pepsi. I wanted to put this to the test. Since there were
only two of us, arranging the test wasn't a simple matter of asking
someone else to pour some cups. I also wanted to do this right:
testing must
be &lt;a href=&quot;http://en.wikipedia.org/wiki/Blind_experiment#Double-blind_trials&quot;&gt;
double-blind&lt;/a&gt;. I devised a little scheme that allowed us to perform
two different tests.
&lt;/p&gt;
&lt;p&gt;
The first test was seeing if Kelsey or I could determine which
beverage was Pepsi and which was Coke. The second was determining if
there was any distinction in taste between the two drinks at all,
which consisted matching two different samples together. The second
test also acts as a check on the first test.
&lt;/p&gt;
&lt;p&gt;
We bought one bottle of each at CVS. Next, we labeled six different
cups with the numbers one though six. Each odd number is paired with
the following even number. Kelsey, who was alone, used a die with an
even number of sides (this includes a something as simple as a coin
toss) to put one beverage in cup #1 and the other in cup #2. In this
case, we used my 20-sided die I use for Dungeons and Dragons, because
using it for this purpose was just full of &lt;i&gt;win&lt;/i&gt;.
&lt;/p&gt;
&lt;p&gt;
The die is important here as a random number generator. If it is left
up to a human to decide what drinks go where, we may bias the
setup. For example, I may be more likely to put Pepsi in an
odd-numbered cup than an even-numbered one.
&lt;/p&gt;
&lt;p&gt;
It is difficult for human beings to behave randomly. Try generating a
list of 50 coin tosses yourself. I mean, without a coin. Just type a
series of 50 H's and T's. If you examine your list of flips, you will
find that you often generate very improbable series of flips
(excessive heads or tails) and exhibit patterns. We need dice or
coins to make decisions for us in this experiment.
&lt;/p&gt;
&lt;p&gt;
To do it right, the beverage must be chosen before the roll: &quot;I will
be pouring Pepsi now.&quot;. Roll the die. If it rolls an odd number, pour
the drink into the odd cup (#1). Write this information down and keep
it secret.
&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;http://www.nullprogram.com/img/double-blind/final4.jpg&quot;&gt;
  &lt;img src=&quot;http://www.nullprogram.com/img/double-blind/final4-thumb.jpg&quot;
       alt=&quot;The Final Setup&quot; align=&quot;left&quot; border=&quot;0&quot; hspace=&quot;10&quot; /&gt;
&lt;/a&gt;
Next, after allowing the foam to calm down (which might accidentally
reveal information to me), Kelsey leaves the room and I enter. I
perform a similar procedure to distribute the drinks into cups #3 and
#4, then #5 and #6. I keep track of what drink, #1 or #2, goes into
what cup. I keep it secret. These last two cups are for the purpose of
the second experiment.
&lt;/p&gt;
&lt;p&gt;
At this point Kelsey knows what was in cups #1 and #2, but not where
they went. I know where they went, but not what was in the
cups. &lt;b&gt;Together we know everything, but individually we know
nothing.&lt;/b&gt;
&lt;/p&gt;
&lt;p&gt;
In order to make the second test double-blind, and allow me to
participate, I leave the room. Kelsey rolls the die. If it rolls odd
she switches the label on cups #5 and #6. It is important that these
cups are identical. One flaw potential, however, is that the liquid in
each cup may look unique. One may be more fizzy or one cup a little
more full. Noticing this may happen subconsciously, which is the whole
point of doing double-blind tests.
&lt;/p&gt;
&lt;p&gt;
Ok, we didn't actually do this last part because I didn't think of it
till later.
&lt;/p&gt;
&lt;p&gt;
We sample all four cups (#3 - #6) in pairs, alone, making notes on
what beverage we think is in what cup. Once we are both done we share
our secrets and see how well we did.
&lt;/p&gt;
&lt;p&gt;
Our results? Neither of us could tell the difference between Coke and
Pepsi.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Sudoku Solver</title>
    <link>http://www.nullprogram.com/index.cgi/2008/07/20#sudoku</link>
    <description>&lt;!-- 20 July 2008 --&gt;
&lt;p&gt;
&lt;img src=&quot;http://www.nullprogram.com/img/sudoku/toilet.jpg&quot;
     alt=&quot;My 'Thinking Chair'&quot; align=&quot;right&quot; /&gt;
I was at my fiancee's parent's house over Fourth of July weekend. Her
family likes to leave plenty of reading material right by the toilet,
which is something fairly new to me. They take their time on the john
quite seriously.
&lt;/p&gt;
&lt;p&gt;
While I was in there I saw a large book
of &lt;a href=&quot;http://en.wikipedia.org/wiki/Sudoku&quot;&gt; Sudoku&lt;/a&gt;
puzzles. Since the toilet is a good spot to think (I like to call it
my
&quot;&lt;a href=&quot;http://everything-more.blogspot.com/2008/04/that-t-shirt-is-wrong-color.html&quot;&gt;
thinking chair&lt;/a&gt;&quot;), I thought out an algorithm for solving
Sudokus. I then left the bathroom and implemented it in order to
verify that it worked.
&lt;/p&gt;
&lt;p&gt;
The method is trial-and-error, which it does recursively: fill in the
next available spot with a valid number as defined by the rules
(cannot have the same number in a column, row, or partition), and
recurse. The function reports success (true) when a solution was
found, or failure (false), which means we try the next available
number. If no more valid numbers are available for testing at the
current position, then the puzzle is not solvable (we made an error at
a previous position), so we stop recursing and return failure.
&lt;/p&gt;
&lt;p&gt;
More formally,
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Find an open position.&lt;/li&gt;
  &lt;li&gt;Look at that position's row, column, and partition to find valid
  numbers to fill in.&lt;/li&gt;
  &lt;li&gt;Fill the position with one of the valid choices.&lt;/li&gt;
  &lt;li&gt;Recurse using the new change.&lt;/li&gt;
  &lt;li&gt;If the recursion reports a problem (returns false), try the next
  valid number and repeat.&lt;/li&gt;
  &lt;li&gt;If recursion reports success (true), stop guessing and return
  success.&lt;/li&gt;
  &lt;li&gt;If the list of valid numbers is exhausted, return failure (false).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Note that the recursion depth does not exceed 81, as it only recurses
once per blank square. The &quot;game tree&quot; is broad rather than deep. It
doesn't have to duplicate the puzzle matrix in memory either because
all operations can be done in place.
&lt;/p&gt;
&lt;p&gt;
Here is the implementation in C I typed up just after I left the
bathroom,
&lt;/p&gt;
&lt;pre&gt;
int solve (char matrix[9][9])
{
  /* Find an empty spot. */
  int x, y, i, j, s = 0;
  for (i = 0; i &amp;lt; 9 &amp;amp;&amp;amp; !s; i++)
    for (j = 0; j &amp;lt; 9 &amp;amp;&amp;amp; !s; j++)
      if (matrix[i][j] == 0)
	{
	  x = i; y = j; s = 1;
	}
  
  /* No empty spots, we found a solution! */
  if (!s)
    return 1;
  
  /* Determine legal numbers for this spot. */
  char nums[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  for (i = 0, j = y; i &amp;lt; 9; i++)
    nums[(int)matrix[i][j]] = 0; /* Vertically */
  for (i = x, j = 0; j &amp;lt; 9; j++)
    nums[(int)matrix[i][j]] = 0; /* Horizontally */
  for (i = 0; i &amp;lt; 3; i++)
    for (j = 0; j &amp;lt; 3; j++)
      nums[(int)matrix
	   [i + ((int)(x / 3)) * 3]
	   [j + ((int)(y / 3)) * 3]
	   ] = 0;                /* Within the partition */
  
  /* Try each possible number and recurse for each. */
  for (i = 1; i &amp;lt; 10; i++)
    if (nums[i] &amp;gt; 0)
      {
	matrix[x][y] = i;
	if (solve (matrix))
	  return 1;
      }
  
  /* Each attempt failed: reset this position and report failure. */
  matrix[x][y] = 0;
  return 0;
}
&lt;/pre&gt;
&lt;p&gt;
I assumed that it would be slow solving the puzzles, having to search
a wide tree, but it turns out to be very fast. It solves normal
human-solvable puzzles in a couple of milliseconds. Wikipedia has a
near-worst case Sudoku that is designed to make algorithms like mine
perform their worst.
&lt;/p&gt;
&lt;p&gt;
  &lt;a href=&quot;http://www.nullprogram.com/img/sudoku/worst-case.svg&quot;&gt;
    &lt;img src=&quot;http://www.nullprogram.com/img/sudoku/worst-case.png&quot; 
	 alt=&quot;Worst-case Sudoku&quot; border=&quot;0&quot; /&gt;
  &lt;/a&gt;
&lt;/p&gt;
&lt;pre&gt;
char worst_case[9][9] =
  {
    {0, 0, 0,   0, 0, 0,   0, 0, 0},
    {0, 0, 0,   0, 0, 3,   0, 8, 5},
    {0, 0, 1,   0, 2, 0,   0, 0, 0},
    
    {0, 0, 0,   5, 0, 7,   0, 0, 0},
    {0, 0, 4,   0, 0, 0,   1, 0, 0},
    {0, 9, 0,   0, 0, 0,   0, 0, 0},
    
    {5, 0, 0,   0, 0, 0,   0, 7, 3},
    {0, 0, 2,   0, 1, 0,   0, 0, 0},
    {0, 0, 0,   0, 4, 0,   0, 0, 9}
  };
&lt;/pre&gt;
&lt;p&gt;
On my laptop, my program solves this in 15 seconds, which means that
it should take no more than 15 seconds to solve any given Sudoku
puzzle. This provides me a nice upper limit.
&lt;/p&gt;
&lt;p&gt;
There is a way to &quot;defeat&quot; this particular puzzle. For example, say an
attacker was trying to perform a
&lt;a href=&quot;http://en.wikipedia.org/wiki/Denial-of-service_attack&quot;&gt;
denial-of-service&lt;/a&gt; (DoS) attack on your Sudoku solver by giving it
puzzles like this one (making your server spend lots of time solving
only a few puzzles). However, these puzzles assume a certain guessing
order. By simply randomizing the order of guessing, both in choosing
positions and the order that numbers are guessed, the attacker will
have a much harder time creating a difficult puzzle. The worst case
could very well be the best case. This is very similar to how
Perl &lt;a href=&quot;http://www.ayni.com/perldoc/perlsec.html#Algorithmic-Complexity-Attacks&quot;&gt;
randomizes its hash array hash functions&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Now suppose we kept our guess order random then &quot;solved&quot; an empty
Sudoku puzzle. What we have is a solution to a randomly generated
Sudoku. To turn it into a puzzle, we just back it off a bit. A Sudoku
is only supposed to have a single unambiguous solution, so we can only
back off until just before the point where two solutions becomes
possible. If you imagine a solution tree, this would be backing up a
branch until you hit a fork.
&lt;/p&gt;
&lt;p&gt;
Normally, Sudokus are symmetric (in the matrix sense), but completely
randomizing the position guessing order won't achieve this. To make
this work, the randomizing process can be adjusted to only select
random points on the upper triangle (including the diagonal). For each
point it selects &lt;i&gt;not&lt;/i&gt; on the diagonal, the mirror point is
automatically selected next. This will preserve symmetry when
generating puzzles.
&lt;/p&gt;
&lt;p&gt;
One issue remains: there seems to be no way to control the difficulty
of the puzzles it generates. Maybe a number of open spaces left behind
is a good metric? This will require some further study (and another
post!).
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Variable Declarations and the C Call Stack</title>
    <link>http://www.nullprogram.com/index.cgi/2008/07/18#c-pointers</link>
    <description>&lt;!-- 18 July 2008 --&gt;
&lt;p&gt;
A co-worker asked me a question today about C/C++ pointers,
&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;
    If a pointer is declared inside a function with no explicit
    initialization, can I assume that the pointer is initialized
    to &lt;code&gt;NULL&lt;/code&gt;?
  &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
We were down in the lab and, therefore, he had no Internet access to
look it up himself, which is why he asked. When I code C, it is just a
sort of mental habit to not use a non-static function variable without
first initializing it, but is this accurate? I &lt;i&gt;knew&lt;/i&gt; the answer
was &quot;no&quot;, but I wanted to be able to explain the &quot;why&quot;.
&lt;/p&gt;
&lt;p&gt;
Anyway, I quickly recalled some of my experimental C programs and
thought carefully about the mechanics of what is going on
behind-the-scenes, allowing me to confidently give him a &quot;no&quot;
answer. I then threw this together in a few seconds to prove it,
&lt;/p&gt;
&lt;pre&gt;
#include &amp;lt;stdio.h&amp;gt;

void a ()
{
  int   * x = (int *) 0x012345FF;
  double  y = -63454;
  (void) x;
  (void) y;
}

void b ()
{
  int   * x;
  double  y;
  printf (&quot;%p, %f\n&quot;, x, y);
}

int main ()
{
  a ();
  b ();
  return 0;
}
&lt;/pre&gt;
&lt;p&gt;
When you compile it, make sure you don't use the optimization options
(&lt;code&gt;-O&lt;/code&gt;, &lt;code&gt;-O2&lt;/code&gt;, or &lt;code&gt;-O3&lt;/code&gt;
for &lt;code&gt;gcc&lt;/code&gt;) because they change the inner-workings of the
program. It might do things like make those functions inline (so they
won't be on the stack as I am intending), or even toss
out &lt;code&gt;a()&lt;/code&gt;, as it appears to do nothing. The compiler sees
that, even though I &quot;used&quot; variables in &lt;code&gt;a()&lt;/code&gt; by casting
them to &lt;code&gt;void&lt;/code&gt;, nothing is really happening,
so &lt;code&gt;a()&lt;/code&gt; can be ignored. We can probably get around this
with a tacked
on &lt;code&gt; &lt;a href=&quot;http://en.wikipedia.org/wiki/Volatile_variable&quot;&gt;
volatile&lt;/a&gt;&lt;/code&gt; declaration, which you might see a lot of in a
micro-controller program. In a micro-controller, some memory addresses
are mapped to registers external to the software, so, from the
compiler's point of view, access to these locations may look like
nothing is really happening. Optimizing away variables that point to
these memory locations will lead to an incorrect binary, so your robot
or laser guided shark or whatever won't work.
&lt;/p&gt;
&lt;p&gt;
Anyway, compiling with optimization will break my example! So don't do
it here.
&lt;/p&gt;
&lt;p&gt;
When compiling, you should get some warnings about using uninitialized
variables, which is kind of the point of my example. Ignore it. That
warning alone gives away the answer to the main question, really, but
this example is a bit more fun!
&lt;/p&gt;
&lt;p&gt;
Before you run it, study it and think about what the output should
look like. When &lt;code&gt;a()&lt;/code&gt; is called, its stack frame goes into
the call stack, which contains the two declared variables. These
variables are then assigned as part of the function
execution. When &lt;code&gt;a()&lt;/code&gt; returns, the frame is popped off the
stack. Then &lt;code&gt;b()&lt;/code&gt; is called, and, as the variable
declarations are exactly the same, it will fit right over top
of &lt;code&gt;a()&lt;/code&gt;'s old stack frame, and its variables will line
up. &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; are not assigned any value, so
they pick up whatever junk was lying around, which happens to be the
values assigned in &lt;code&gt;a()&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
When you run the program, this is the output,
&lt;/p&gt;
&lt;pre&gt;
0x12345ff, -63454.000000
&lt;/pre&gt;
&lt;p&gt;
The pointer is &lt;i&gt;not&lt;/i&gt; initialized
to &lt;code&gt;NULL&lt;/code&gt;. If &lt;code&gt;x&lt;/code&gt; is passed back uninitialized
under the assumption that a &lt;code&gt;NULL&lt;/code&gt; is being passed, some
other poor function that handles the return value may dereference it,
resulting in possibly
some &lt;a href=&quot;http://www.catb.org/jargon/html/N/nasal-demons.html&quot;&gt;
nasal demons&lt;/a&gt;, but most likely an annoying segmentation
fault. Worse, this error may occur far, far away from where the actual
problem is, and even worse than that, only sometimes (depending on the
state of the call stack at just the right moment).
&lt;/p&gt;
&lt;p&gt;
Note here that I am talking about non-static function variable
declarations. Global variables and static function variables will not
be on the stack. They are placed in a fixed location (in the data
segment), and their values are implicitly initialized to 0
at &lt;i&gt;compile time&lt;/i&gt;.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>A One-Time Pad Mistake</title>
    <link>http://www.nullprogram.com/index.cgi/2008/07/15#otp-fail</link>
    <description>&lt;!-- 15 July 2008 --&gt;
&lt;p&gt;
In a &lt;a href=&quot;http://www.nullprogram.com/index.cgi/2008/07/08#otp&quot;&gt;
previous post&lt;/a&gt; I discussed one-time pads. Note: this is about a
cryptosystem, not some kind of menstruation disaster. The information
for this post comes
from &lt;a href=&quot;http://forums.xkcd.com/viewtopic.php?f=12&amp;amp;t=23226&quot;&gt;
a little gem&lt;/a&gt; I saw on the &lt;a href=&quot;http://forums.xkcd.com/&quot;&gt; xkcd
forums&lt;/a&gt;. I generally don't lurk around there because it suffers
from the same disease most non-self-moderating forums suffer from:
anal retentive, power-abusing, whiny moderators. I lucked out this
time.
&lt;/p&gt;
&lt;p&gt;
The user Berengal posed the question,
&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p style=&quot;font-style: italic;&quot;&gt;
    One thing I've been wondering about is if you can use a single
    one-time-pad to encrypt other one-time-pads to send around.
  &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
My first though was, &quot;Hey, why didn't &lt;i&gt;I&lt;/i&gt; think of this?&quot;. Then,
after a moment, I realized that it was the sort of thing that is too
good to be true. This is along the lines of ideas that break the laws
of thermodynamics. We are looking at a perpetual motion machine
here. &lt;b&gt;Just as you cannot create or destroy energy, neither can you
use a one-time pad to distribute more than one other equal length
one-time pad.&lt;/b&gt; Let's make it formal,
&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p style=&quot;font-style: italic;&quot;&gt;
    In any closed one-time pad cryptosystem, the total number of
    one-time pad bits in the system remains the same.
  &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
Also, if something like this could work, people would be using it
already everywhere. Before I got a chance to think too much about it,
user AJR spoiled it with an excellent proof on why it &lt;i&gt;won't&lt;/i&gt;
work.
&lt;/p&gt;
&lt;p&gt;
Note below that I use &lt;code&gt;^&lt;/code&gt; to indicate
&lt;a href=&quot;http://en.wikipedia.org/wiki/Exclusive_or&quot;&gt; exclusive or&lt;/a&gt;
(XOR).
&lt;/p&gt;
&lt;p&gt;
Suppose you have a master pad, &lt;code&gt;K&lt;/code&gt;, that you use to
distribute two message pads, &lt;code&gt;k&lt;sub&gt;1 &lt;/sub&gt;&lt;/code&gt;
and &lt;code&gt;k&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;. You have two
messages, &lt;code&gt;m&lt;sub&gt;1 &lt;/sub&gt;&lt;/code&gt;
and &lt;code&gt;m&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;. We then have four transmitted texts:
two encrypted message pads &lt;code&gt;e&lt;sub&gt;1 &lt;/sub&gt;&lt;/code&gt;
and &lt;code&gt;e&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;, and two
ciphertexts &lt;code&gt;c&lt;sub&gt;1 &lt;/sub&gt;&lt;/code&gt;
and &lt;code&gt;c&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;. We define these as,
&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;e&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;K&lt;/code&gt; ^ &lt;code&gt;k&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt;
&lt;code&gt;e&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;K&lt;/code&gt; ^ &lt;code&gt;k&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;

&lt;code&gt;c&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;k&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;m&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt;
&lt;code&gt;c&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;k&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;m&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;
Suppose an adversary is able to record all four transmitted texts. He
can apply them like so,
&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;e&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;c&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;K&lt;/code&gt; ^ &lt;code&gt;k&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;k&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;m&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;K&lt;/code&gt; ^ &lt;code&gt;m&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt;

&lt;code&gt;e&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;c&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;K&lt;/code&gt; ^ &lt;code&gt;k&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;k&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;m&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;K&lt;/code&gt; ^ &lt;code&gt;m&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;
This cancels the original message keys and effectively leaves you
encrypting two messages with the same pad, which is exactly the wrong
thing to do when using one-time pads. Once that is done, the adversary
can do tricks like,
&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;e&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;e&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;c&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;c&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt; = &lt;code&gt;m&lt;sub&gt;1&lt;/sub&gt;&lt;/code&gt; ^ &lt;code&gt;m&lt;sub&gt;2&lt;/sub&gt;&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;
What is left is the two messages XORed together with no keys/pads
involved, which, depending on the messages, might reveal
something. Don't make this mistake.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>One-Time Pads and Plausible Deniability</title>
    <link>http://www.nullprogram.com/index.cgi/2008/07/11#otp-denial</link>
    <description>&lt;!-- 11 July 2008 --&gt;
&lt;p&gt;
In a &lt;a href=&quot;http://www.nullprogram.com/index.cgi/2008/07/08#otp&quot;&gt;
previous post&lt;/a&gt; I discussed one-time pads. The information for this
post comes from Bruce
Schneier's &lt;a href=&quot;http://www.schneier.com/book-applied.html&quot;&gt;
Applied Cryptography&lt;/a&gt; (section 10.8).
&lt;/p&gt;
&lt;p&gt;
One-time pads are great for something
called &lt;a href=&quot;http://www.freenet.org.nz/phonebook/manual.html&quot;&gt;
plausible deniability&lt;/a&gt;. With plausible deniability, when a person
holding encrypted data is coerced into decrypting their data, the
interrogator will not be able to tell if the person is complying with
the decryption order or not. For example, the victim could provide an
alternate key that decrypts the ciphertext into some harmless dummy
plaintext. To make this more plausible, the plaintext would probably
be something potentially embarrassing, such as pornography or secret
love letters.
&lt;/p&gt;
&lt;p&gt;
We have a one-time pad &lt;code&gt;K&lt;/code&gt;, a plaintext &lt;code&gt;P&lt;/code&gt;, a
dummy plaintext (the pornography or love letters) &lt;code&gt;D&lt;/code&gt;, a
dummy key &lt;code&gt;K'&lt;/code&gt;, and a ciphertext &lt;code&gt;C&lt;/code&gt;. Below, I
denote XOR with &lt;code&gt;^&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
To encrypt our plaintext, its the normal one-time pad algorithm,
&lt;/p&gt;
&lt;pre&gt;
P ^ K = C
&lt;/pre&gt;
&lt;p&gt;
Bob and Alice share K, so decryption works like,
&lt;/p&gt;
&lt;pre&gt;
C ^ K = P
&lt;/pre&gt;
&lt;p&gt;
However, the secret police come along with
their &lt;a href=&quot;http://en.wikipedia.org/wiki/Thumbscrews&quot;&gt;
thumbscrews&lt;/a&gt; and demand that Alice and Bob give them the one-time
pad &lt;code&gt;K&lt;/code&gt;. Instead, they will provide &lt;code&gt;K'&lt;/code&gt;. How is
K' defined? Like this,
&lt;/p&gt;
&lt;pre&gt;
K' = C ^ D
&lt;/pre&gt;
&lt;p&gt;
Because &lt;code&gt;K&lt;/code&gt; is a one-time pad and is randomly generated,
there is no way to prove that &lt;code&gt;K'&lt;/code&gt; is &lt;i&gt;not&lt;/i&gt; the real
key. Alice and Bob give up &lt;code&gt;K'&lt;/code&gt;. The secret police decrypt
it,
&lt;/p&gt;
&lt;pre&gt;
C ^ K' = C ^ C ^ D = D
&lt;/pre&gt;
&lt;p&gt;
&quot;See? We were just keeping our love affair a secret from our spouses!&quot;
&lt;/p&gt;</description>
  </item>
  </channel>
</rss>