<?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: Autokey</title>
	<atom:link href="http://programmingpraxis.com/2009/12/04/autokey/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/12/04/autokey/</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Mon, 28 May 2012 03:30:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Adam Thomas</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-846</link>
		<dc:creator><![CDATA[Adam Thomas]]></dc:creator>
		<pubDate>Thu, 17 Dec 2009 13:30:17 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-846</guid>
		<description><![CDATA[The solution I posted above is implemented in C.]]></description>
		<content:encoded><![CDATA[<p>The solution I posted above is implemented in C.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Thomas</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-845</link>
		<dc:creator><![CDATA[Adam Thomas]]></dc:creator>
		<pubDate>Thu, 17 Dec 2009 13:25:51 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-845</guid>
		<description><![CDATA[[sourcecode lang=&quot;C&quot;]
/*
 * Obtaining the encrypted character from the dictionary:
 * a - plain text character
 * b - cipher key character
 * x - first character in dictionary (&#039;A&#039;)
 * z - size of dictionary (26)
 *
 * y = x + (a + b - 2 * x) % z
 */
char* encrypt(const char *txt, const char* key, char *enc)
{
	unsigned i, len;
	for (i = 0, len = strlen(txt); i &lt; len; i++) {
		enc[i] = &#039;A&#039; + (txt[i] + key[i] - 2 * &#039;A&#039;) % 26;
	}
	return enc;
}

/*
 * Obtaining the decrypted character from the dictionary:
 * a - encrypted character
 * b - cipher key character
 * x - first character in dictionary (&#039;A&#039;)
 * z - size of dictionary (26)
 *
 * y = x + (a - b + z) % z
 */
char* decrypt(const char *enc, const char *key, char *dec)
{
	unsigned i, len;
	for (i = 0, len = strlen(enc); i &lt; len; i++) {
		dec[i] = &#039;A&#039; + (enc[i] - key[i] + 26) % 26;
	}
	return dec;
}
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<pre class="brush: cpp;">
/*
 * Obtaining the encrypted character from the dictionary:
 * a - plain text character
 * b - cipher key character
 * x - first character in dictionary ('A')
 * z - size of dictionary (26)
 *
 * y = x + (a + b - 2 * x) % z
 */
char* encrypt(const char *txt, const char* key, char *enc)
{
	unsigned i, len;
	for (i = 0, len = strlen(txt); i &lt; len; i++) {
		enc[i] = 'A' + (txt[i] + key[i] - 2 * 'A') % 26;
	}
	return enc;
}

/*
 * Obtaining the decrypted character from the dictionary:
 * a - encrypted character
 * b - cipher key character
 * x - first character in dictionary ('A')
 * z - size of dictionary (26)
 *
 * y = x + (a - b + z) % z
 */
char* decrypt(const char *enc, const char *key, char *dec)
{
	unsigned i, len;
	for (i = 0, len = strlen(enc); i &lt; len; i++) {
		dec[i] = 'A' + (enc[i] - key[i] + 26) % 26;
	}
	return dec;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-836</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Tue, 15 Dec 2009 21:09:38 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-836</guid>
		<description><![CDATA[Fixed!]]></description>
		<content:encoded><![CDATA[<p>Fixed!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gramie</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-835</link>
		<dc:creator><![CDATA[gramie]]></dc:creator>
		<pubDate>Tue, 15 Dec 2009 21:03:58 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-835</guid>
		<description><![CDATA[&gt; invented by Blaise de Vigenère in 1586, over five hundred years ago

Wow, I really must have overslept this morning! I could have sworn it was only 2009!]]></description>
		<content:encoded><![CDATA[<p>&gt; invented by Blaise de Vigenère in 1586, over five hundred years ago</p>
<p>Wow, I really must have overslept this morning! I could have sworn it was only 2009!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: agilefall</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-818</link>
		<dc:creator><![CDATA[agilefall]]></dc:creator>
		<pubDate>Sat, 05 Dec 2009 20:49:08 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-818</guid>
		<description><![CDATA[Here is a scala version:

class&#160;Crypt(key:&#160;String)&#160;{
&#160;&#160;private&#160;def&#160;convert(s:&#160;String,&#160;converter:&#160;(Char,&#160;Char)=&gt;Int)&#160;=&#160;{
&#160;&#160;&#160;&#160;new&#160;String(
&#160;&#160;&#160;&#160;&#160;&#160;(0&#160;until&#160;plain.length).map(
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ix&#160;=&gt;&#160;(converter(s(ix),key(ix&#160;%&#160;key.length))&#160;%&#160;26&#160;+&#160;&#039;A&#039;).toChar
&#160;&#160;&#160;&#160;&#160;&#160;).toArray)
&#160;&#160;}
&#160;&#160;
&#160;&#160;def&#160;encrypt(plain:&#160;String)&#160;=&#160;convert(plain,&#160;(a:&#160;Char,&#160;b:&#160;Char)=&gt;&#160;a&#160;+&#160;b)
&#160;&#160;def&#160;decrypt(encrypted:&#160;String)&#160;=&#160;convert(encrypted,&#160;(a:&#160;Char,&#160;b:&#160;Char)&#160;=&gt;&#160;a&#160;-&#160;b&#160;+&#160;26)
}]]></description>
		<content:encoded><![CDATA[<p>Here is a scala version:</p>
<p>class&nbsp;Crypt(key:&nbsp;String)&nbsp;{<br />
&nbsp;&nbsp;private&nbsp;def&nbsp;convert(s:&nbsp;String,&nbsp;converter:&nbsp;(Char,&nbsp;Char)=&gt;Int)&nbsp;=&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;new&nbsp;String(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(0&nbsp;until&nbsp;plain.length).map(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ix&nbsp;=&gt;&nbsp;(converter(s(ix),key(ix&nbsp;%&nbsp;key.length))&nbsp;%&nbsp;26&nbsp;+&nbsp;&#8217;A').toChar<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;).toArray)<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;def&nbsp;encrypt(plain:&nbsp;String)&nbsp;=&nbsp;convert(plain,&nbsp;(a:&nbsp;Char,&nbsp;b:&nbsp;Char)=&gt;&nbsp;a&nbsp;+&nbsp;b)<br />
&nbsp;&nbsp;def&nbsp;decrypt(encrypted:&nbsp;String)&nbsp;=&nbsp;convert(encrypted,&nbsp;(a:&nbsp;Char,&nbsp;b:&nbsp;Char)&nbsp;=&gt;&nbsp;a&nbsp;-&nbsp;b&nbsp;+&nbsp;26)<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Autokey &#124; Andrew Ferguson</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-817</link>
		<dc:creator><![CDATA[Autokey &#124; Andrew Ferguson]]></dc:creator>
		<pubDate>Sat, 05 Dec 2009 02:09:15 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-817</guid>
		<description><![CDATA[[...] programming puzzles from time to time. I&#8217;m also going to try work these problems using Perl. Today&#8217;s assignment is to make a simple Autokey Cipher, which I accomplished over my lunch [...]]]></description>
		<content:encoded><![CDATA[<p>[...] programming puzzles from time to time. I&#8217;m also going to try work these problems using Perl. Today&#8217;s assignment is to make a simple Autokey Cipher, which I accomplished over my lunch [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gierad</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-816</link>
		<dc:creator><![CDATA[Gierad]]></dc:creator>
		<pubDate>Fri, 04 Dec 2009 21:20:55 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-816</guid>
		<description><![CDATA[Here&#039;s a quick PHP Solution:

[code lang=&quot;php&quot;]
function encrypt($str, $key)
{
	$out = &quot;&quot;;
	for ($i=0; $i&lt;strlen($str); $i++)
	{
		$base = ord($str[$i]) - 65;	  // take index of base string
		$offset = ord($key[$i]) - 65;	  // take index of key
		$ascii = ($base + $offset) % 26;  // add indices and wrap around 26
		$out .= chr(65 + $ascii);	  // add 65 to indices to display ASCII
	}		
	return $out;
}

function decrypt($str,$key)
{
	$out = &quot;&quot;;
	for ($i=0; $i&lt;strlen($str); $i++)
	{
		$base = ord($str[$i]) - 65;	// take index of base string
		$offset = ord($key[$i]) - 65;   // take index of key

		// Perform reverse &quot;wrapping&quot;
		$ascii = ($base - $offset);				
		if ($ascii &lt; 0) $ascii = 26 + $ascii;	
		
		$out .= chr(65 + $ascii);	// add 65 to indices to display ASCII
	}		
	return $out;
}
[/code]]]></description>
		<content:encoded><![CDATA[<p>Here&#8217;s a quick PHP Solution:</p>
<pre class="brush: php;">
function encrypt($str, $key)
{
	$out = &quot;&quot;;
	for ($i=0; $i&lt;strlen($str); $i++)
	{
		$base = ord($str[$i]) - 65;	  // take index of base string
		$offset = ord($key[$i]) - 65;	  // take index of key
		$ascii = ($base + $offset) % 26;  // add indices and wrap around 26
		$out .= chr(65 + $ascii);	  // add 65 to indices to display ASCII
	}		
	return $out;
}

function decrypt($str,$key)
{
	$out = &quot;&quot;;
	for ($i=0; $i&lt;strlen($str); $i++)
	{
		$base = ord($str[$i]) - 65;	// take index of base string
		$offset = ord($key[$i]) - 65;   // take index of key

		// Perform reverse &quot;wrapping&quot;
		$ascii = ($base - $offset);				
		if ($ascii &lt; 0) $ascii = 26 + $ascii;	
		
		$out .= chr(65 + $ascii);	// add 65 to indices to display ASCII
	}		
	return $out;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gierad</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-815</link>
		<dc:creator><![CDATA[Gierad]]></dc:creator>
		<pubDate>Fri, 04 Dec 2009 21:19:30 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-815</guid>
		<description><![CDATA[Here&#039;s a quick PHP Solution

&lt;code&gt;
function encrypt($str, $key)
{
	$out = &quot;&quot;;
	for ($i=0; $i&lt;strlen($str); $i++)
	{
		$base = ord($str[$i]) - 65;	 // take index of base string
		$offset = ord($key[$i]) - 65;	 // take index of key
		$ascii = ($base + $offset) % 26; // add indices and wrap around 26
		$out .= chr(65 + $ascii);	 // add 65 to indices to display ASCII
	}		
	return $out;
}

function decrypt($str,$key)
{
	$out = &quot;&quot;;
	for ($i=0; $i&lt;strlen($str); $i++)
	{
		$base = ord($str[$i]) - 65;	// take index of base string
		$offset = ord($key[$i]) - 65;   // take index of key

		// Perform reverse &quot;wrapping&quot;
		$ascii = ($base - $offset);				
		if ($ascii &lt; 0) $ascii = 26 + $ascii;	
		
		$out .= chr(65 + $ascii);	// add 65 to indices to display ASCII
	}		
	return $out;
}
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>Here&#8217;s a quick PHP Solution</p>
<p><code><br />
function encrypt($str, $key)<br />
{<br />
	$out = "";<br />
	for ($i=0; $i&lt;strlen($str); $i++)<br />
	{<br />
		$base = ord($str[$i]) - 65;	 // take index of base string<br />
		$offset = ord($key[$i]) - 65;	 // take index of key<br />
		$ascii = ($base + $offset) % 26; // add indices and wrap around 26<br />
		$out .= chr(65 + $ascii);	 // add 65 to indices to display ASCII<br />
	}<br />
	return $out;<br />
}</p>
<p>function decrypt($str,$key)<br />
{<br />
	$out = &quot;&quot;;<br />
	for ($i=0; $i&lt;strlen($str); $i++)<br />
	{<br />
		$base = ord($str[$i]) - 65;	// take index of base string<br />
		$offset = ord($key[$i]) - 65;   // take index of key</p>
<p>		// Perform reverse &quot;wrapping&quot;<br />
		$ascii = ($base - $offset);<br />
		if ($ascii &lt; 0) $ascii = 26 + $ascii;	</p>
<p>		$out .= chr(65 + $ascii);	// add 65 to indices to display ASCII<br />
	}<br />
	return $out;<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Skrud</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-814</link>
		<dc:creator><![CDATA[Skrud]]></dc:creator>
		<pubDate>Fri, 04 Dec 2009 17:22:17 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-814</guid>
		<description><![CDATA[Here&#039;s a quick Python solution.

[sourcecode lang=&quot;python&quot;]
def encrypt(cleartext,key):
	ciphertext = &quot;&quot;
	key = key + cleartext
	i = 0
	while i &lt; len(cleartext):
		ciphertext += __vig( cleartext[i], key[i] )
		i += 1
	return ciphertext

def decrypt(ciphertext,key):
	cleartext = &quot;&quot;
	i = 0
	while i &lt; len(ciphertext):
		cleartext += __vig( ciphertext[i], key[i % len(key)], True )
		key += cleartext[-1]
		i += 1
	return cleartext

def __rot(l,d):
	# Rotate the letter l by the specified number of degrees (assume uppercase)
	return chr((((ord(l) - ord(&#039;A&#039;)) + d) % 26) + ord(&#039;A&#039;))

def __vig(l,k,inverse=False):
	# Determine the index of key-letter &#039;k&#039; relative to &#039;A&#039; and use that
	# as the number of degrees to rotate by.
	degree = ord(k) - ord(&#039;A&#039;)
	if inverse:
		degree = -degree
	return __rot(l, degree)
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Here&#8217;s a quick Python solution.</p>
<pre class="brush: python;">
def encrypt(cleartext,key):
	ciphertext = &quot;&quot;
	key = key + cleartext
	i = 0
	while i &lt; len(cleartext):
		ciphertext += __vig( cleartext[i], key[i] )
		i += 1
	return ciphertext

def decrypt(ciphertext,key):
	cleartext = &quot;&quot;
	i = 0
	while i &lt; len(ciphertext):
		cleartext += __vig( ciphertext[i], key[i % len(key)], True )
		key += cleartext[-1]
		i += 1
	return cleartext

def __rot(l,d):
	# Rotate the letter l by the specified number of degrees (assume uppercase)
	return chr((((ord(l) - ord('A')) + d) % 26) + ord('A'))

def __vig(l,k,inverse=False):
	# Determine the index of key-letter 'k' relative to 'A' and use that
	# as the number of degrees to rotate by.
	degree = ord(k) - ord('A')
	if inverse:
		degree = -degree
	return __rot(l, degree)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/2009/12/04/autokey/#comment-813</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Fri, 04 Dec 2009 16:20:34 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1743#comment-813</guid>
		<description><![CDATA[Of course it is possible.  But one-time pads are generally more useful for diplomats than spies.  A spy would rather memorize a keyword, or a system of generating a keyword from the daily newspaper, or carry an innocent book for a book cipher, than carry an incriminating one-time pad.  I know Kahn says that in his book, though I can&#039;t cite a specific reference.]]></description>
		<content:encoded><![CDATA[<p>Of course it is possible.  But one-time pads are generally more useful for diplomats than spies.  A spy would rather memorize a keyword, or a system of generating a keyword from the daily newspaper, or carry an innocent book for a book cipher, than carry an incriminating one-time pad.  I know Kahn says that in his book, though I can&#8217;t cite a specific reference.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

