<?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: Bifid Cipher</title>
	<atom:link href="http://programmingpraxis.com/2009/10/13/bifid-cipher/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Wed, 17 Mar 2010 13:18:44 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rudi Angela</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-715</link>
		<dc:creator>Rudi Angela</dc:creator>
		<pubDate>Thu, 22 Oct 2009 18:57:01 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-715</guid>
		<description>Here&#039;s an implementation in Erlang. Source file:
-module(bifid).
-export([encode/1, decode/1]).

encode(Source) -&gt;
	frompoints(makecolumns(flattenrows(topoints(Source)))).
	
decode(Source) -&gt;
	frompoints(unflattenrows(flattencolumns(topoints(Source)))).

% flattenrows(PointsList)
% flattens a list of two-integer tuples [{X1, Y1}, {X2, Y2} ... ]
% into a list of ints [X1, X2, ... Y1, Y2, ...]
flattenrows(Points) -&gt;
	[X &#124;&#124; {X,_} &lt;- Points] ++ [Y &#124;&#124; {_,Y}  
	makepoints(lists:split(length(List) div 2, List), []).

% makepoints({IntsList1, IntsList2}, AccumulatorList)
% Helper function for makepoints, that does most of the work
% Joins corresponding items of the two input lists to two-integer
% tuples and ads the result to accumulator list
% at the end the accumulator list is reversed to get the right order
makepoints({[], _}, Acc) -&gt; lists:reverse(Acc);
makepoints({[X &#124; Xlist], [Y &#124; Ylist]}, Acc) -&gt;
	makepoints({Xlist, Ylist}, [{X, Y} &#124; Acc]).

% flattencolumns(PointsList)
% flattens a list of two-integer tuples [{X1, Y1}, {X2, Y2} ... ]
% into a list of ints [X1, Y1, X2, Y2, ...]
flattencolumns(List) -&gt; flattencolumns(List, []).
flattencolumns([], Acc) -&gt; lists:reverse(Acc);
flattencolumns([{X, Y} &#124; Tail], Acc) -&gt;
	flattencolumns(Tail, [Y &#124; [X &#124; Acc]]). % will be reversed
	
% makecolumns(IntegersList)
% does the inverse operation of flattencolumns
makecolumns(List) -&gt; makecolumns(List, []).

makecolumns([], Acc) -&gt; lists:reverse(Acc);
makecolumns([X &#124; [Y &#124; Tail]], Acc) -&gt;
	makecolumns(Tail, [{X, Y} &#124; Acc]).

% topoints(String, Encoding)
% calculates the two-integer tuple that represents a character
% in the given encoding
topoints(Source, {Key, Period}) -&gt;
	[divrem( indexof(Char, Key), Period) &#124;&#124; Char 
	frompoints(Source, Key, Period, []).
frompoints([], _Key, _Period, Accumulator) -&gt; lists:reverse(Accumulator);
frompoints([{X, Y} &#124; Tail], Key, Period, Accumulator) -&gt; 
		Index = (X-1) * Period + (Y),
		Char = lists:nth(Index, Key),
		frompoints(Tail, Key, Period, [Char &#124; Accumulator]);
frompoints(Any, _, _, Acc) -&gt;
	io:format(&quot;Error: ~p, ~p~n&quot;, [Any, Acc]),
	Acc.

% divrem(X, Y)
% function to X div Y and X rem Y and return both as a tuple {Div, Rem}
% both values are offset by 1 for convenience
divrem(X, Y) -&gt; divrem(X, Y, 0).
divrem(X, Y, Acc) when X  {Acc+1, X+1};
divrem(X, Y, Acc) -&gt; divrem(X - Y, Y, Acc + 1).

% indexof(List, Item)
% As Erlang has no array data type we have to use linked lists.
% The lists module does not have a function to calculate the index
% of an item so here is my implementation.
indexof(Item, List) -&gt; indexof(Item, List, 0).
indexof(_Item, [], Start) -&gt; Start;
indexof(Item, [Head &#124; Tail], Start) -&gt;
	if 	Item =:= Head -&gt; Start;
		true -&gt; indexof(Item, Tail, Start + 1)
	end.

% encoding()
% convenience method for testing
encoding() -&gt; {&quot;ABCDEFGHIKLMNOPQRSTUVWXYZ&quot;, 5}.

% topoints(List)
% convenience method for testing
topoints(Source) -&gt; topoints(Source, encoding()).

% frompoints(Source)
% convenience method for testing
frompoints(Source) -&gt; frompoints(Source, encoding()).

In the erlang shell you can then enter:
1&gt; c(bifid).
{ok,bifid}
2&gt; bifid:encode(&quot;PROGRAMMINGPRAXIS&quot;).
&quot;OMQNHHQWUIGBIMWCS&quot;
3&gt; E = bifid:encode(&quot;PROGRAMMINGPRAXIS&quot;).
&quot;OMQNHHQWUIGBIMWCS&quot;
4&gt; bifid:decode(E).
&quot;PROGRAMMINGPRAXIS&quot;</description>
		<content:encoded><![CDATA[<p>Here&#8217;s an implementation in Erlang. Source file:<br />
-module(bifid).<br />
-export([encode/1, decode/1]).</p>
<p>encode(Source) -&gt;<br />
	frompoints(makecolumns(flattenrows(topoints(Source)))).</p>
<p>decode(Source) -&gt;<br />
	frompoints(unflattenrows(flattencolumns(topoints(Source)))).</p>
<p>% flattenrows(PointsList)<br />
% flattens a list of two-integer tuples [{X1, Y1}, {X2, Y2} ... ]<br />
% into a list of ints [X1, X2, ... Y1, Y2, ...]<br />
flattenrows(Points) -&gt;<br />
	[X || {X,_} &lt;- Points] ++ [Y || {_,Y}<br />
	makepoints(lists:split(length(List) div 2, List), []).</p>
<p>% makepoints({IntsList1, IntsList2}, AccumulatorList)<br />
% Helper function for makepoints, that does most of the work<br />
% Joins corresponding items of the two input lists to two-integer<br />
% tuples and ads the result to accumulator list<br />
% at the end the accumulator list is reversed to get the right order<br />
makepoints({[], _}, Acc) -&gt; lists:reverse(Acc);<br />
makepoints({[X | Xlist], [Y | Ylist]}, Acc) -&gt;<br />
	makepoints({Xlist, Ylist}, [{X, Y} | Acc]).</p>
<p>% flattencolumns(PointsList)<br />
% flattens a list of two-integer tuples [{X1, Y1}, {X2, Y2} ... ]<br />
% into a list of ints [X1, Y1, X2, Y2, ...]<br />
flattencolumns(List) -&gt; flattencolumns(List, []).<br />
flattencolumns([], Acc) -&gt; lists:reverse(Acc);<br />
flattencolumns([{X, Y} | Tail], Acc) -&gt;<br />
	flattencolumns(Tail, [Y | [X | Acc]]). % will be reversed</p>
<p>% makecolumns(IntegersList)<br />
% does the inverse operation of flattencolumns<br />
makecolumns(List) -&gt; makecolumns(List, []).</p>
<p>makecolumns([], Acc) -&gt; lists:reverse(Acc);<br />
makecolumns([X | [Y | Tail]], Acc) -&gt;<br />
	makecolumns(Tail, [{X, Y} | Acc]).</p>
<p>% topoints(String, Encoding)<br />
% calculates the two-integer tuple that represents a character<br />
% in the given encoding<br />
topoints(Source, {Key, Period}) -&gt;<br />
	[divrem( indexof(Char, Key), Period) || Char<br />
	frompoints(Source, Key, Period, []).<br />
frompoints([], _Key, _Period, Accumulator) -&gt; lists:reverse(Accumulator);<br />
frompoints([{X, Y} | Tail], Key, Period, Accumulator) -&gt;<br />
		Index = (X-1) * Period + (Y),<br />
		Char = lists:nth(Index, Key),<br />
		frompoints(Tail, Key, Period, [Char | Accumulator]);<br />
frompoints(Any, _, _, Acc) -&gt;<br />
	io:format(&#8220;Error: ~p, ~p~n&#8221;, [Any, Acc]),<br />
	Acc.</p>
<p>% divrem(X, Y)<br />
% function to X div Y and X rem Y and return both as a tuple {Div, Rem}<br />
% both values are offset by 1 for convenience<br />
divrem(X, Y) -&gt; divrem(X, Y, 0).<br />
divrem(X, Y, Acc) when X  {Acc+1, X+1};<br />
divrem(X, Y, Acc) -&gt; divrem(X &#8211; Y, Y, Acc + 1).</p>
<p>% indexof(List, Item)<br />
% As Erlang has no array data type we have to use linked lists.<br />
% The lists module does not have a function to calculate the index<br />
% of an item so here is my implementation.<br />
indexof(Item, List) -&gt; indexof(Item, List, 0).<br />
indexof(_Item, [], Start) -&gt; Start;<br />
indexof(Item, [Head | Tail], Start) -&gt;<br />
	if 	Item =:= Head -&gt; Start;<br />
		true -&gt; indexof(Item, Tail, Start + 1)<br />
	end.</p>
<p>% encoding()<br />
% convenience method for testing<br />
encoding() -&gt; {&#8220;ABCDEFGHIKLMNOPQRSTUVWXYZ&#8221;, 5}.</p>
<p>% topoints(List)<br />
% convenience method for testing<br />
topoints(Source) -&gt; topoints(Source, encoding()).</p>
<p>% frompoints(Source)<br />
% convenience method for testing<br />
frompoints(Source) -&gt; frompoints(Source, encoding()).</p>
<p>In the erlang shell you can then enter:<br />
1&gt; c(bifid).<br />
{ok,bifid}<br />
2&gt; bifid:encode(&#8220;PROGRAMMINGPRAXIS&#8221;).<br />
&#8220;OMQNHHQWUIGBIMWCS&#8221;<br />
3&gt; E = bifid:encode(&#8220;PROGRAMMINGPRAXIS&#8221;).<br />
&#8220;OMQNHHQWUIGBIMWCS&#8221;<br />
4&gt; bifid:decode(E).<br />
&#8220;PROGRAMMINGPRAXIS&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fb</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-714</link>
		<dc:creator>fb</dc:creator>
		<pubDate>Thu, 22 Oct 2009 18:45:44 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-714</guid>
		<description>My J solution:

[sourcecode lang=&quot;css&quot;]
pre=:(]-&gt;&amp;9)@-&amp;65@(a.&amp;i.@toupper)
enc=:&#124;:@((%&amp;2@#,2:)$[)@(&lt;.@%&amp;5,5&amp;&#124;)
dec=:((2:,%&amp;2@#)$[)@(&lt;.@%&amp;5,@,.5&amp;&#124;)
pst=:{&amp;a.@(]-&lt;&amp;75)@(5&amp;*@[/+66&amp;+@]/)

encode=:pst@enc@pre
decode=:pst@dec@pre
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>My J solution:</p>
<pre class="brush: css;">
pre=:(]-&gt;&amp;9)@-&amp;65@(a.&amp;i.@toupper)
enc=:|:@((%&amp;2@#,2:)$[)@(&lt;.@%&amp;5,5&amp;|)
dec=:((2:,%&amp;2@#)$[)@(&lt;.@%&amp;5,@,.5&amp;|)
pst=:{&amp;a.@(]-&lt;&amp;75)@(5&amp;*@[/+66&amp;+@]/)

encode=:pst@enc@pre
decode=:pst@dec@pre
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: DotNetter</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-709</link>
		<dc:creator>DotNetter</dc:creator>
		<pubDate>Wed, 21 Oct 2009 07:25:56 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-709</guid>
		<description>Another C# soln. 

public class Bifid
	{
		string[,] KeyMatrix = new string[5,5];

		public Bifid()
		{
			BuildKeyMatrix();
		}

		private void BuildKeyMatrix()
		{
			int k = 65;
			for(int i = 0; i &lt;5; i++)
			{
				for(int j = 0; j&lt;5; j++)
				{			
					if(k==74) {k++;} // Dont take j (j ascii = 64)
					KeyMatrix[i,j] = ((char)k).ToString();
					k++;
				}
			}
		}

		public string EncryptDecrypt(string Text, bool Encrypt)
		{
			int k = 0;
			string CharofMessage = string.Empty;
			StringBuilder sb1 = new StringBuilder();
			StringBuilder sb2 = new StringBuilder();
			StringBuilder sbOut = new StringBuilder();
			bool HasGotChar = false;
			
			while(k &lt; Text.Length)
			{
				CharofMessage = Text.Substring(k,1); 
				for(int i = 0; i &lt;5; i++)
				{					
					for(int j = 0; j&lt;5; j++)
					{
						if(string.Compare(KeyMatrix[i,j],CharofMessage, true) == 0)
						{
							sb1.Append(i.ToString()); 
							if(Encrypt)
								sb2.Append(j.ToString()); //Use separate string builder for encrypt - ease of coding :-)
							else
								sb1.Append(j.ToString());
							HasGotChar = true;
							break;
						}
					}
					if(HasGotChar) // exit the loop if we hit the character
					{
						HasGotChar = false;
						break;
					}
				}
				k++;
			}
			
			k = 0;	
			
			if(Encrypt)
			{
				sb1.Append(sb2.ToString()); // combine both
				while(k &lt; sb1.Length)
				{
					sbOut.Append( KeyMatrix[Convert.ToInt32(sb1[k].ToString()),Convert.ToInt32(sb1[k+1].ToString())]);
					k += 2;
				}
			}
			else
			{
				int SplitNum = (sb1.Length) / 2;
				while(k &lt; SplitNum)
				{
					sbOut.Append( KeyMatrix[Convert.ToInt32(sb1[k].ToString()),Convert.ToInt32(sb1[k + SplitNum].ToString())]);
					k ++;
				}
			}
			
			return sbOut.ToString();
		}
	}</description>
		<content:encoded><![CDATA[<p>Another C# soln. </p>
<p>public class Bifid<br />
	{<br />
		string[,] KeyMatrix = new string[5,5];</p>
<p>		public Bifid()<br />
		{<br />
			BuildKeyMatrix();<br />
		}</p>
<p>		private void BuildKeyMatrix()<br />
		{<br />
			int k = 65;<br />
			for(int i = 0; i &lt;5; i++)<br />
			{<br />
				for(int j = 0; j&lt;5; j++)<br />
				{<br />
					if(k==74) {k++;} // Dont take j (j ascii = 64)<br />
					KeyMatrix[i,j] = ((char)k).ToString();<br />
					k++;<br />
				}<br />
			}<br />
		}</p>
<p>		public string EncryptDecrypt(string Text, bool Encrypt)<br />
		{<br />
			int k = 0;<br />
			string CharofMessage = string.Empty;<br />
			StringBuilder sb1 = new StringBuilder();<br />
			StringBuilder sb2 = new StringBuilder();<br />
			StringBuilder sbOut = new StringBuilder();<br />
			bool HasGotChar = false;</p>
<p>			while(k &lt; Text.Length)<br />
			{<br />
				CharofMessage = Text.Substring(k,1);<br />
				for(int i = 0; i &lt;5; i++)<br />
				{<br />
					for(int j = 0; j&lt;5; j++)<br />
					{<br />
						if(string.Compare(KeyMatrix[i,j],CharofMessage, true) == 0)<br />
						{<br />
							sb1.Append(i.ToString());<br />
							if(Encrypt)<br />
								sb2.Append(j.ToString()); //Use separate string builder for encrypt &#8211; ease of coding :-)<br />
							else<br />
								sb1.Append(j.ToString());<br />
							HasGotChar = true;<br />
							break;<br />
						}<br />
					}<br />
					if(HasGotChar) // exit the loop if we hit the character<br />
					{<br />
						HasGotChar = false;<br />
						break;<br />
					}<br />
				}<br />
				k++;<br />
			}</p>
<p>			k = 0;	</p>
<p>			if(Encrypt)<br />
			{<br />
				sb1.Append(sb2.ToString()); // combine both<br />
				while(k &lt; sb1.Length)<br />
				{<br />
					sbOut.Append( KeyMatrix[Convert.ToInt32(sb1[k].ToString()),Convert.ToInt32(sb1[k+1].ToString())]);<br />
					k += 2;<br />
				}<br />
			}<br />
			else<br />
			{<br />
				int SplitNum = (sb1.Length) / 2;<br />
				while(k &lt; SplitNum)<br />
				{<br />
					sbOut.Append( KeyMatrix[Convert.ToInt32(sb1[k].ToString()),Convert.ToInt32(sb1[k + SplitNum].ToString())]);<br />
					k ++;<br />
				}<br />
			}</p>
<p>			return sbOut.ToString();<br />
		}<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Explore Clojure: Building a Bifid cipher &#171; Reminiscential: of or pertaining to remembrance</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-703</link>
		<dc:creator>Explore Clojure: Building a Bifid cipher &#171; Reminiscential: of or pertaining to remembrance</dc:creator>
		<pubDate>Tue, 20 Oct 2009 17:28:27 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-703</guid>
		<description>[...] best way to learn a language is to use it to solve some non-trivial practical problems. I stumbled this problem on Programming Praxis. It&#8217;s about building a Bifid cipher, which I thought could be a [...]</description>
		<content:encoded><![CDATA[<p>[...] best way to learn a language is to use it to solve some non-trivial practical problems. I stumbled this problem on Programming Praxis. It&#8217;s about building a Bifid cipher, which I thought could be a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Qiu</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-701</link>
		<dc:creator>Kevin Qiu</dc:creator>
		<pubDate>Tue, 20 Oct 2009 02:41:35 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-701</guid>
		<description>In Clojure:

[sourcecode lang=&quot;css&quot;]
(ns bifid
  (:gen-class))
 
 
(defn polybius-square
  &quot;Polybius square by the given charset and size&quot;
  [charset square-size]
  (map #(vector %1 [%2 %3]) charset
    (for [x (range 1 (+ 1 square-size)), y (range 1 (+ 1 square-size))] x)
    (take (count charset) (cycle (range 1 (+ 1 square-size))))))
 
(defn- letter-2-code
  &quot;Produce a mapping between letters and their codes&quot;
  [square]
  (letfn [(helper [the-square the-map]
          (if (empty? the-square)
            the-map
            (let [the-item (first the-square)
                  the-key (first the-item)
                  the-number (second the-item)]
              (recur (rest the-square) (assoc the-map the-key the-number)))))]
    (helper square (empty hash-map))))
 
(defn- transposed-2-letter
  &quot;Produce a mapping between the transposed codes to letter&quot;
  [square]
  (letfn [(helper [the-square the-map]
            (if (empty? the-square)
              the-map
              (let [the-item (first the-square)
                    the-key (second the-item)
                    the-letter (first the-item)]
                (recur (rest the-square) (assoc the-map the-key the-letter)))))]
    (helper square (empty hash-map))))
 
(defn encode
  &quot;Return the message encoded by the specified polybius-square&quot;
  [message polybius-square]
  (let [l2c (letter-2-code polybius-square)
        tr2l (transposed-2-letter polybius-square)]
    (apply str
      (map #(get tr2l % %) (partition 2 (apply interleave (map #(get l2c % %) message)))))))
 
(defn decode
  &quot;Return the decoded message using the specified polybius-square&quot;
  [encoded polybius-square]
  (let [l2c (letter-2-code polybius-square)
        c2l (transposed-2-letter polybius-square)
        codes (apply concat (map #(get l2c % %) encoded))
        len (count codes)
        parts (partition (/ len 2) codes)]
    (apply str (map #(get c2l %1 %1) (map #(vector %1 %2) (first parts) (second parts))))))
 
(defn -main
  &quot;A simple test case entry point&quot;
  []
  (let [square (polybius-square &quot;ABCDEFGHIKLMNOPQRSTUVWXYZ&quot; 5)]
    (do
        (println (encode &quot;PROGRAMMINGPRAXIS&quot; square))
        (println (decode &quot;OMQNHHQWUIGBIMWCS&quot; square)))))
[/sourcecode]</description>
		<content:encoded><![CDATA[<p>In Clojure:</p>
<pre class="brush: css;">
(ns bifid
  (:gen-class))

(defn polybius-square
  &quot;Polybius square by the given charset and size&quot;
  [charset square-size]
  (map #(vector %1 [%2 %3]) charset
    (for [x (range 1 (+ 1 square-size)), y (range 1 (+ 1 square-size))] x)
    (take (count charset) (cycle (range 1 (+ 1 square-size))))))

(defn- letter-2-code
  &quot;Produce a mapping between letters and their codes&quot;
  [square]
  (letfn [(helper [the-square the-map]
          (if (empty? the-square)
            the-map
            (let [the-item (first the-square)
                  the-key (first the-item)
                  the-number (second the-item)]
              (recur (rest the-square) (assoc the-map the-key the-number)))))]
    (helper square (empty hash-map))))

(defn- transposed-2-letter
  &quot;Produce a mapping between the transposed codes to letter&quot;
  [square]
  (letfn [(helper [the-square the-map]
            (if (empty? the-square)
              the-map
              (let [the-item (first the-square)
                    the-key (second the-item)
                    the-letter (first the-item)]
                (recur (rest the-square) (assoc the-map the-key the-letter)))))]
    (helper square (empty hash-map))))

(defn encode
  &quot;Return the message encoded by the specified polybius-square&quot;
  [message polybius-square]
  (let [l2c (letter-2-code polybius-square)
        tr2l (transposed-2-letter polybius-square)]
    (apply str
      (map #(get tr2l % %) (partition 2 (apply interleave (map #(get l2c % %) message)))))))

(defn decode
  &quot;Return the decoded message using the specified polybius-square&quot;
  [encoded polybius-square]
  (let [l2c (letter-2-code polybius-square)
        c2l (transposed-2-letter polybius-square)
        codes (apply concat (map #(get l2c % %) encoded))
        len (count codes)
        parts (partition (/ len 2) codes)]
    (apply str (map #(get c2l %1 %1) (map #(vector %1 %2) (first parts) (second parts))))))

(defn -main
  &quot;A simple test case entry point&quot;
  []
  (let [square (polybius-square &quot;ABCDEFGHIKLMNOPQRSTUVWXYZ&quot; 5)]
    (do
        (println (encode &quot;PROGRAMMINGPRAXIS&quot; square))
        (println (decode &quot;OMQNHHQWUIGBIMWCS&quot; square)))))
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete Jones</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-698</link>
		<dc:creator>Pete Jones</dc:creator>
		<pubDate>Sun, 18 Oct 2009 20:01:45 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-698</guid>
		<description>Javascript using a 6x6 square.

http://pastebin.com/f44f6043c</description>
		<content:encoded><![CDATA[<p>Javascript using a 6&#215;6 square.</p>
<p><a href="http://pastebin.com/f44f6043c" rel="nofollow">http://pastebin.com/f44f6043c</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-696</link>
		<dc:creator>Christopher</dc:creator>
		<pubDate>Sat, 17 Oct 2009 13:14:18 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-696</guid>
		<description>A ruby solution

class String
  def bifid_encipher
    self.gsub!(/[^A-Za-z]/,&#039;&#039;)
    stringify coordinates.transpose.flatten.each_slice(2)
  end

  def bifid_decipher
    stringify coordinates.flatten.each_slice(self.size).to_a.transpose
  end
  
  protected
    def coordinates
      self.upcase.split(//).inject([]) do &#124;a, char&#124;
        polybius_square.each_with_index do &#124;array, i&#124;
          a &lt;&lt; [i, $_] if $_ = array =~ /#{char}/
        end

        a
      end
    end

    def stringify(message)
      message.map { &#124;k,v&#124; &quot;%c&quot; % polybius_square[k][v] }.to_s
    end
    
    def polybius_square
      @square &#124;&#124;= ((&#039;A&#039;..&#039;Z&#039;).to_a - %w(J)).each_slice(5).map { &#124;a&#124; a.join }
    end
end</description>
		<content:encoded><![CDATA[<p>A ruby solution</p>
<p>class String<br />
  def bifid_encipher<br />
    self.gsub!(/[^A-Za-z]/,&#8221;)<br />
    stringify coordinates.transpose.flatten.each_slice(2)<br />
  end</p>
<p>  def bifid_decipher<br />
    stringify coordinates.flatten.each_slice(self.size).to_a.transpose<br />
  end</p>
<p>  protected<br />
    def coordinates<br />
      self.upcase.split(//).inject([]) do |a, char|<br />
        polybius_square.each_with_index do |array, i|<br />
          a &lt;&lt; [i, $_] if $_ = array =~ /#{char}/<br />
        end</p>
<p>        a<br />
      end<br />
    end</p>
<p>    def stringify(message)<br />
      message.map { |k,v| &quot;%c&quot; % polybius_square[k][v] }.to_s<br />
    end</p>
<p>    def polybius_square<br />
      @square ||= ((&#039;A&#039;..&#039;Z&#039;).to_a &#8211; %w(J)).each_slice(5).map { |a| a.join }<br />
    end<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paulc</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-691</link>
		<dc:creator>Paulc</dc:creator>
		<pubDate>Fri, 16 Oct 2009 21:41:55 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-691</guid>
		<description>Here is another version in Python (a bit more object oriented)

http://vpaste.net/nksKf?</description>
		<content:encoded><![CDATA[<p>Here is another version in Python (a bit more object oriented)</p>
<p><a href="http://vpaste.net/nksKf?" rel="nofollow">http://vpaste.net/nksKf?</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leftware</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-690</link>
		<dc:creator>Leftware</dc:creator>
		<pubDate>Fri, 16 Oct 2009 21:41:48 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-690</guid>
		<description>This is my dirty C# implementation:

		public static string Bifid(string entrada) {
			var filas = &quot;1111122222333334444455555&quot;;
			var cols = &quot;1234512345123451234512345&quot;;
			var alfa = &quot;abcdefghiklmnopqrstuvwxyz&quot;;

			entrada = entrada.ToLower();

			var arr1 = new char[entrada.Length];
			var arr2 = new char[entrada.Length];

			for (int i = 0; i &lt; entrada.Length; i++) {
				var ind = alfa.IndexOf(entrada[i]);
				arr1[i] = filas[ind];
				arr2[i] = cols[ind];
			}
			var arr3 = new char[entrada.Length * 2];
			Array.ConstrainedCopy(arr1, 0, arr3, 0, arr1.Length);
			Array.ConstrainedCopy(arr2, 0, arr3, arr1.Length, arr2.Length);
			var sb = new StringBuilder();
			for (int i = 0; i &lt; arr3.Length; i += 2) {
				var sf = filas.IndexOf(arr3[i]);
				var sc = cols.IndexOf(arr3[i + 1], sf);
				sb.Append(alfa[sc]);
			}

			return sb.ToString();
		}</description>
		<content:encoded><![CDATA[<p>This is my dirty C# implementation:</p>
<p>		public static string Bifid(string entrada) {<br />
			var filas = &#8220;1111122222333334444455555&#8243;;<br />
			var cols = &#8220;1234512345123451234512345&#8243;;<br />
			var alfa = &#8220;abcdefghiklmnopqrstuvwxyz&#8221;;</p>
<p>			entrada = entrada.ToLower();</p>
<p>			var arr1 = new char[entrada.Length];<br />
			var arr2 = new char[entrada.Length];</p>
<p>			for (int i = 0; i &lt; entrada.Length; i++) {<br />
				var ind = alfa.IndexOf(entrada[i]);<br />
				arr1[i] = filas[ind];<br />
				arr2[i] = cols[ind];<br />
			}<br />
			var arr3 = new char[entrada.Length * 2];<br />
			Array.ConstrainedCopy(arr1, 0, arr3, 0, arr1.Length);<br />
			Array.ConstrainedCopy(arr2, 0, arr3, arr1.Length, arr2.Length);<br />
			var sb = new StringBuilder();<br />
			for (int i = 0; i &lt; arr3.Length; i += 2) {<br />
				var sf = filas.IndexOf(arr3[i]);<br />
				var sc = cols.IndexOf(arr3[i + 1], sf);<br />
				sb.Append(alfa[sc]);<br />
			}</p>
<p>			return sb.ToString();<br />
		}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnar</title>
		<link>http://programmingpraxis.com/2009/10/13/bifid-cipher/#comment-689</link>
		<dc:creator>Arnar</dc:creator>
		<pubDate>Fri, 16 Oct 2009 21:30:21 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1443#comment-689</guid>
		<description>Hm, sorry about code formatting (can it be fixed?).

Here&#039;s the code: http://pastie.org/658185</description>
		<content:encoded><![CDATA[<p>Hm, sorry about code formatting (can it be fixed?).</p>
<p>Here&#8217;s the code: <a href="http://pastie.org/658185" rel="nofollow">http://pastie.org/658185</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
