<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: The Playfair Cipher</title>
	<atom:link href="http://programmingpraxis.com/2009/07/03/the-playfair-cipher/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/07/03/the-playfair-cipher/</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Sat, 11 Feb 2012 09:48:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Steganography &#171; Programming Praxis</title>
		<link>http://programmingpraxis.com/2009/07/03/the-playfair-cipher/#comment-3124</link>
		<dc:creator><![CDATA[Steganography &#171; Programming Praxis]]></dc:creator>
		<pubDate>Fri, 10 Jun 2011 09:03:39 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=902#comment-3124</guid>
		<description><![CDATA[[...] bailouts as a brilliant success with no unpleasant side effects.&#8221; We&#8217;ll refer to the previous exercise for [...]]]></description>
		<content:encoded><![CDATA[<p>[...] bailouts as a brilliant success with no unpleasant side effects.&#8221; We&#8217;ll refer to the previous exercise for [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/2009/07/03/the-playfair-cipher/#comment-278</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Fri, 03 Jul 2009 19:46:18 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=902#comment-278</guid>
		<description><![CDATA[&lt;a href=&quot;http://bonsaicode.wordpress.com/2009/07/03/programming-praxis-the-playfair-cipher/&quot; rel=&quot;nofollow&quot;&gt;Elsewhere&lt;/a&gt;, Remco asks:

&lt;blockquote&gt;Interestingly, if you try to decode the 1943 message, you’ll notice two errors in the result: it says Blackess instead of Blackett and coce instead of cove. I wonder if the errors were made by the original sender or by the first person to type it on a computer.&lt;/blockquote&gt;

Both errors are in the original.  You can confirm that because Kahn includes in his book, in the chapter &quot;The Inscrutable Orientals,&quot; a picture of the original hand-written decipherment by Arthur Evans at 9:30am on the morning of August 2, 1943 (it&#039;s on page 592 of my copy of the 1996 edition).  His key ROYAL NEW ZEALAND NAVY forms the following Polybius square:

&lt;code&gt;R O Y A L
N E W Z D
V B C F G
H I K M P
Q S T U X&lt;/code&gt;

In the original message, BLACKETT STRAIT is enciphered as GOYFI WTTTU OLKS.  The three Ts all in a row is a violation of the Playfair rules.  Evans decoded the message as:

&lt;code&gt;GO YF IW TT TU OL KS
BL AC KE TT ST RA IT&lt;/code&gt;

When Evans reached the TT digram, he deciphered it as TT; that was easy, because he was sitting on his jungle hilltop looking at Blackett Strait.  But though it is easy to adjust by hand, the program does the wrong thing, as you noted.

The COVE/COCE error is undoubtedly a transcription error either by the original sender or by Evans.  The corresponding cipher-text is BYBW.  A correct encipherment of COVE is BYBN, and somewhere the N was transcribed as a W; easy enough to do if the pencil slips just at the beginning of the N, forming a small serif that causes N to be mistaken as W.  Again, Evans had no trouble fixing the error; since he lived there, he knew the message said MERESU COVE rather than MERESU COCE.

It is worth reading Kahn&#039;s book to learn the entire cryptographic history of the incident.  There is much more to it than just a few errors in a Playfair cipher.]]></description>
		<content:encoded><![CDATA[<p><a href="http://bonsaicode.wordpress.com/2009/07/03/programming-praxis-the-playfair-cipher/" rel="nofollow">Elsewhere</a>, Remco asks:</p>
<blockquote><p>Interestingly, if you try to decode the 1943 message, you’ll notice two errors in the result: it says Blackess instead of Blackett and coce instead of cove. I wonder if the errors were made by the original sender or by the first person to type it on a computer.</p></blockquote>
<p>Both errors are in the original.  You can confirm that because Kahn includes in his book, in the chapter &#8220;The Inscrutable Orientals,&#8221; a picture of the original hand-written decipherment by Arthur Evans at 9:30am on the morning of August 2, 1943 (it&#8217;s on page 592 of my copy of the 1996 edition).  His key ROYAL NEW ZEALAND NAVY forms the following Polybius square:</p>
<p><code>R O Y A L<br />
N E W Z D<br />
V B C F G<br />
H I K M P<br />
Q S T U X</code></p>
<p>In the original message, BLACKETT STRAIT is enciphered as GOYFI WTTTU OLKS.  The three Ts all in a row is a violation of the Playfair rules.  Evans decoded the message as:</p>
<p><code>GO YF IW TT TU OL KS<br />
BL AC KE TT ST RA IT</code></p>
<p>When Evans reached the TT digram, he deciphered it as TT; that was easy, because he was sitting on his jungle hilltop looking at Blackett Strait.  But though it is easy to adjust by hand, the program does the wrong thing, as you noted.</p>
<p>The COVE/COCE error is undoubtedly a transcription error either by the original sender or by Evans.  The corresponding cipher-text is BYBW.  A correct encipherment of COVE is BYBN, and somewhere the N was transcribed as a W; easy enough to do if the pencil slips just at the beginning of the N, forming a small serif that causes N to be mistaken as W.  Again, Evans had no trouble fixing the error; since he lived there, he knew the message said MERESU COVE rather than MERESU COCE.</p>
<p>It is worth reading Kahn&#8217;s book to learn the entire cryptographic history of the incident.  There is much more to it than just a few errors in a Playfair cipher.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Remco Niemeijer</title>
		<link>http://programmingpraxis.com/2009/07/03/the-playfair-cipher/#comment-275</link>
		<dc:creator><![CDATA[Remco Niemeijer]]></dc:creator>
		<pubDate>Fri, 03 Jul 2009 13:00:11 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=902#comment-275</guid>
		<description><![CDATA[My Haskell solution (see http://bonsaicode.wordpress.com/2009/07/03/programming-praxis-the-playfair-cipher/ for a version with comments):

[sourcecode lang=&#039;css&#039;]
import Data.Char
import Data.List
import Data.List.HT
import Data.List.Split
import qualified Data.Map as M

type Key = M.Map (Int, Int) Char

process :: String -&gt; String
process = replace &quot;J&quot; &quot;I&quot; . map toUpper . filter isLetter

key :: String -&gt; Key
key = M.fromList . concat .
      zipWith (\y -&gt; zipWith (\x c -&gt; ((x, y), c)) [0..]) [0..] .
      chunk 5 . (`union` delete &#039;J&#039; [&#039;A&#039;..&#039;Z&#039;]) . nub . process

bigram :: Key -&gt; Int -&gt; Char -&gt; Char -&gt; String
bigram k dir c1 c2
    &#124; y1 == y2  = get (x1 + dir, y1) : [get (x2 + dir, y2)]
    &#124; x1 == x2  = get (x1, y1 + dir) : [get (x2, y2 + dir)]
    &#124; otherwise = get (x2, y1)       : [get (x1, y2)]
    where (x1, y1) = head . M.keys $ M.filter (== c1) k
          (x2, y2) = head . M.keys $ M.filter (== c2) k
          get (x,y) = k M.! (mod x 5, mod y 5)

encode&#039; :: Key -&gt; String -&gt; String
encode&#039; _ []       = []
encode&#039; k [x]      = encode&#039; k (x : &quot;X&quot;)
encode&#039; k (x:y:xs) &#124; x == y    = encode&#039; k [x] ++ encode&#039; k (y:xs)
                   &#124; otherwise = bigram k 1 x y ++ encode&#039; k xs

decode&#039; :: Key -&gt; String -&gt; String
decode&#039; k = concatMap (\[x,y] -&gt; bigram k (-1) x y) . chunk 2

encode :: String -&gt; String -&gt; String
encode k = encode&#039; (key k) . process

decode :: String -&gt; String -&gt; String
decode k = decode&#039; (key k) . process

main :: IO ()
main = do print $ encode &quot;PLAYFAIR&quot; &quot;PROGRAMMING PRAXIS&quot;
          print $ decode &quot;PLAYFAIR&quot; &quot;LIVOBLKZEDOELIYWCN&quot;
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>My Haskell solution (see <a href="http://bonsaicode.wordpress.com/2009/07/03/programming-praxis-the-playfair-cipher/" rel="nofollow">http://bonsaicode.wordpress.com/2009/07/03/programming-praxis-the-playfair-cipher/</a> for a version with comments):</p>
<pre class="brush: css;">
import Data.Char
import Data.List
import Data.List.HT
import Data.List.Split
import qualified Data.Map as M

type Key = M.Map (Int, Int) Char

process :: String -&gt; String
process = replace &quot;J&quot; &quot;I&quot; . map toUpper . filter isLetter

key :: String -&gt; Key
key = M.fromList . concat .
      zipWith (\y -&gt; zipWith (\x c -&gt; ((x, y), c)) [0..]) [0..] .
      chunk 5 . (`union` delete 'J' ['A'..'Z']) . nub . process

bigram :: Key -&gt; Int -&gt; Char -&gt; Char -&gt; String
bigram k dir c1 c2
    | y1 == y2  = get (x1 + dir, y1) : [get (x2 + dir, y2)]
    | x1 == x2  = get (x1, y1 + dir) : [get (x2, y2 + dir)]
    | otherwise = get (x2, y1)       : [get (x1, y2)]
    where (x1, y1) = head . M.keys $ M.filter (== c1) k
          (x2, y2) = head . M.keys $ M.filter (== c2) k
          get (x,y) = k M.! (mod x 5, mod y 5)

encode' :: Key -&gt; String -&gt; String
encode' _ []       = []
encode' k [x]      = encode' k (x : &quot;X&quot;)
encode' k (x:y:xs) | x == y    = encode' k [x] ++ encode' k (y:xs)
                   | otherwise = bigram k 1 x y ++ encode' k xs

decode' :: Key -&gt; String -&gt; String
decode' k = concatMap (\[x,y] -&gt; bigram k (-1) x y) . chunk 2

encode :: String -&gt; String -&gt; String
encode k = encode' (key k) . process

decode :: String -&gt; String -&gt; String
decode k = decode' (key k) . process

main :: IO ()
main = do print $ encode &quot;PLAYFAIR&quot; &quot;PROGRAMMING PRAXIS&quot;
          print $ decode &quot;PLAYFAIR&quot; &quot;LIVOBLKZEDOELIYWCN&quot;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Programming Praxis &#8211; The Playfair Cipher &#171; Bonsai Code</title>
		<link>http://programmingpraxis.com/2009/07/03/the-playfair-cipher/#comment-274</link>
		<dc:creator><![CDATA[Programming Praxis &#8211; The Playfair Cipher &#171; Bonsai Code]]></dc:creator>
		<pubDate>Fri, 03 Jul 2009 12:59:54 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=902#comment-274</guid>
		<description><![CDATA[[...] Praxis &#8211; The Playfair&#160;Cipher By Remco Niemeijer  Today’s Programming Praxis problem is about the Playfair Cipher, a way of encrypting messages that was used [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Praxis &#8211; The Playfair&nbsp;Cipher By Remco Niemeijer  Today’s Programming Praxis problem is about the Playfair Cipher, a way of encrypting messages that was used [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

