<?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: Blum Blum Shub</title>
	<atom:link href="http://programmingpraxis.com/2009/08/18/blum-blum-shub/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/08/18/blum-blum-shub/</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: Graham</title>
		<link>http://programmingpraxis.com/2009/08/18/blum-blum-shub/#comment-3102</link>
		<dc:creator><![CDATA[Graham]]></dc:creator>
		<pubDate>Wed, 01 Jun 2011 20:44:36 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1193#comment-3102</guid>
		<description><![CDATA[Late to the party, but here we go:
[sourcecode lang=&quot;python&quot;]
#!/usr/bin/env python

def bbs_gen(n, seed):
    &quot;&quot;&quot;Blum Blum Shub PRNG&quot;&quot;&quot;
    x = pow(seed, 2, n)
    while True:
        yield x % 256
        x = pow(x, 2, n)

def xor_cipher(text, n, seed):
    &quot;&quot;&quot;Uses Blum Blum Shub generator to en/decipher text via XOR&quot;&quot;&quot;
    bbs = bbs_gen(n, seed)
    return &#039;&#039;.join(chr(x) for x in (ord(t) ^ next(bbs) for t in text))

if __name__ == &quot;__main__&quot;:
    P, Q, S = 983, 991, 17
    PLAIN = &quot;PROGRAMMING PRAXIS&quot;
    CIPHER = xor_cipher(PLAIN, P * Q, S)
    print CIPHER
    print xor_cipher(CIPHER, P * Q, S)
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Late to the party, but here we go:</p>
<pre class="brush: python;">
#!/usr/bin/env python

def bbs_gen(n, seed):
    &quot;&quot;&quot;Blum Blum Shub PRNG&quot;&quot;&quot;
    x = pow(seed, 2, n)
    while True:
        yield x % 256
        x = pow(x, 2, n)

def xor_cipher(text, n, seed):
    &quot;&quot;&quot;Uses Blum Blum Shub generator to en/decipher text via XOR&quot;&quot;&quot;
    bbs = bbs_gen(n, seed)
    return ''.join(chr(x) for x in (ord(t) ^ next(bbs) for t in text))

if __name__ == &quot;__main__&quot;:
    P, Q, S = 983, 991, 17
    PLAIN = &quot;PROGRAMMING PRAXIS&quot;
    CIPHER = xor_cipher(PLAIN, P * Q, S)
    print CIPHER
    print xor_cipher(CIPHER, P * Q, S)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; First clojure code Elements of the Life Programmatic</title>
		<link>http://programmingpraxis.com/2009/08/18/blum-blum-shub/#comment-540</link>
		<dc:creator><![CDATA[&#187; First clojure code Elements of the Life Programmatic]]></dc:creator>
		<pubDate>Sun, 23 Aug 2009 00:24:34 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1193#comment-540</guid>
		<description><![CDATA[[...] that I would get into clojure for some time, and i finally got around to doing a programming praxis exercise in clojure.  Basically, it consists of creating a sequence of pseudo-random numbers, and [...]]]></description>
		<content:encoded><![CDATA[<p>[...] that I would get into clojure for some time, and i finally got around to doing a programming praxis exercise in clojure.  Basically, it consists of creating a sequence of pseudo-random numbers, and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pschorf</title>
		<link>http://programmingpraxis.com/2009/08/18/blum-blum-shub/#comment-539</link>
		<dc:creator><![CDATA[pschorf]]></dc:creator>
		<pubDate>Sat, 22 Aug 2009 22:37:15 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1193#comment-539</guid>
		<description><![CDATA[a clojure solution:
&lt;code&gt;
(defn bbs
 ([n s] 
    (iterate 
     (fn [x] (rem (rem n (* x x)) 256))
     (rem (rem n (* s s)) 256))))
(defn stream-cipher
  ([text n s]
     (let [sequence (if (= (class text) java.lang.String) (seq text) text)]
     (map (fn [x y] (char (bit-xor (int x) (int y)))) sequence (bbs n s))))
  ([text]
     (stream-cipher text (* 199967 199999) (- (* 199967 199999) 1)))))
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>a clojure solution:<br />
<code><br />
(defn bbs<br />
 ([n s]<br />
    (iterate<br />
     (fn [x] (rem (rem n (* x x)) 256))<br />
     (rem (rem n (* s s)) 256))))<br />
(defn stream-cipher<br />
  ([text n s]<br />
     (let [sequence (if (= (class text) java.lang.String) (seq text) text)]<br />
     (map (fn [x y] (char (bit-xor (int x) (int y)))) sequence (bbs n s))))<br />
  ([text]<br />
     (stream-cipher text (* 199967 199999) (- (* 199967 199999) 1)))))<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lautaro Pecile</title>
		<link>http://programmingpraxis.com/2009/08/18/blum-blum-shub/#comment-528</link>
		<dc:creator><![CDATA[Lautaro Pecile]]></dc:creator>
		<pubDate>Tue, 18 Aug 2009 17:12:26 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1193#comment-528</guid>
		<description><![CDATA[def blum_blum_shub(n, s):
    while True:
        s = s**2 % n
        yield int(s % 256)

def encypher(n, s, text):
    bbs = blum_blum_shub(n, s)
    return [ord(c)^bbs.next() for c in text]

def decypher (n, s, lst):
    bbs = blum_blum_shub(n, s)
    return &#039;&#039;.join([chr(i^bbs.next()) for i in lst])

decypher(974153, 17, encypher (974153, 17, &quot;PROGRAMMING PRAXIS&quot;))]]></description>
		<content:encoded><![CDATA[<p>def blum_blum_shub(n, s):<br />
    while True:<br />
        s = s**2 % n<br />
        yield int(s % 256)</p>
<p>def encypher(n, s, text):<br />
    bbs = blum_blum_shub(n, s)<br />
    return [ord(c)^bbs.next() for c in text]</p>
<p>def decypher (n, s, lst):<br />
    bbs = blum_blum_shub(n, s)<br />
    return &#8221;.join([chr(i^bbs.next()) for i in lst])</p>
<p>decypher(974153, 17, encypher (974153, 17, &#8220;PROGRAMMING PRAXIS&#8221;))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Remco Niemeijer</title>
		<link>http://programmingpraxis.com/2009/08/18/blum-blum-shub/#comment-526</link>
		<dc:creator><![CDATA[Remco Niemeijer]]></dc:creator>
		<pubDate>Tue, 18 Aug 2009 13:24:01 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1193#comment-526</guid>
		<description><![CDATA[My Haskell solution (see http://bonsaicode.wordpress.com/2009/08/18/programming-praxis-blum-blum-shub/ for a version with comments):

[sourcecode lang=&#039;css&#039;]
import Data.Bits
import Data.Char

rng :: Int -&gt; Int -&gt; [Int]
rng m = map (.&amp;. 7) . tail . iterate (\n -&gt; mod (n ^ 2) m)

cipher :: Int -&gt; Int -&gt; Int -&gt; String -&gt; String
cipher s p q = map chr . zipWith xor (rng (p * q) s) . map ord

main :: IO ()
main = do print $ cipher 3 11 19 &quot;Bonsai Code&quot;
          print . cipher 3 11 19 $ cipher 3 11 19 &quot;Bonsai Code&quot;
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>My Haskell solution (see <a href="http://bonsaicode.wordpress.com/2009/08/18/programming-praxis-blum-blum-shub/" rel="nofollow">http://bonsaicode.wordpress.com/2009/08/18/programming-praxis-blum-blum-shub/</a> for a version with comments):</p>
<pre class="brush: css;">
import Data.Bits
import Data.Char

rng :: Int -&gt; Int -&gt; [Int]
rng m = map (.&amp;. 7) . tail . iterate (\n -&gt; mod (n ^ 2) m)

cipher :: Int -&gt; Int -&gt; Int -&gt; String -&gt; String
cipher s p q = map chr . zipWith xor (rng (p * q) s) . map ord

main :: IO ()
main = do print $ cipher 3 11 19 &quot;Bonsai Code&quot;
          print . cipher 3 11 19 $ cipher 3 11 19 &quot;Bonsai Code&quot;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Programming Praxis &#8211; Blum Blum Shub &#171; Bonsai Code</title>
		<link>http://programmingpraxis.com/2009/08/18/blum-blum-shub/#comment-525</link>
		<dc:creator><![CDATA[Programming Praxis &#8211; Blum Blum Shub &#171; Bonsai Code]]></dc:creator>
		<pubDate>Tue, 18 Aug 2009 13:23:11 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1193#comment-525</guid>
		<description><![CDATA[[...] Praxis &#8211; Blum Blum&#160;Shub By Remco Niemeijer  In today’s Programming Praxis problem we have to implement a stream cipher based on the Blum Blum Shub method. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Praxis &#8211; Blum Blum&nbsp;Shub By Remco Niemeijer  In today’s Programming Praxis problem we have to implement a stream cipher based on the Blum Blum Shub method. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

