<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx</link><description>Below is a primitive implementation of ROT13 / Ceasar Cipher in F#. In short it is a simple encryption algorithm that works by 'shifting' each letter 13 places. So an 'a' becomes an 'n', a 'b' becomes an 'o', and so on. To decrypt the text you simply</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>F# Zen - ROT13 | Tmao Coders</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9053204</link><pubDate>Sat, 08 Nov 2008 01:40:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9053204</guid><dc:creator>F# Zen - ROT13 | Tmao Coders</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.tmao.info/f-zen-rot13/"&gt;http://www.tmao.info/f-zen-rot13/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9053959</link><pubDate>Sat, 08 Nov 2008 12:23:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9053959</guid><dc:creator>Sergi Mansilla</dc:creator><description>&lt;p&gt;I like how F# makes the algorithm be so simple and elegant, and I didn't know about this super simple way of casting chars into ints, thanks!&lt;/p&gt;
&lt;p&gt;I recently made a F# implementation of Bruce Schneier's Solitaire encryption algorithm, you might want to check it out: &lt;a rel="nofollow" target="_new" href="http://www.sergimansilla.com/blog/?p=24"&gt;http://www.sergimansilla.com/blog/?p=24&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Your opinion will be really appreciated :)&lt;/p&gt;
&lt;p&gt;Thanks for your articles!&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9054538</link><pubDate>Sat, 08 Nov 2008 23:53:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9054538</guid><dc:creator>Robert McCall</dc:creator><description>&lt;p&gt;I feel uneasy about nitpicking like this, but it is even simpler via module [b]Microsoft.FSharp.Core.String[/b]'s [b]map[/b] function:&lt;/p&gt;
&lt;p&gt;[code]let encryptText (s:string) =&lt;/p&gt;
&lt;p&gt; &amp;nbsp;s |&amp;gt; String.map (int &amp;gt;&amp;gt; ((+) 13) &amp;gt;&amp;gt; char)&lt;/p&gt;
&lt;p&gt;let decryptText (s:string) =&lt;/p&gt;
&lt;p&gt; &amp;nbsp;s |&amp;gt; String.map (int &amp;gt;&amp;gt; ((+) -13) &amp;gt;&amp;gt; char)&lt;/p&gt;
&lt;p&gt;[/code]&lt;/p&gt;
&lt;p&gt;And thanks for the first practical (and beautifully elegant) use I've seen so far of fct composition -- I'm sure there are more to be discovered.&lt;/p&gt;
&lt;p&gt;And, officially, everything about F# is tremendous from the lang design to the docs to shipping the source code. &amp;nbsp;You guys have set the new standard for combining high-level cs theory, real-world programmer productivity and exe performance. &amp;nbsp;After 20 years of professional programming (mostly C/C++/C# and various db systems), you guys have me excited about programming again.&lt;/p&gt;
&lt;p&gt;-Robert&lt;/p&gt;
&lt;p&gt;[i]&amp;quot;Lasting Peace and Happiness for [u][b]ALL[/b][/u] human beings.&amp;quot;[/i]&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9056886</link><pubDate>Mon, 10 Nov 2008 08:35:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9056886</guid><dc:creator>Carsten K.</dc:creator><description>&lt;p&gt;well I guess I give my 25cents too:&lt;/p&gt;
&lt;p&gt;You will see a lot of ROT13 &amp;quot;encrypted&amp;quot; messages in the usenet (to &amp;quot;hide&amp;quot; a solution, mark a spoiler etc.). In order to make your code really work there you will have to take care of some cases:&lt;/p&gt;
&lt;p&gt;1) normaly only [a-z], [A-Z] gets encrypted so a-&amp;gt;n, A-&amp;gt;N but !-&amp;gt;! for example.&lt;/p&gt;
&lt;p&gt;2) You don't need a decrypt-function in those cases ;) - it's the same as the encryption function&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9057401</link><pubDate>Mon, 10 Nov 2008 17:03:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9057401</guid><dc:creator>Patrick Dewane</dc:creator><description>&lt;p&gt;At 13 characters, you're already halfway through the alphabet. Meaning you could have just 1 function for encrypting and decrypting.&lt;/p&gt;</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9058266</link><pubDate>Mon, 10 Nov 2008 20:14:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9058266</guid><dc:creator>ChrSmith</dc:creator><description>&lt;p&gt;@Patrick,&lt;/p&gt;
&lt;p&gt;True, but if and only if you modulo the integer value of each character with 26. Since I'm blindly adding 13, 'z' becomes something outside the typical ASCII plane...&lt;/p&gt;
&lt;p&gt;That's exactly why I didn't clame this 'was' an exact implementation of ROT13, but equivocated with 'primitive implementation of ROT13 / Ceasar Cipher'.&lt;/p&gt;
&lt;p&gt;But yes, you are right. If you did the extra work you would only need one function for encrypting and decrypting.&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9060202</link><pubDate>Tue, 11 Nov 2008 16:39:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9060202</guid><dc:creator>Patrick Dewane</dc:creator><description>&lt;p&gt;How does one &amp;quot;read&amp;quot; the line:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Array.map (int &amp;gt;&amp;gt; ((+) 13) &amp;gt;&amp;gt; char)&lt;/p&gt;
&lt;p&gt;I like to apply a natural language to something I'm trying to learn, but I'm not sure of the correct way to say what this is doing.&lt;/p&gt;</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9060556</link><pubDate>Tue, 11 Nov 2008 20:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9060556</guid><dc:creator>ChrSmith</dc:creator><description>&lt;p&gt;That is the beauty of function composition :)&lt;/p&gt;
&lt;p&gt;I'll probabaly need to devote an entire post to concept later, but in short:&lt;/p&gt;
&lt;p&gt;Array.map takes a function which converts the array element to some new value. So in the context of ROT13 transforms a char to a new char.&lt;/p&gt;
&lt;p&gt;[int &amp;gt;&amp;gt; (+) 13 &amp;gt;&amp;gt; char] is actually three functions glued together using the function composition operator (&amp;gt;&amp;gt;).&lt;/p&gt;
&lt;p&gt;[int] takes an input and converts it to an integer, so 'A' is converted to 65.&lt;/p&gt;
&lt;p&gt;[(+) 13] is the (+) function with the first parameter specified as 13, so it is a function that takes an input of an integer and returns 13 plus that integer.&lt;/p&gt;
&lt;p&gt;[char] takes an input and converts it to a character. So 65' is converted to 'A'.&lt;/p&gt;
&lt;p&gt;By composing those three functions [int &amp;gt;&amp;gt; (+) 13 &amp;gt;&amp;gt; char] the result is a new function that takes anything, converts it to an integer, adds 13, and converts that to a character.&lt;/p&gt;
&lt;p&gt;So when applied via Array.map it encrypts the input string. &lt;/p&gt;
&lt;p&gt;Function composition is one of the core conepts of functional programming, but definitely requires a bit of time to wrap your head around.&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9060588</link><pubDate>Tue, 11 Nov 2008 21:29:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9060588</guid><dc:creator>Patrick Dewane</dc:creator><description>&lt;p&gt;Thanks for the explanation. It doesn't look like function composition from what I know of the subject. Knowing that &amp;quot;&amp;gt;&amp;gt;&amp;quot; is the function composition operator makes it really easy to read the line now, thanks again.&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9068755</link><pubDate>Fri, 14 Nov 2008 11:31:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9068755</guid><dc:creator>Jay Hugard</dc:creator><description>&lt;p&gt;This doesn't show clever use of function composition (very cool, by the way), but it does provide a traditional rot13 implementation:&lt;/p&gt;
&lt;p&gt;let rot13 =&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;let rot b c = (int c - int b + 13) % 26 + int b |&amp;gt; char&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;String.map (function&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | 'A'..'Z' as c -&amp;gt; rot 'A' c&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | 'a'..'z' as c -&amp;gt; rot 'a' c&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | c -&amp;gt; c )&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9591227</link><pubDate>Wed, 06 May 2009 16:31:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9591227</guid><dc:creator>Frederico Pessoa</dc:creator><description>&lt;p&gt;Summing all cents:&lt;/p&gt;
&lt;p&gt;let rot13 s =&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;let rotc = function&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| i when 97 &amp;lt;= i &amp;amp;&amp;amp; i &amp;lt;= 122 -&amp;gt; (i - 84) % 26 + 97&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| i when 65 &amp;lt;= i &amp;amp;&amp;amp; i &amp;lt;= 90 -&amp;gt; (i - 52) % 26 + 65&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| i -&amp;gt; i&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;s |&amp;gt; String.map (int &amp;gt;&amp;gt; rotc &amp;gt;&amp;gt; char)&lt;/p&gt;
</description></item><item><title>re: F# Zen - ROT13</title><link>http://blogs.msdn.com/chrsmith/archive/2008/11/07/f-zen-rot13.aspx#9591238</link><pubDate>Wed, 06 May 2009 16:35:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9591238</guid><dc:creator>Frederico Pessoa</dc:creator><description>&lt;p&gt;And I do miss python 0 &amp;lt;= x &amp;lt;= 100 construct...&lt;/p&gt;
</description></item></channel></rss>