<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	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>Breaking Code</title>
	<atom:link href="http://breakingcode.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://breakingcode.wordpress.com</link>
	<description>When a meth lab&#039;s not an option, get into infosec instead.</description>
	<lastBuildDate>Sat, 28 Jan 2012 12:24:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='breakingcode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Breaking Code</title>
		<link>http://breakingcode.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://breakingcode.wordpress.com/osd.xml" title="Breaking Code" />
	<atom:link rel='hub' href='http://breakingcode.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Posting anonymously to Pastebin.com</title>
		<link>http://breakingcode.wordpress.com/2012/01/27/posting-anonymously-to-pastebin-com/</link>
		<comments>http://breakingcode.wordpress.com/2012/01/27/posting-anonymously-to-pastebin-com/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 18:58:53 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Privacy]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web applications]]></category>
		<category><![CDATA[anonymous]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tor]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=477</guid>
		<description><![CDATA[An easy way to send content anonymously to the Pastebin.com site, using Python and Tor.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=477&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">While going through some old code of mine to document it using Epydoc at a friend&#8217;s request, I found something funny. <a href="http://breakingcode.wordpress.com/2010/03/06/using-the-pastebin-api-with-python/">Some time ago</a> I made a quick and dirty script to access the Pastebin.com API from Python. Well, it turns out the API has changed quite a bit since then &#8211; most importantly, now it requires a <strong>mandatory API key</strong> that&#8217;s linked to a user account (which in turn, if you used OAuth, is linked to your Gmail address or Twitter feed). That means it&#8217;s <strong>no longer possible</strong> to post <strong>anonymously</strong> using the official API.</span></p>
<p><span style="font-size:120%;">Funny thing is, my <strong>old</strong> script was <strong>still working</strong>! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Apparently the folks at Pastebin have left the legacy API still running. The old documentation is gone though, and now even to read the <a href="http://pastebin.com/api">updated documentation</a> you need to log in&#8230; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">Now, this takes care of the API key problem, but there&#8217;s still the issue of Pastebin seeing your <strong>IP address</strong>. An HTTP <strong>proxy</strong> can fix that&#8230; provided you trust that proxy not to store your IP somewhere in the logs. The procedure is simple, just set the <em>HTTP_PROXY</em> environment variable to wherever your proxy is, and <i>voil&agrave;</i>! The standard Python module <a href="http://docs.python.org/library/urllib.html">urllib</a> will automatically connect through the proxy.</span></p>
<p><span style="font-size:120%;">If you don&#8217;t have a trusty HTTP proxy, the best way to go is through the <strong>Tor network</strong>. You&#8217;ll need to install the Tor service itself and the Privoxy HTTP proxy in your machine, then set the <em>HTTP_PROXY</em> variable to <em>127.0.0.1:8123</em>. <a href="https://trac.torproject.org/projects/tor/wiki/doc/TorifyHOWTO">This document</a> from the Tor Project explains it in detail.</span></p>
<p><span style="font-size:120%;">Once you&#8217;ve set up your proxy, download <a href="http://winappdbg.sourceforge.net/blog/pastebin.py">pastebin.py</a> and send a file to Pastebin like this:</span></p>
<p><span style="font-size:120%;"><em>
<pre>    $ python pastebin.py manifesto.txt
    manifesto.txt --&gt; http://pastebin.com/ixSetT5f</pre>
<p></em></span></p>
<p><span style="font-size:120%;">The script accepts multiple filenames as well. You can also set the syntax highlighting format (useful for source code, config files or logs) as follows:</span></p>
<p><span style="font-size:120%;"><em>
<pre>    python pastebin.py --format=apache /var/log/apache2/access.log /var/log/apache2/error.log</pre>
<p></em></span></p>
<p><span style="font-size:120%;">And set an expiration time, after which it gets automatically deleted. In the following example a SQL dump is uploaded and automatically deleted the next day:</span></p>
<p><span style="font-size:120%;"><em>
<pre>    python pastebin.py dump.sql --format=sql --expire=1D</pre>
<p></em></span></p>
<p><span style="font-size:120%;">So, that&#8217;s pretty much it. There&#8217;s a limit of 512Kb per file uploaded, in order to bypass this you&#8217;ll have to split the file into multiple pieces (something similar to <a href="http://breakingcode.wordpress.com/2010/01/14/having-fun-with-url-shorteners-part-2-parasitic-storage/">this</a> but using pastes instead of URLs). I may do it another day, but for now it&#8217;s left as an exercise to the reader. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">There&#8217;s one thing I don&#8217;t quite understand: why did the Pastebin folks think it was necessary to have a mandatory API key? Even if the legacy API had been shut down, it would still be possible to figure out how the web page was doing it and replicate it in Python. The API key being linked to the user account seems a bit strange too&#8230; Their intention might be to catch script kiddies uploading illegal stuff, but it may also be an attempt to do data mining on people&#8217;s posts. Who knows&#8230;</span></p>
<p>
<h2>Download</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pastebin.py">pastebin.py</a></h3></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/privacy/'>Privacy</a>, <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a>, <a href='http://breakingcode.wordpress.com/category/web-applications/'>Web applications</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/anonymous/'>anonymous</a>, <a href='http://breakingcode.wordpress.com/tag/api/'>API</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/privacy-2/'>privacy</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/tor/'>tor</a>, <a href='http://breakingcode.wordpress.com/tag/web/'>web</a>, <a href='http://breakingcode.wordpress.com/tag/webapp/'>webapp</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/477/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=477&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2012/01/27/posting-anonymously-to-pastebin-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickpost: Listing all available Java cryptographic services</title>
		<link>http://breakingcode.wordpress.com/2011/07/20/quickpost-listing-all-available-java-cryptographic-services/</link>
		<comments>http://breakingcode.wordpress.com/2011/07/20/quickpost-listing-all-available-java-cryptographic-services/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 13:17:59 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=455</guid>
		<description><![CDATA[This little command line tool dumps all available Java cryptographic services to standard output.

Executable: http://winappdbg.sourceforge.net/blog/ListServices.jar
Sources + Eclipse project: http://winappdbg.sourceforge.net/blog/ListServices.zip<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=455&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">I recently wanted to know which hash functions were available to Java in a given machine, so I cooked up a little command line tool for that. Maybe this could be useful to others so I posted it here.</span></p>
<p><span style="font-size:120%;">Java hash functions are implemented as a MessageDigest object, which you can&#8217;t instance directly but rather get an instance through the MessageDigest.getInstance() static method. It takes as it&#8217;s only argument a string with the name of the algorithm &#8211; but I couldn&#8217;t find an easy way to enumerate all available algorithms.</span></p>
<p><span style="font-size:120%;">After a little googling I found this code example at <a href="http://www.exampledepot.com/egs/java.security/ListServices.html">Example Depot</a> to do it programatically. Since results may vary from one installation of Java to the next, a command line tool would have been more useful to me, but  I don&#8217;t know of any. (If you do, let me know!)</span></p>
<p><span style="font-size:120%;">Anyway, I wrapped the code in a very simple Main function and compiled it using Eclipse. I called this little tool &#8220;ListServices&#8221; because I didn&#8217;t feel like thinking of a catchy name. <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">By default this tool lists all available cryptographic providers, but you can specify just the ones you need (in the example below, we type MessageDigest to get just the hashing algorithms):</span></p>
<pre>
        $ java -jar ListServices.jar
        KeyFactory:
                1.2.840.113549.1.3.1
                OID.1.2.840.113549.1.1
                1.2.840.113549.1.1
                OID.1.2.840.113549.1.3.1
                1.3.14.3.2.12
                DSA
                DiffieHellman
                RSA
                DH
                1.2.840.10040.4.1

        TransformService:
                INCLUSIVE_WITH_COMMENTS
                ENVELOPED
                (... output omitted for brevity ...)

        $ java -jar ListProviders.jar MessageDigest
        MessageDigest:
                SHA-256
                SHA-512
                SHA
                SHA-384
                SHA1
                MD5
                SHA-1
                MD2

        $
</pre>
<p><span style="font-size:120%;">Enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p>
<h2>Downloads</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/ListServices.jar">Executable JAR</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/ListServices.zip">Source code + Eclipse project</a></h3></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/cryptography/'>Cryptography</a>, <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/crypto/'>crypto</a>, <a href='http://breakingcode.wordpress.com/tag/java/'>java</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/455/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=455&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2011/07/20/quickpost-listing-all-available-java-cryptographic-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>A dual screen hack: x2vnc</title>
		<link>http://breakingcode.wordpress.com/2010/09/08/a-dual-screen-hack-x2vnc/</link>
		<comments>http://breakingcode.wordpress.com/2010/09/08/a-dual-screen-hack-x2vnc/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 18:30:24 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Just for fun]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=443</guid>
		<description><![CDATA[I patched x2vnc to add a few extra command line options. My branch is in Google Code: http://code.google.com/p/x2vnc/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=443&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">Today I just had to use two laptop computers simultaneously, and switching back and forth was driving me insane. Then I remembered an old trick I used to pull back at my old job: the dual screen hack.</span></p>
<p><span style="font-size:120%;">Most of you probably know it already, but just in case, here goes the explanation. You can connect two computers and simulate what would happen if you had two monitors instead: when the mouse leaves the screen in one computer, it &#8220;enters&#8221; the other computer on the opposite side of the screen. For example, if you have two laptops on your table and you move the mouse to the <strong>right</strong>, after reaching the border of the screen you see it coming out on the <strong>left</strong> side of the other computer. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">The magic is done by using a remote desktop protocol like VNC, which lets you send keystrokes and mouse events, but discarding the framebuffer updates. That is, a program that connects to the remote desktop, but instead of showing you the remote screen, it monitors mouse movements locally and when the mouse reaches the screen limits, it captures the mouse and starts sending mouse events to the remote system. Similarly, when the mouse reaches the opposite limit on the remote system, it stops capturing the mouse so you can use it on the local system.</span></p>
<p><span style="font-size:120%;">Since I use Linux my choice was <a href="http://fredrik.hubbe.net/x2vnc.html">x2vnc</a>, the Linux cousin of the more famous <a href="http://fredrik.hubbe.net/win2vnc.html">Win2VNC</a>, also by the same author. But unlike Win2VNC which is now actively maintained at <a href="http://sourceforge.net/projects/win2vnc/">SourceForge</a>, x2vnc seems to have been abandoned.</span></p>
<p><span style="font-size:120%;">x2vnc supports SSH tunneling, which is just perfect since VNC is a plaintext-only protocol and <a href="http://www.hideaway.net/2007/07/stating-obvious-vnc-is-insecure_09.html">insecure by design</a>. However there&#8217;s <a href="http://linux.die.net/man/5/ssh_config">no easy way</a> to tell x2vnc to which <strong>port</strong> to connect or which <strong>username</strong> to login as &#8211; it defaults always to the current local user and port 22.</span></p>
<p><span style="font-size:120%;">I also had a problem with my other laptop, which had Windows 7. When the mouse cursor leaves the screen, it is &#8220;parked&#8221; to a corner of the screen so it doesn&#8217;t show (it&#8217;d be confusing to see two mouse cursors as you wouldn&#8217;t know which one is active). But the corner chosen by x2vnc is always the lower right corner, causing Windows 7 to hide all active windows&#8230; very annoying.</span></p>
<p><span style="font-size:120%;">So I did what any other geek would do in my situation &#8211; branch it! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  </span></p>
<p><span style="font-size:120%;">The patched code is now at <a href="http://code.google.com/p/x2vnc/">Google Code</a>. The new command line switches I added were:</span></p>
<p><span style="font-size:120%;"><strong>-sshuser</strong>: Log in to the SSH tunnel using the given username.</span></p>
<p><span style="font-size:120%;"><strong>-sshport</strong>: Connect to the given TCP port number instead of the SSH default (22).</span></p>
<p><span style="font-size:120%;"><strong>-restingx</strong> and <strong>-restingy</strong>: Tell x2vnc where to park the mouse cursor. A value of 0 means left or top, a value of -1 means right or bottom. Then for example, <em>-restingx 0 -restingy -1</em> means the top right corner of the screen.</span></p>
<p><span style="font-size:120%;">Currently there&#8217;s only the source code but if I have the time I&#8217;ll upload a precompiled Debian package as well. Enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p>
<h2>Download</h2>
</p>
<p>
<h3>Source code: <a href="http://code.google.com/p/x2vnc/source/checkout">http://code.google.com/p/x2vnc/source/checkout</a></h3></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/just-for-fun/'>Just for fun</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/debian/'>Debian</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/linux/'>linux</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/443/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=443&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2010/09/08/a-dual-screen-hack-x2vnc/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>WinAppDbg 1.4 is out!</title>
		<link>http://breakingcode.wordpress.com/2010/08/24/winappdbg-1-4-is-out/</link>
		<comments>http://breakingcode.wordpress.com/2010/08/24/winappdbg-1-4-is-out/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 12:44:41 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[ctypes]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[diStorm]]></category>
		<category><![CDATA[fuzzer]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[vulnerability research]]></category>
		<category><![CDATA[win32]]></category>
		<category><![CDATA[WinAppDbg]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Wine]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=436</guid>
		<description><![CDATA[WinAppDbg 1.4 is out! http://tinyurl.com/winappdbg<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=436&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>What is WinAppDbg?</h2>
<p><span style="font-size:120%;">The WinAppDbg python module allows developers to quickly code instrumentation scripts in Python under a Windows environment.</span></p>
<p><span style="font-size:120%;">It uses ctypes to wrap many Win32 API calls related to debugging, and provides an object-oriented abstraction layer to manipulate threads, libraries and processes, attach your script as a debugger, trace execution, hook API calls, handle events in your debugee and set breakpoints of different kinds (code, hardware and memory). Additionally it has no native code at all, making it easier to maintain or modify than other debuggers on Windows.</span></p>
<p><span style="font-size:120%;">The intended audience are QA engineers and software security auditors wishing to test / fuzz Windows applications with quickly coded Python scripts. Several ready to use utilities are shipped and can be used for this purposes.</span></p>
<p><span style="font-size:120%;">Current features also include disassembling x86 native code (using the open source diStorm project, see http://ragestorm.net/distorm/), debugging multiple processes simultaneously and produce a detailed log of application crashes, useful for fuzzing and automated testing.</span></p>
<h2>What&#8217;s new in this version?</h2>
<p><span style="font-size:120%;">In a nutshell&#8230;</span></p>
<ul>
<li><span style="font-size:120%;">fully supports Python 2.4 through 2.7</span></li>
<li><span style="font-size:120%;">fully supports Windows XP through Windows 7, 32 and 64 bit editions</span></li>
<li><span style="font-size:120%;">crash report tool now supports MSSQL (requires pyodbc)</span></li>
<li><span style="font-size:120%;">now supports downloading debugging symbols from Microsoft (thanks Neitsa!)</span></li>
<li><span style="font-size:120%;">new tool: sehtest.py (Windows SEH buffer overflow jump address bruteforcer, inspired by the same tool by Nicolas Economou)</span></li>
<li><span style="font-size:120%;">the tutorial is now available in chm and pdf formats</span></li>
<li><span style="font-size:120%;">now with only one MSI installer for all supported Python versions</span></li>
<li><span style="font-size:120%;">added support for diStorm 3 (falls back to the old version if not found)</span></li>
<li><span style="font-size:120%;">now using cerealizer instead of pickle whenever possible</span></li>
<li><span style="font-size:120%;">added new command to the command line debugger to show the exception handlers</span></li>
<li><span style="font-size:120%;">a few more anti-anti-debug tricks were added, still more to go!</span></li>
<li><span style="font-size:120%;">several improvements to the Window instrumentation classes</span></li>
<li><span style="font-size:120%;">more code examples</span></li>
<li><span style="font-size:120%;">more Win32 API wrappers</span></li>
<li><span style="font-size:120%;">lots of miscellaneous improvements, more documentation and bugfixes as usual!</span></li>
</ul>
<p><span style="font-size:120%;">Entire changelog for all versions (slow!):</span></p>
<ul>
<li><span style="font-size:120%;"><a href="http://p.sf.net/winappdbg/changelog">http://p.sf.net/winappdbg/changelog</a></span></li>
</ul>
<h2>Where can I find WinAppDbg?</h2>
<h4>Project homepage</h4>
<ul>
<li><span style="font-size:120%;"><a href="http://tinyurl.com/winappdbg">http://tinyurl.com/winappdbg</a></span></li>
</ul>
<h4>Windows installer (32 bits)</h4>
<ul>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.win32.msi/download">winappdbg-1.4.win32.msi</a></span></li>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.win32.exe/download">winappdbg-1.4.win32.exe</a></span></li>
</ul>
<h4>Windows installer (64 bits)</h4>
<ul>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.win-amd64.msi/download">winappdbg-1.4.win-amd64.msi</a></span></li>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.win-amd64.exe/download">winappdbg-1.4.win-amd64.exe</a></span></li>
</ul>
<h4>Source code</h4>
<ul>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.zip/download">winappdbg-1.4.zip</a></span></li>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.tar.bz2/download">winappdbg-1.4.tar.bz2</a></span></li>
</ul>
<h4>Online documentation</h4>
<ul>
<li><span style="font-size:120%;"><a href="http://winappdbg.sourceforge.net/doc/v1.4/tutorial">Programming Guide</a></span></li>
<li><span style="font-size:120%;"><a href="http://winappdbg.sourceforge.net/doc/v1.4/reference">Reference documentation</a></span></li>
</ul>
<h4>Offline documentation</h4>
<ul>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.chm/download">winappdbg-tutorial-1.4.chm</a></span></li>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.pdf/download">winappdbg-tutorial-1.4.pdf</a></span></li>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.chm/download">winappdbg-reference-1.4.chm</a></span></li>
<li><span style="font-size:120%;"><a href="http://sourceforge.net/projects/winappdbg/files/WinAppDbg/1.4/winappdbg-1.4.pdf/download">winappdbg-reference-1.4.pdf</a></span></li>
</ul>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/ctypes/'>ctypes</a>, <a href='http://breakingcode.wordpress.com/tag/debugger/'>debugger</a>, <a href='http://breakingcode.wordpress.com/tag/distorm/'>diStorm</a>, <a href='http://breakingcode.wordpress.com/tag/fuzzer/'>fuzzer</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/reverse-engineering/'>reverse engineering</a>, <a href='http://breakingcode.wordpress.com/tag/testing/'>testing</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/vulnerability-research/'>vulnerability research</a>, <a href='http://breakingcode.wordpress.com/tag/win32/'>win32</a>, <a href='http://breakingcode.wordpress.com/tag/winappdbg/'>WinAppDbg</a>, <a href='http://breakingcode.wordpress.com/tag/windows/'>Windows</a>, <a href='http://breakingcode.wordpress.com/tag/wine/'>Wine</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/436/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=436&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2010/08/24/winappdbg-1-4-is-out/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickpost: &#8220;Hiding&#8221; your Python source with ROT13</title>
		<link>http://breakingcode.wordpress.com/2010/07/23/quickpost-hiding-your-python-source-with-rot13/</link>
		<comments>http://breakingcode.wordpress.com/2010/07/23/quickpost-hiding-your-python-source-with-rot13/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 17:50:28 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Just for fun]]></category>
		<category><![CDATA[antivirus]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[obfuscate]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=432</guid>
		<description><![CDATA[A nifty Python trick: using ROT13 as your script's source code encoding. Pretty much useless, but fun! :) Download: http://winappdbg.sourceforge.net/blog/rot13src.py<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=432&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">First of all I want to make something clear: this is an absolutely lame way to obfuscate your code. I guess some antivirus, IDS or other kind of security scanner may fail to properly analyze the code if it&#8217;s encoded like this, but you can&#8217;t really fool a human.</span></p>
<p><span style="font-size:120%;">Anyway, it was fun <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and that&#8217;s my main motivation to write this blog in the first place, soooo&#8230; here it is! A Python source code obfuscator that uses ROT13.</span></p>
<p><span style="font-size:120%;">How does it work? Simply put, by misusing the Python source encodings feature. I stumbled upon this idea while reading a thread in <a href="http://stackoverflow.com/questions/101268/hidden-features-of-python/1024693#1024693">Stack Overflow</a>. Python allows us to use any supported form of text encoding for our source code, by placing a magic comment in either the first or second line of the script:</span></p>
<pre><font face="Lucida,Courier New,Monospace,Vera sans mono"><font color="#008000">    #!/usr/bin/env python
</font><font color="#008000">    # -*- coding: &lt;codec-name-goes-here&gt; -*-</font><font color="#000000"></font></font></pre>
<p><span style="font-size:120%;">This is useful for example to use UTF-8 and other encodings that allow non-english characters. But Python also has some other fun encodings, like ROT13 (the ancient Roman empire encryption system). The following snippet from Stack Overflow shows how to do it:</span></p>
<pre><font face="Lucida,Courier New,Monospace,Vera sans mono"><font color="#008000">    #!/usr/bin/env python
</font><font color="#008000">    # -*- coding: rot13 -*-
</font>
<font color="#000000">    cevag</font> <font color="#004080">"Uryyb fgnpxbiresybj!"</font><font color="#0000C0">.</font><font color="#000000">rapbqr</font><font color="#0000C0">(</font><font color="#004080">"rot13"</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<p><span style="font-size:120%;">The only caveat is, ASCII strings are not decoded when you run the script, so you have to do it yourself. Unicode strings on the other hand are decoded automatically.</span></p>
<pre><font face="Lucida,Courier New,Monospace,Vera sans mono"><font color="#008000">    #!/usr/bin/env python
</font><font color="#008000">    # -*- coding: rot13 -*-
</font>
<font color="#000000">    cevag</font> <font color="#000000">h</font><font color="#004080">"Uryyb fgnpxbiresybj!"</font><font color="#000000"></font></font></pre>
<p><span style="font-size:120%;">There are some other fun encodings like &#8220;base64&#8243;, &#8220;uuencode&#8221;, &#8220;zlib&#8221; or &#8220;bz2&#8243; that you can experiment with too. If you try them let me know how it went. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">I wrote a quick script to use the ROT13 trick. Naturally the source code itself is also encoded in ROT13, decoding it is left as an exercise for the reader. Enjoy!</span></p>
<p>
<h2>Download</h2>
</p>
<p>
<h3>Source code: <a href="http://winappdbg.sourceforge.net/blog/rot13src.py">rot13src.py</a></h3></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/just-for-fun/'>Just for fun</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/antivirus/'>antivirus</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/obfuscate/'>obfuscate</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/reverse-engineering/'>reverse engineering</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/432/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=432&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2010/07/23/quickpost-hiding-your-python-source-with-rot13/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickpost: Using Google Search from your Python code</title>
		<link>http://breakingcode.wordpress.com/2010/06/29/google-search-python/</link>
		<comments>http://breakingcode.wordpress.com/2010/06/29/google-search-python/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 18:31:13 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web applications]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[information gathering]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[recon]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=413</guid>
		<description><![CDATA[Quick script in Python to make Google searches. Can be used as a command line script or imported as a module. Download: http://winappdbg.sourceforge.net/blog/google-1.01.tar.gz<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=413&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">Hi everyone. Today I&#8217;ll be showing you a quick script I wrote to make Google searches from Python. There are previous projects doing the same thing -actually, doing it better-, namely <a href="http://googolplex.sourceforge.net/">Googolplex</a> by Sebastian Wain and <a href="http://www.catonmat.net/blog/python-library-for-google-search/">xgoogle</a> by Peteris Krumins, but unfortunately they&#8217;re no longer working. Maybe the lack of complexity of this script will keep it working a little longer&#8230; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">The interface is extremely simple, the module exports only one function called <strong>search()</strong>.</span></p>
<pre><font face="Lucida,Courier New,Monospace,Vera sans mono"><font color="#008000">        # Get the first 20 hits for: "Breaking Code" WordPress blog
</font>        <font color="#C00000">from</font> <font color="#000000">google</font> <font color="#C00000">import</font> <font color="#000000">search</font>
        <font color="#C00000">for</font> <font color="#000000">url</font> <font color="#C00000">in</font> <font color="#000000">search</font><font color="#0000C0">(</font><font color="#004080">'"Breaking Code" WordPress blog'</font><font color="#0000C0">,</font> <font color="#000000">stop</font><font color="#0000C0">=</font><font color="#0080C0">20</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
            <font color="#C00000">print</font><font color="#0000C0">(</font><font color="#000000">url</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<p><span style="font-size:120%;">You can control which one of the Google Search pages to use, which language to search in, how many results per page, which page to start searching from and when to stop, and how long to wait between queries &#8211; however the only mandatory argument is the query string, everything else has a default value.</span></p>
<pre><font face="Lucida,Courier New,Monospace,Vera sans mono"><font color="#008000">        # Get the first 20 hits for "Mariposa botnet" in Google Spain
</font>        <font color="#C00000">from</font> <font color="#000000">google</font> <font color="#C00000">import</font> <font color="#000000">search</font>
        <font color="#C00000">for</font> <font color="#000000">url</font> <font color="#C00000">in</font> <font color="#000000">search</font><font color="#0000C0">(</font><font color="#004080">'Mariposa botnet'</font><font color="#0000C0">,</font> <font color="#000000">tld</font><font color="#0000C0">=</font><font color="#004080">'es'</font><font color="#0000C0">,</font> <font color="#000000">lang</font><font color="#0000C0">=</font><font color="#004080">'es'</font><font color="#0000C0">,</font> <font color="#000000">stop</font><font color="#0000C0">=</font><font color="#0080C0">20</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
            <font color="#C00000">print</font><font color="#0000C0">(</font><font color="#000000">url</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<p><span style="font-size:120%;">A word of caution, though: if you wait too little between requests or make too many of them, Google may block your IP for a while. This is especially annoying when you&#8217;re behind a corporate proxy &#8211; I won&#8217;t be made responsible when your coworkers suddenly develop an urge to kill you! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">Below are the download links (source code and Windows installers) and the source code for you to read online. Enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p>
<h2>Changelog</h2>
</p>
<ul>
<li><span style="font-size:120%;">Version 1.0 (initial release).</span></li>
</ul>
<ul>
<li><span style="font-size:120%;">Version 1.01 (fixed the IOError exception bug).</span></li>
</ul>
<ul>
<li><span style="font-size:120%;">Version 1.02 (fixed the missing href bug reported by <a href="https://twitter.com/fb1h2s">Rahul Sasi</a> and the duplicate results bug reported by Slawek).</span></li>
</ul>
<p>
<h2>Download</h2>
</p>
<p>
<h3>Source code: <a href="http://winappdbg.sourceforge.net/blog/google-1.02.tar.bz2">google-1.02.tar.bz2</a></h3>
</p>
<p>
<h3>Windows 32 bits installer: <a href="http://winappdbg.sourceforge.net/blog/google-1.02.win32.exe">google-1.02.win32.exe</a></h3>
</p>
<p>
<h3>Windows 64 bits installer: <a href="http://winappdbg.sourceforge.net/blog/google-1.02.win-amd64.exe">google-1.02.win-amd64.exe</a></h3>
</p>
<p>
<h3>Documentation: <a href="http://winappdbg.sourceforge.net/blog/google-1.02-doc.zip">google-1.02-doc.zip</a></h3>
</p>
<p>
<h2>Source code</h2>
</p>
<p><span id="more-413"></span></p>
<div class="highlight" style="background:#f8f8f8;">
<pre style="line-height:125%;"><span style="color:#408080;font-style:italic;">#!/usr/bin/env python</span>

<span style="color:#408080;font-style:italic;"># Python bindings to the Google search engine</span>
<span style="color:#408080;font-style:italic;"># Copyright (c) 2009-2012, Mario Vilas</span>
<span style="color:#408080;font-style:italic;"># All rights reserved.</span>
<span style="color:#408080;font-style:italic;">#</span>
<span style="color:#408080;font-style:italic;"># Redistribution and use in source and binary forms, with or without</span>
<span style="color:#408080;font-style:italic;"># modification, are permitted provided that the following conditions are met:</span>
<span style="color:#408080;font-style:italic;">#</span>
<span style="color:#408080;font-style:italic;">#     * Redistributions of source code must retain the above copyright notice,</span>
<span style="color:#408080;font-style:italic;">#       this list of conditions and the following disclaimer.</span>
<span style="color:#408080;font-style:italic;">#     * Redistributions in binary form must reproduce the above copyright</span>
<span style="color:#408080;font-style:italic;">#       notice,this list of conditions and the following disclaimer in the</span>
<span style="color:#408080;font-style:italic;">#       documentation and/or other materials provided with the distribution.</span>
<span style="color:#408080;font-style:italic;">#     * Neither the name of the copyright holder nor the names of its</span>
<span style="color:#408080;font-style:italic;">#       contributors may be used to endorse or promote products derived from</span>
<span style="color:#408080;font-style:italic;">#       this software without specific prior written permission.</span>
<span style="color:#408080;font-style:italic;">#</span>
<span style="color:#408080;font-style:italic;"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;</span>
<span style="color:#408080;font-style:italic;"># AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<span style="color:#408080;font-style:italic;"># IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
<span style="color:#408080;font-style:italic;"># ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE</span>
<span style="color:#408080;font-style:italic;"># LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span>
<span style="color:#408080;font-style:italic;"># CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span>
<span style="color:#408080;font-style:italic;"># SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</span>
<span style="color:#408080;font-style:italic;"># INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN</span>
<span style="color:#408080;font-style:italic;"># CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)</span>
<span style="color:#408080;font-style:italic;"># ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</span>
<span style="color:#408080;font-style:italic;"># POSSIBILITY OF SUCH DAMAGE.</span>

__version__ <span style="color:#666666;">=</span> <span style="color:#BA2121;">&quot;$Id: google.py 892 2012-01-02 16:42:08Z qvasimodo $&quot;</span>

__all__ <span style="color:#666666;">=</span> [<span style="color:#BA2121;">&#039;search&#039;</span>]

<span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">BeautifulSoup</span>
<span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">cookielib</span>
<span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">os</span>
<span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">time</span>
<span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">urllib</span>
<span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">urllib2</span>
<span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">urlparse</span>

<span style="color:#408080;font-style:italic;"># URL templates to make Google searches.</span>
url_home          <span style="color:#666666;">=</span> <span style="color:#BA2121;">&quot;http://www.google.</span><span style="color:#BB6688;font-weight:bold;">%(tld)s</span><span style="color:#BA2121;">/&quot;</span>
url_search        <span style="color:#666666;">=</span> <span style="color:#BA2121;">&quot;http://www.google.</span><span style="color:#BB6688;font-weight:bold;">%(tld)s</span><span style="color:#BA2121;">/search?hl=</span><span style="color:#BB6688;font-weight:bold;">%(lang)s</span><span style="color:#BA2121;">&amp;q=</span><span style="color:#BB6688;font-weight:bold;">%(query)s</span><span style="color:#BA2121;">&amp;btnG=Google+Search&quot;</span>
url_next_page     <span style="color:#666666;">=</span> <span style="color:#BA2121;">&quot;http://www.google.</span><span style="color:#BB6688;font-weight:bold;">%(tld)s</span><span style="color:#BA2121;">/search?hl=</span><span style="color:#BB6688;font-weight:bold;">%(lang)s</span><span style="color:#BA2121;">&amp;q=</span><span style="color:#BB6688;font-weight:bold;">%(query)s</span><span style="color:#BA2121;">&amp;start=</span><span style="color:#BB6688;font-weight:bold;">%(start)d</span><span style="color:#BA2121;">&quot;</span>
url_search_num    <span style="color:#666666;">=</span> <span style="color:#BA2121;">&quot;http://www.google.</span><span style="color:#BB6688;font-weight:bold;">%(tld)s</span><span style="color:#BA2121;">/search?hl=</span><span style="color:#BB6688;font-weight:bold;">%(lang)s</span><span style="color:#BA2121;">&amp;q=</span><span style="color:#BB6688;font-weight:bold;">%(query)s</span><span style="color:#BA2121;">&amp;num=</span><span style="color:#BB6688;font-weight:bold;">%(num)d</span><span style="color:#BA2121;">&amp;btnG=Google+Search&quot;</span>
url_next_page_num <span style="color:#666666;">=</span> <span style="color:#BA2121;">&quot;http://www.google.</span><span style="color:#BB6688;font-weight:bold;">%(tld)s</span><span style="color:#BA2121;">/search?hl=</span><span style="color:#BB6688;font-weight:bold;">%(lang)s</span><span style="color:#BA2121;">&amp;q=</span><span style="color:#BB6688;font-weight:bold;">%(query)s</span><span style="color:#BA2121;">&amp;num=</span><span style="color:#BB6688;font-weight:bold;">%(num)d</span><span style="color:#BA2121;">&amp;start=</span><span style="color:#BB6688;font-weight:bold;">%(start)d</span><span style="color:#BA2121;">&quot;</span>

<span style="color:#408080;font-style:italic;"># Cookie jar. Stored at the user&#039;s home folder.</span>
home_folder <span style="color:#666666;">=</span> os<span style="color:#666666;">.</span>getenv(<span style="color:#BA2121;">&#039;HOME&#039;</span>)
<span style="color:#008000;font-weight:bold;">if</span> <span style="color:#AA22FF;font-weight:bold;">not</span> home_folder:
    home_folder <span style="color:#666666;">=</span> os<span style="color:#666666;">.</span>getenv(<span style="color:#BA2121;">&#039;USERHOME&#039;</span>)
    <span style="color:#008000;font-weight:bold;">if</span> <span style="color:#AA22FF;font-weight:bold;">not</span> home_folder:
        home_folder <span style="color:#666666;">=</span> <span style="color:#BA2121;">&#039;.&#039;</span>   <span style="color:#408080;font-style:italic;"># Use the current folder on error.</span>
cookie_jar <span style="color:#666666;">=</span> cookielib<span style="color:#666666;">.</span>LWPCookieJar(os<span style="color:#666666;">.</span>path<span style="color:#666666;">.</span>join(home_folder, <span style="color:#BA2121;">&#039;.google-cookie&#039;</span>))
<span style="color:#008000;font-weight:bold;">try</span>:
    cookie_jar<span style="color:#666666;">.</span>load()
<span style="color:#008000;font-weight:bold;">except</span> <span style="color:#D2413A;font-weight:bold;">Exception</span>:
    <span style="color:#008000;font-weight:bold;">pass</span>

<span style="color:#408080;font-style:italic;"># Request the given URL and return the response page, using the cookie jar.</span>
<span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">get_page</span>(url):
    <span style="color:#BA2121;font-style:italic;">&quot;&quot;&quot;</span>
<span style="color:#BA2121;font-style:italic;">    Request the given URL and return the response page, using the cookie jar.</span>

<span style="color:#BA2121;font-style:italic;">    @type  url: str</span>
<span style="color:#BA2121;font-style:italic;">    @param url: URL to retrieve.</span>

<span style="color:#BA2121;font-style:italic;">    @rtype:  str</span>
<span style="color:#BA2121;font-style:italic;">    @return: Web page retrieved for the given URL.</span>

<span style="color:#BA2121;font-style:italic;">    @raise IOError: An exception is raised on error.</span>
<span style="color:#BA2121;font-style:italic;">    @raise urllib2.URLError: An exception is raised on error.</span>
<span style="color:#BA2121;font-style:italic;">    @raise urllib2.HTTPError: An exception is raised on error.</span>
<span style="color:#BA2121;font-style:italic;">    &quot;&quot;&quot;</span>
    request <span style="color:#666666;">=</span> urllib2<span style="color:#666666;">.</span>Request(url)
    request<span style="color:#666666;">.</span>add_header(<span style="color:#BA2121;">&#039;User-Agent&#039;</span>, <span style="color:#BA2121;">&#039;Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)&#039;</span>)
    cookie_jar<span style="color:#666666;">.</span>add_cookie_header(request)
    response <span style="color:#666666;">=</span> urllib2<span style="color:#666666;">.</span>urlopen(request)
    cookie_jar<span style="color:#666666;">.</span>extract_cookies(response, request)
    html <span style="color:#666666;">=</span> response<span style="color:#666666;">.</span>read()
    response<span style="color:#666666;">.</span>close()
    cookie_jar<span style="color:#666666;">.</span>save()
    <span style="color:#008000;font-weight:bold;">return</span> html

<span style="color:#408080;font-style:italic;"># Returns a generator that yields URLs.</span>
<span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">search</span>(query, tld<span style="color:#666666;">=</span><span style="color:#BA2121;">&#039;com&#039;</span>, lang<span style="color:#666666;">=</span><span style="color:#BA2121;">&#039;en&#039;</span>, num<span style="color:#666666;">=10</span>, start<span style="color:#666666;">=0</span>, stop<span style="color:#666666;">=</span><span style="color:#008000;">None</span>, pause<span style="color:#666666;">=2.0</span>):
    <span style="color:#BA2121;font-style:italic;">&quot;&quot;&quot;</span>
<span style="color:#BA2121;font-style:italic;">    Search the given query string using Google.</span>

<span style="color:#BA2121;font-style:italic;">    @type  query: str</span>
<span style="color:#BA2121;font-style:italic;">    @param query: Query string. Must NOT be url-encoded.</span>

<span style="color:#BA2121;font-style:italic;">    @type  tld: str</span>
<span style="color:#BA2121;font-style:italic;">    @param tld: Top level domain.</span>

<span style="color:#BA2121;font-style:italic;">    @type  lang: str</span>
<span style="color:#BA2121;font-style:italic;">    @param lang: Languaje.</span>

<span style="color:#BA2121;font-style:italic;">    @type  num: int</span>
<span style="color:#BA2121;font-style:italic;">    @param num: Number of results per page.</span>

<span style="color:#BA2121;font-style:italic;">    @type  start: int</span>
<span style="color:#BA2121;font-style:italic;">    @param start: First result to retrieve.</span>

<span style="color:#BA2121;font-style:italic;">    @type  stop: int</span>
<span style="color:#BA2121;font-style:italic;">    @param stop: Last result to retrieve.</span>
<span style="color:#BA2121;font-style:italic;">        Use C{None} to keep searching forever.</span>

<span style="color:#BA2121;font-style:italic;">    @type  pause: float</span>
<span style="color:#BA2121;font-style:italic;">    @param pause: Lapse to wait between HTTP requests.</span>
<span style="color:#BA2121;font-style:italic;">        A lapse too long will make the search slow, but a lapse too short may</span>
<span style="color:#BA2121;font-style:italic;">        cause Google to block your IP. Your mileage may vary!</span>

<span style="color:#BA2121;font-style:italic;">    @rtype:  generator</span>
<span style="color:#BA2121;font-style:italic;">    @return: Generator (iterator) that yields found URLs. If the C{stop}</span>
<span style="color:#BA2121;font-style:italic;">        parameter is C{None} the iterator will loop forever.</span>
<span style="color:#BA2121;font-style:italic;">    &quot;&quot;&quot;</span>

    <span style="color:#408080;font-style:italic;"># Set of hashes for the results found.</span>
    <span style="color:#408080;font-style:italic;"># This is used to avoid repeated results.</span>
    hashes <span style="color:#666666;">=</span> <span style="color:#008000;">set</span>()

    <span style="color:#408080;font-style:italic;"># Prepare the search string.</span>
    query <span style="color:#666666;">=</span> urllib<span style="color:#666666;">.</span>quote_plus(query)

    <span style="color:#408080;font-style:italic;"># Grab the cookie from the home page.</span>
    get_page(url_home <span style="color:#666666;">%</span> <span style="color:#008000;">vars</span>())

    <span style="color:#408080;font-style:italic;"># Prepare the URL of the first request.</span>
    <span style="color:#008000;font-weight:bold;">if</span> num <span style="color:#666666;">==</span> <span style="color:#666666;">10</span>:
        url <span style="color:#666666;">=</span> url_search <span style="color:#666666;">%</span> <span style="color:#008000;">vars</span>()
    <span style="color:#008000;font-weight:bold;">else</span>:
        url <span style="color:#666666;">=</span> url_search_num <span style="color:#666666;">%</span> <span style="color:#008000;">vars</span>()

    <span style="color:#408080;font-style:italic;"># Loop until we reach the maximum result, if any (otherwise, loop forever).</span>
    <span style="color:#008000;font-weight:bold;">while</span> <span style="color:#AA22FF;font-weight:bold;">not</span> stop <span style="color:#AA22FF;font-weight:bold;">or</span> start <span style="color:#666666;">&lt;</span> stop:

        <span style="color:#408080;font-style:italic;"># Sleep between requests.</span>
        time<span style="color:#666666;">.</span>sleep(pause)

        <span style="color:#408080;font-style:italic;"># Request the Google Search results page.</span>
        html <span style="color:#666666;">=</span> get_page(url)

        <span style="color:#408080;font-style:italic;"># Parse the response and yield every anchored URL.</span>
        <span style="color:#408080;font-style:italic;"># Discard duplicate URLs.</span>
        soup <span style="color:#666666;">=</span> BeautifulSoup<span style="color:#666666;">.</span>BeautifulSoup(html)
        anchors <span style="color:#666666;">=</span> soup<span style="color:#666666;">.</span>findAll(<span style="color:#BA2121;">&#039;a&#039;</span>)
        <span style="color:#008000;font-weight:bold;">for</span> a <span style="color:#AA22FF;font-weight:bold;">in</span> anchors:
            <span style="color:#008000;font-weight:bold;">try</span>:
                link <span style="color:#666666;">=</span> a[<span style="color:#BA2121;">&#039;href&#039;</span>]
            <span style="color:#008000;font-weight:bold;">except</span> <span style="color:#D2413A;font-weight:bold;">KeyError</span>:
                <span style="color:#008000;font-weight:bold;">continue</span>
            h <span style="color:#666666;">=</span> <span style="color:#008000;">hash</span>(link)
            <span style="color:#008000;font-weight:bold;">if</span> h <span style="color:#AA22FF;font-weight:bold;">in</span> hashes:
                <span style="color:#008000;font-weight:bold;">continue</span>
            hashes<span style="color:#666666;">.</span>add(h)
            <span style="color:#008000;font-weight:bold;">try</span>:
                o <span style="color:#666666;">=</span> urlparse<span style="color:#666666;">.</span>urlparse(link, <span style="color:#BA2121;">&#039;http&#039;</span>)
            <span style="color:#008000;font-weight:bold;">except</span> <span style="color:#D2413A;font-weight:bold;">Exception</span>:
                <span style="color:#008000;font-weight:bold;">continue</span>
            <span style="color:#008000;font-weight:bold;">if</span> o<span style="color:#666666;">.</span>netloc <span style="color:#AA22FF;font-weight:bold;">and</span> <span style="color:#BA2121;">&#039;google&#039;</span> <span style="color:#AA22FF;font-weight:bold;">not</span> <span style="color:#AA22FF;font-weight:bold;">in</span> o<span style="color:#666666;">.</span>netloc:
                <span style="color:#008000;font-weight:bold;">yield</span> link

        <span style="color:#408080;font-style:italic;"># Prepare the URL for the next request.</span>
        start <span style="color:#666666;">+=</span> num
        <span style="color:#008000;font-weight:bold;">if</span> num <span style="color:#666666;">==</span> <span style="color:#666666;">10</span>:
            url <span style="color:#666666;">=</span> url_next_page <span style="color:#666666;">%</span> <span style="color:#008000;">vars</span>()
        <span style="color:#008000;font-weight:bold;">else</span>:
            url <span style="color:#666666;">=</span> url_next_page_num <span style="color:#666666;">%</span> <span style="color:#008000;">vars</span>()

<span style="color:#408080;font-style:italic;"># When run as a script, take all arguments as a search query and run it.</span>
<span style="color:#008000;font-weight:bold;">if</span> __name__ <span style="color:#666666;">==</span> <span style="color:#BA2121;">&quot;__main__&quot;</span>:
    <span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">sys</span>
    query <span style="color:#666666;">=</span> <span style="color:#BA2121;">&#039; &#039;</span><span style="color:#666666;">.</span>join(sys<span style="color:#666666;">.</span>argv[<span style="color:#666666;">1</span>:])
    <span style="color:#008000;font-weight:bold;">if</span> query:
        <span style="color:#008000;font-weight:bold;">for</span> url <span style="color:#AA22FF;font-weight:bold;">in</span> search(query, stop<span style="color:#666666;">=20</span>):
            <span style="color:#008000;font-weight:bold;">print</span>(url)
</pre>
</div>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a>, <a href='http://breakingcode.wordpress.com/category/web-applications/'>Web applications</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/google/'>Google</a>, <a href='http://breakingcode.wordpress.com/tag/information-gathering/'>information gathering</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/recon/'>recon</a>, <a href='http://breakingcode.wordpress.com/tag/search/'>search</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/web/'>web</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/413/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=413&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2010/06/29/google-search-python/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>The forgotten bug: silently patched vulnerabilities</title>
		<link>http://breakingcode.wordpress.com/2010/05/05/the-forgotten-bug-silently-patched-vulnerabilities/</link>
		<comments>http://breakingcode.wordpress.com/2010/05/05/the-forgotten-bug-silently-patched-vulnerabilities/#comments</comments>
		<pubDate>Wed, 05 May 2010 10:39:54 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Vulnerabilities]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[vulnerability research]]></category>
		<category><![CDATA[win32]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=395</guid>
		<description><![CDATA[Researcher Nicolas Economou found the MS10-024 patch came with a little "surprise" in the form of two previously undisclosed high risk vulnerabilities, much worse than the originally reported denial of service. Read the Core Security advisory here: http://archives.neohapsis.com/archives/fulldisclosure/2010-05/0058.html<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=395&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">Last month, Microsoft released the security bulletin <a href="http://www.microsoft.com/technet/security/Bulletin/MS10-024.mspx">MS10-024</a> with a patch for a denial of service vulnerability in Exchange and the Windows SMTP service:</span></p>
<blockquote><p><span style="font-size:120%;"><i>&#8220;This security update resolves one publicly disclosed vulnerability and one privately reported vulnerability in Microsoft Exchange and Windows SMTP Service. The more severe of these vulnerabilities could allow denial of service if an attacker sent a specially crafted DNS response to a computer running the SMTP service.&#8221;</i></span></p></blockquote>
<p><span style="font-size:120%;">However, researcher <a href="http://corelabs.coresecurity.com/index.php?module=Wiki&amp;action=view&amp;type=researcher&amp;name=Nicolas_Economou">Nicolás Economou</a> found an interesting surprise in this patch: two additional, undisclosed vulnerabilities had also been patched&#8230; and they were far more severe than the ones reported! From the <a href="http://archives.neohapsis.com/archives/fulldisclosure/2010-05/0058.html">Core Security advisory</a>:</span></p>
<blockquote>
<p><span style="font-size:120%;"><i>&#8220;Nicolas found that the Windows SMTP Service does its own DNS resolution of MX records rather that use the DNS resolver from the operating system while investigating <a href="http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2010-0024">CVE-2010-0024</a>.</i></span></p>
<p><span style="font-size:120%;"><i>Furthermore, he found that the patch referenced in MS10-024 fixed two severe bugs that were not disclosed as such in the bulletin and had no CVE identifiers assigned to them. Basic analysis of the vulnerabilities disclosed in this advisory indicates that the threat of DNS spoofing attacks against Windows SMTP service and Microsoft Exchange or of exploitation of CVE-2010-0024 was underestimated in MS10-024.</i></span></p>
<p><span style="font-size:120%;"><i>An attacker may leverage the two previously undisclosed vulnerabilities fixed by MS10-014 to spoof responses to any DNS query sent by the Windows SMTP service trivially. DNS response spoofing and cache poisoning attacks are well known to have a variety of security implications with impact beyond just Denial of Service and Information Disclosure as originally stated in MS10-024.&#8221;</i></span></p>
</blockquote>
<p><span style="font-size:120%;">In fact, the two &#8220;new&#8221; vulnerabilities were quite crass. Both Exchange and the SMTP service were doing their own manually crafted DNS queries using incremental transaction IDs, which is a big no-no when implementing DNS because it makes it real easy for attackers to guess the transaction ID and spoof replies, as is a well known fact for&#8230; say&#8230; the last 16 years or so? But as it turns out, attackers didn&#8217;t even need to guess the transaction IDs&#8230; because they weren&#8217;t even being used when parsing the DNS responses! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_eek.gif' alt=':shock:' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">This omission may be easily attributed to the &#8220;embarrasment factor&#8221; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  but it&#8217;s still a terrible idea to patch vulnerabilities silently: IT administrators, unaware of the real danger of the problem, may give the patch a lower priority. A denial of service just means having the mail server down for a while until it restarts, so the patch can wait &#8211; it&#8217;d be worse if the server didn&#8217;t work at all because patching went wrong. On the other hand, a DNS poison vulnerability means having an attacker browse through everyone&#8217;s emails and taking over all other services you may have on the same machine &#8211; patching becomes much more worth the risk.</span></p>
<p><span style="font-size:120%;">Of course, this isn&#8217;t the first time this happens. Practically every vendor did this at one time or another. A quick Google search for <a href="http://www.google.com/search?q=silently+patched+vulnerability">&#8220;silently patched vulnerability&#8221;</a> shows some 1.400.000 hits at the time I&#8217;m writing this, showing this is neither new or uncommon &#8211; and that even small software vendors may easily get caught. Especially thanks to the rise of <a href="http://www.woodmann.com/collaborative/tools/index.php/Category:Executable_Diff_Tools">binary diffing tools</a> that can pinpoint precisely where and how the code was patched.</span></p>
<p><span style="font-size:120%;">Thanks Alfredo Ortega for <a href="https://twitter.com/ortegaalfredo/status/13396750641">pointing out this advisory</a> and providing such a cool sounding title. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </span></p>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/vulnerabilities/'>Vulnerabilities</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/reverse-engineering/'>reverse engineering</a>, <a href='http://breakingcode.wordpress.com/tag/vulnerability/'>vulnerability</a>, <a href='http://breakingcode.wordpress.com/tag/vulnerability-research/'>vulnerability research</a>, <a href='http://breakingcode.wordpress.com/tag/win32/'>win32</a>, <a href='http://breakingcode.wordpress.com/tag/windows/'>Windows</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/395/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=395&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2010/05/05/the-forgotten-bug-silently-patched-vulnerabilities/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Impacket/Pcapy with Python 2.6 on Windows</title>
		<link>http://breakingcode.wordpress.com/2010/04/02/using-impacketpcapy-with-python-2-6-on-windows/</link>
		<comments>http://breakingcode.wordpress.com/2010/04/02/using-impacketpcapy-with-python-2-6-on-windows/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 17:30:46 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[inlineegg]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[pentest]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[SMB]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[vulnerability research]]></category>
		<category><![CDATA[win32]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=367</guid>
		<description><![CDATA[How to install Impacket and Pcapy on Windows for Python 2.6. Includes an MSI of Pcapy for Python 2.6 which is missing from the CORE Security webpage. Download: http://winappdbg.sourceforge.net/blog/pcapy-0.10.5.win32-py2.6.msi<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=367&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">Hello everyone! Today we&#8217;ll be installing <a href="http://oss.coresecurity.com/projects/impacket.html">Impacket</a> and <a href="http://oss.coresecurity.com/projects/pcapy.html">Pcapy</a> for Python 2.6 on Windows. The Impacket module lets you parse network packets, this is very useful for example when developing a sniffer. The Pcapy module interfaces with <a href="http://www.winpcap.org/">WinPcap</a> to do the actual packet capture.</span></p>
<p><span style="font-size:120%;">From the <a href="http://oss.coresecurity.com/">CORE Security</a> webpage:</span></p>
<blockquote><p>What is Impacket?</p>
<p>Impacket is a collection of Python classes focused on providing access to network packets. Impacket allows Python developers to craft and decode network packets in simple and consistent manner. It includes support for low-level protocols such as IP, UDP and TCP, as well as higher-level protocols such as NMB and SMB. Impacket is highly effective when used in conjunction with a packet capture utility or package such as Pcapy. Packets can be constructed from scratch, as well as parsed from raw data. Furthermore, the object oriented API makes it simple to work with deep protocol hierarchies.</p></blockquote>
<blockquote><p>What is Pcapy?</p>
<p>Pcapy is a Python extension module that interfaces with the libpcap packet capture library. Pcapy enables python scripts to capture packets on the network. Pcapy is highly effective when used in conjunction with a packet-handling package such as Impacket, which is a collection of Python classes for constructing and dissecting network packets.</p></blockquote>
<p><span style="font-size:120%;">There is a problem though &#8211; Pcapy hasn&#8217;t been updated in quite a while, so there is no MSI installer for Python 2.6. I&#8217;ve built it myself and hosted in here in the blog, so you don&#8217;t have to. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I&#8217;ve also built an EXE installer for Impacket, it&#8217;s not really needed since it&#8217;s a pure Python module, but why not?</span></p>
<p><span style="font-size:120%;">So this is the list of files we&#8217;ll be needing:</span></p>
<p>
<h3><a href="http://www.winpcap.org/install/bin/WinPcap_4_1_1.exe">WinPcap_4_1_1.exe</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pcapy-0.10.5.win32-py2.6.msi">pcapy-0.10.5.win32-py2.6.msi</a></h3>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/Impacket-0.9.8.0.win32.exe">Impacket-0.9.8.0.win32.exe</a></h3>
</p>
<p><span style="font-size:120%;">Installation is now pretty much straight forward. After running all the installers, let&#8217;s try it out with this example script to dump all connection attempts by sniffing SYN packets:</span></p>
<pre>    C:\Documents and Settings\Mario Vilas\Desktop&gt;python connections.py
    Available network interfaces:
            1 - \Device\NPF_GenericDialupAdapter
            2 - \Device\NPF_{5BE055D9-461D-4F51-99DD-188224D1A6D0}
            3 - \Device\NPF_{9B7DC2FB-7660-4E68-B4EC-DB9682C76E40}
            4 - \Device\NPF_{166A618C-4230-42E7-93AD-298D1145F5BC}
            5 - \Device\NPF_{BE987C8D-D523-49B8-8B95-DDDBAA46EB3F}

    Choose an interface [0 to quit]: 2
    Listening on: \Device\NPF_{5BE055D9-461D-4F51-99DD-188224D1A6D0}
    Connection attempt 10.0.2.15 -&gt; 192.168.254.254
    Connection attempt 10.0.2.15 -&gt; 192.168.254.254
    Connection attempt 10.0.2.15 -&gt; 192.168.254.254
    Connection attempt 10.0.2.15 -&gt; 192.168.254.254
    Connection attempt 10.0.2.15 -&gt; 192.168.254.254
    Connection attempt 10.0.2.15 -&gt; 209.85.227.106
    Connection attempt 10.0.2.15 -&gt; 209.85.227.104
    Connection attempt 10.0.2.15 -&gt; 209.85.227.104
    Connection attempt 10.0.2.15 -&gt; 209.85.227.104
    Connection attempt 10.0.2.15 -&gt; 209.85.227.100
    ^C</pre>
<p><span style="font-size:120%;">Below is the source code to the script. Enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p>
<h2>Updates</h2>
</p>
<ul>
<li><span style="font-size:120%;">A newer version of Impacket is hosted at <a href="http://code.google.com/p/impacket/">Google Code</a>, so I built a new installer. The previous version of the installer, based on the version of Impacket found in the Core Security webpage, is still available here: <a href="http://winappdbg.sourceforge.net/blog/Impacket-0.9.6.0.win32.exe">Impacket-0.9.6.0.win32.exe</a></span></li>
</ul>
<p>
<h2>Download</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/connections.py">connections.py</a></h3>
</p>
<p>
<h2>Source code</h2>
</p>
<p><span id="more-367"></span></p>
<pre><font face="Lucida,Courier New"><font color="#008000">#!/usr/bin/env python</font>

<font color="#008000"># Copyright (c) 2009-2010, Mario Vilas</font>
<font color="#008000"># All rights reserved.</font>
<font color="#008000">#</font>
<font color="#008000"># Redistribution and use in source and binary forms, with or without</font>
<font color="#008000"># modification, are permitted provided that the following conditions are met:</font>
<font color="#008000">#</font>
<font color="#008000">#     * Redistributions of source code must retain the above copyright notice,</font>
<font color="#008000">#       this list of conditions and the following disclaimer.</font>
<font color="#008000">#     * Redistributions in binary form must reproduce the above copyright</font>
<font color="#008000">#       notice,this list of conditions and the following disclaimer in the</font>
<font color="#008000">#       documentation and/or other materials provided with the distribution.</font>
<font color="#008000">#     * Neither the name of the copyright holder nor the names of its</font>
<font color="#008000">#       contributors may be used to endorse or promote products derived from</font>
<font color="#008000">#       this software without specific prior written permission.</font>
<font color="#008000">#</font>
<font color="#008000"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"</font>
<font color="#008000"># AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</font>
<font color="#008000"># IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</font>
<font color="#008000"># ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE</font>
<font color="#008000"># LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</font>
<font color="#008000"># CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</font>
<font color="#008000"># SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</font>
<font color="#008000"># INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN</font>
<font color="#008000"># CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)</font>
<font color="#008000"># ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</font>
<font color="#008000"># POSSIBILITY OF SUCH DAMAGE.</font>

<font color="#C00000">from</font> <font color="#000000">pcapy</font> <font color="#C00000">import</font> <font color="#000000">findalldevs</font><font color="#0000C0">,</font> <font color="#000000">open_live</font>
<font color="#C00000">from</font> <font color="#000000">impacket</font> <font color="#C00000">import</font> <font color="#000000">ImpactDecoder</font><font color="#0000C0">,</font> <font color="#000000">ImpactPacket</font>

<font color="#C00000">def</font> <font color="#000000">get_interface</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#0000C0">:</font>

    <font color="#008000"># Get the list of interfaces we can listen on</font>
    <font color="#000000">ifs</font> <font color="#0000C0">=</font> <font color="#000000">findalldevs</font><font color="#0000C0">(</font><font color="#0000C0">)</font>

    <font color="#008000"># No interfaces found</font>
    <font color="#C00000">if</font> <font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">ifs</font><font color="#0000C0">)</font> <font color="#0000C0">==</font> <font color="#0080C0">0</font><font color="#0000C0">:</font>
        <font color="#C00000">raise</font> <font color="#000000">RuntimeError</font><font color="#0000C0">,</font> <font color="#004080">"Error: no available network interfaces, or you don't have enough permissions on this system."</font>

    <font color="#008000"># A single interface was found</font>
    <font color="#C00000">if</font> <font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">ifs</font><font color="#0000C0">)</font> <font color="#0000C0">==</font> <font color="#0080C0">1</font><font color="#0000C0">:</font>
        <font color="#000000">interface</font> <font color="#0000C0">=</font> <font color="#000000">ifs</font><font color="#0000C0">[</font><font color="#0080C0">0</font><font color="#0000C0">]</font>

    <font color="#008000"># Multiple interfaces found</font>
    <font color="#C00000">else</font><font color="#0000C0">:</font>
        <font color="#C00000">print</font> <font color="#004080">"Available network interfaces:"</font>
        <font color="#C00000">for</font> <font color="#000000">i</font> <font color="#C00000">in</font> <font color="#000000">xrange</font><font color="#0000C0">(</font><font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">ifs</font><font color="#0000C0">)</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
            <font color="#C00000">print</font> <font color="#004080">'\t%i - %s'</font> <font color="#0000C0">%</font> <font color="#0000C0">(</font><font color="#000000">i</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font><font color="#0000C0">,</font> <font color="#000000">ifs</font><font color="#0000C0">[</font><font color="#000000">i</font><font color="#0000C0">]</font><font color="#0000C0">)</font>
        <font color="#C00000">print</font>
        <font color="#C00000">while</font> <font color="#0080C0">1</font><font color="#0000C0">:</font>
            <font color="#000000">choice</font> <font color="#0000C0">=</font> <font color="#000000">raw_input</font><font color="#0000C0">(</font><font color="#004080">"Choose an interface [0 to quit]: "</font><font color="#0000C0">)</font>
            <font color="#C00000">try</font><font color="#0000C0">:</font>
                <font color="#000000">i</font> <font color="#0000C0">=</font> <font color="#000000">int</font><font color="#0000C0">(</font><font color="#000000">choice</font><font color="#0000C0">)</font>
                <font color="#C00000">if</font> <font color="#000000">i</font> <font color="#0000C0">==</font> <font color="#0080C0">0</font><font color="#0000C0">:</font>
                    <font color="#000000">interface</font> <font color="#0000C0">=</font> <font color="#000000">None</font>
                    <font color="#C00000">break</font>
                <font color="#000000">interface</font> <font color="#0000C0">=</font> <font color="#000000">ifs</font><font color="#0000C0">[</font><font color="#000000">i</font><font color="#0000C0">-</font><font color="#0080C0">1</font><font color="#0000C0">]</font>
                <font color="#C00000">break</font>
            <font color="#C00000">except</font> <font color="#000000">Exception</font><font color="#0000C0">:</font>
                <font color="#C00000">pass</font>

    <font color="#008000"># Return the selected interface</font>
    <font color="#C00000">return</font> <font color="#000000">interface</font>

<font color="#C00000">def</font> <font color="#000000">sniff</font><font color="#0000C0">(</font><font color="#000000">interface</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
    <font color="#C00000">print</font> <font color="#004080">"Listening on: %s"</font> <font color="#0000C0">%</font> <font color="#000000">interface</font>

    <font color="#008000"># Open a live capture</font>
    <font color="#000000">reader</font> <font color="#0000C0">=</font> <font color="#000000">open_live</font><font color="#0000C0">(</font><font color="#000000">interface</font><font color="#0000C0">,</font> <font color="#0080C0">1500</font><font color="#0000C0">,</font> <font color="#0080C0">0</font><font color="#0000C0">,</font> <font color="#0080C0">100</font><font color="#0000C0">)</font>

    <font color="#008000"># Set a filter to be notified only for TCP packets</font>
    <font color="#000000">reader</font><font color="#0000C0">.</font><font color="#000000">setfilter</font><font color="#0000C0">(</font><font color="#004080">'ip proto \\tcp'</font><font color="#0000C0">)</font>

    <font color="#008000"># Run the packet capture loop</font>
    <font color="#000000">reader</font><font color="#0000C0">.</font><font color="#000000">loop</font><font color="#0000C0">(</font><font color="#0080C0">0</font><font color="#0000C0">,</font> <font color="#000000">callback</font><font color="#0000C0">)</font>

<font color="#C00000">def</font> <font color="#000000">callback</font><font color="#0000C0">(</font><font color="#000000">hdr</font><font color="#0000C0">,</font> <font color="#000000">data</font><font color="#0000C0">)</font><font color="#0000C0">:</font>

    <font color="#008000"># Parse the Ethernet packet</font>
    <font color="#000000">decoder</font> <font color="#0000C0">=</font> <font color="#000000">ImpactDecoder</font><font color="#0000C0">.</font><font color="#000000">EthDecoder</font><font color="#0000C0">(</font><font color="#0000C0">)</font>
    <font color="#000000">ether</font> <font color="#0000C0">=</font> <font color="#000000">decoder</font><font color="#0000C0">.</font><font color="#000000">decode</font><font color="#0000C0">(</font><font color="#000000">data</font><font color="#0000C0">)</font>

    <font color="#008000"># Parse the IP packet inside the Ethernet packet</font>
    <font color="#000000">iphdr</font> <font color="#0000C0">=</font> <font color="#000000">ether</font><font color="#0000C0">.</font><font color="#000000">child</font><font color="#0000C0">(</font><font color="#0000C0">)</font>

    <font color="#008000"># Parse the TCP packet inside the IP packet</font>
    <font color="#000000">tcphdr</font> <font color="#0000C0">=</font> <font color="#000000">iphdr</font><font color="#0000C0">.</font><font color="#000000">child</font><font color="#0000C0">(</font><font color="#0000C0">)</font>

    <font color="#008000"># Only process SYN packets</font>
    <font color="#C00000">if</font> <font color="#000000">tcphdr</font><font color="#0000C0">.</font><font color="#000000">get_SYN</font><font color="#0000C0">(</font><font color="#0000C0">)</font> <font color="#C00000">and</font> <font color="#C00000">not</font> <font color="#000000">tcphdr</font><font color="#0000C0">.</font><font color="#000000">get_ACK</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#0000C0">:</font>

        <font color="#008000"># Get the source and destination IP addresses</font>
        <font color="#000000">src_ip</font> <font color="#0000C0">=</font> <font color="#000000">iphdr</font><font color="#0000C0">.</font><font color="#000000">get_ip_src</font><font color="#0000C0">(</font><font color="#0000C0">)</font>
        <font color="#000000">dst_ip</font> <font color="#0000C0">=</font> <font color="#000000">iphdr</font><font color="#0000C0">.</font><font color="#000000">get_ip_dst</font><font color="#0000C0">(</font><font color="#0000C0">)</font>

        <font color="#008000"># Print the results</font>
        <font color="#C00000">print</font> <font color="#004080">"Connection attempt %s -&gt; %s"</font> <font color="#0000C0">%</font> <font color="#0000C0">(</font><font color="#000000">src_ip</font><font color="#0000C0">,</font> <font color="#000000">dst_ip</font><font color="#0000C0">)</font>

<font color="#C00000">def</font> <font color="#000000">main</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
    <font color="#000000">interface</font> <font color="#0000C0">=</font> <font color="#000000">get_interface</font><font color="#0000C0">(</font><font color="#0000C0">)</font>
    <font color="#C00000">if</font> <font color="#000000">interface</font><font color="#0000C0">:</font>
        <font color="#000000">sniff</font><font color="#0000C0">(</font><font color="#000000">interface</font><font color="#0000C0">)</font>

<font color="#C00000">if</font> <font color="#000000">__name__</font> <font color="#0000C0">==</font> <font color="#004080">"__main__"</font><font color="#0000C0">:</font>
    <font color="#000000">main</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/inlineegg/'>inlineegg</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/pentest/'>pentest</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/reverse-engineering/'>reverse engineering</a>, <a href='http://breakingcode.wordpress.com/tag/smb/'>SMB</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/vulnerability-research/'>vulnerability research</a>, <a href='http://breakingcode.wordpress.com/tag/win32/'>win32</a>, <a href='http://breakingcode.wordpress.com/tag/windows/'>Windows</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/367/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=367&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2010/04/02/using-impacketpcapy-with-python-2-6-on-windows/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickpost: Using the Pastebin.com API with Python</title>
		<link>http://breakingcode.wordpress.com/2010/03/06/using-the-pastebin-api-with-python/</link>
		<comments>http://breakingcode.wordpress.com/2010/03/06/using-the-pastebin-api-with-python/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 23:59:18 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web applications]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=362</guid>
		<description><![CDATA[Quick script in Python to use the Pastebin.com API. Can be used as a command line script or imported as a module. Download: http://winappdbg.sourceforge.net/blog/pastebin.py<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=362&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">Hello everyone. Today we have a quick script I just coded to access the <a href="http://pastebin.com/api.php">Pastebin.com API</a> from Python. It can be imported like a module or run as a command line script, and the interface is really simple (just one function!). The command line interface allows you to upload files. Enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;"><strong>Edit:</strong> Also see <a href="http://breakingcode.wordpress.com/2012/01/27/pasting-anonymously-to-pastebin-com/">this post</a> on how to use this script to send files anonymously to Pastebin.</span></p>
<p><span style="font-size:120%;"><strong>Updated 28-Jun-2011</strong>: small changes made</span><br />
<span style="font-size:120%;"><strong>Updated 27-Jan-2012</strong>: fixed bug in paste_expire_date, added Epydoc documentation</span><br />
<span style="font-size:120%;"><strong>Updated 28-Jan-2012</strong>: removed paste_subdomain, feature seems to have been deprecated</span></p>
<p>
<h2>Download</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/pastebin.py">pastebin.py</a></h3>
</p>
<p>
<h2>Source code</h2>
</p>
<p><span id="more-362"></span></p>
<div class="highlight" style="background:#f8f8f8;">
<pre style="line-height:125%;"><span style="color:#408080;font-style:italic;">#!/usr/bin/env python</span>

<span style="color:#408080;font-style:italic;"># Copyright (c) 2009-2012, Mario Vilas</span>
<span style="color:#408080;font-style:italic;"># All rights reserved.</span>
<span style="color:#408080;font-style:italic;">#</span>
<span style="color:#408080;font-style:italic;"># Redistribution and use in source and binary forms, with or without</span>
<span style="color:#408080;font-style:italic;"># modification, are permitted provided that the following conditions are met:</span>
<span style="color:#408080;font-style:italic;">#</span>
<span style="color:#408080;font-style:italic;">#     * Redistributions of source code must retain the above copyright notice,</span>
<span style="color:#408080;font-style:italic;">#       this list of conditions and the following disclaimer.</span>
<span style="color:#408080;font-style:italic;">#     * Redistributions in binary form must reproduce the above copyright</span>
<span style="color:#408080;font-style:italic;">#       notice,this list of conditions and the following disclaimer in the</span>
<span style="color:#408080;font-style:italic;">#       documentation and/or other materials provided with the distribution.</span>
<span style="color:#408080;font-style:italic;">#     * Neither the name of the copyright holder nor the names of its</span>
<span style="color:#408080;font-style:italic;">#       contributors may be used to endorse or promote products derived from</span>
<span style="color:#408080;font-style:italic;">#       this software without specific prior written permission.</span>
<span style="color:#408080;font-style:italic;">#</span>
<span style="color:#408080;font-style:italic;"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;</span>
<span style="color:#408080;font-style:italic;"># AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<span style="color:#408080;font-style:italic;"># IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
<span style="color:#408080;font-style:italic;"># ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE</span>
<span style="color:#408080;font-style:italic;"># LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span>
<span style="color:#408080;font-style:italic;"># CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span>
<span style="color:#408080;font-style:italic;"># SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</span>
<span style="color:#408080;font-style:italic;"># INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN</span>
<span style="color:#408080;font-style:italic;"># CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)</span>
<span style="color:#408080;font-style:italic;"># ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</span>
<span style="color:#408080;font-style:italic;"># POSSIBILITY OF SUCH DAMAGE.</span>

<span style="color:#BA2121;font-style:italic;">&quot;&quot;&quot;</span>
<span style="color:#BA2121;font-style:italic;">Unofficial pastebin.com API for Python</span>
<span style="color:#BA2121;font-style:italic;">by Mario Vilas (mvilas at gmail dot com)</span>

<span style="color:#BA2121;font-style:italic;">Unlike the official API, this one doesn&#039;t require an API key.</span>

<span style="color:#BA2121;font-style:italic;">U{http://breakingcode.wordpress.com/2012/01/27/pasting-anonymously-to-pastebin-com/}</span>

<span style="color:#BA2121;font-style:italic;">U{http://breakingcode.wordpress.com/2010/03/06/using-the-pastebin-api-with-python/}</span>

<span style="color:#BA2121;font-style:italic;">Usage examples::</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt; from pastebin import submit</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt;</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt; # Submit a simple text message.</span>
<span style="color:#BA2121;font-style:italic;">    ... url = submit(&quot;This is a test message.&quot;)</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt; print url</span>
<span style="color:#BA2121;font-style:italic;">    http://pastebin.com/G4YWsB1a</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt;</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt; # Submit a simple &quot;hello world&quot; code in Python.</span>
<span style="color:#BA2121;font-style:italic;">    ... # Paste expires in 10 minutes.</span>
<span style="color:#BA2121;font-style:italic;">    ... url = submit(&quot;print \&quot;Hello world!\&quot;&quot;,</span>
<span style="color:#BA2121;font-style:italic;">    ...               paste_format=&quot;python&quot;,</span>
<span style="color:#BA2121;font-style:italic;">    ...               paste_expire_date=&quot;10M&quot;)</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt; print url</span>
<span style="color:#BA2121;font-style:italic;">    http://pastebin.com/rKEVDWHP</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt;</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt; # Submit Apache&#039;s logs as a private paste.</span>
<span style="color:#BA2121;font-style:italic;">    ... # Give the paste a title.</span>
<span style="color:#BA2121;font-style:italic;">    ... url = submit(open(&#039;/var/log/apache/access.log&#039;, &#039;r&#039;).read(),</span>
<span style="color:#BA2121;font-style:italic;">    ...              paste_format=&quot;apache&quot;,</span>
<span style="color:#BA2121;font-style:italic;">    ...              paste_private=True,</span>
<span style="color:#BA2121;font-style:italic;">    ...              paste_name=&quot;My Apache access logs&quot;)</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt; print url</span>
<span style="color:#BA2121;font-style:italic;">    http://pastebin.com/kfepMRLh</span>
<span style="color:#BA2121;font-style:italic;">    &gt;&gt;&gt;</span>
<span style="color:#BA2121;font-style:italic;">&quot;&quot;&quot;</span>

__all__ <span style="color:#666666;">=</span> [<span style="color:#BA2121;">&#039;submit&#039;</span>, <span style="color:#BA2121;">&#039;Pastebin&#039;</span>, <span style="color:#BA2121;">&#039;PastebinError&#039;</span>]

<span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">urllib</span>

<span style="color:#008000;font-weight:bold;">class</span> <span style="color:#0000FF;font-weight:bold;">PastebinError</span>(<span style="color:#D2413A;font-weight:bold;">RuntimeError</span>):
    <span style="color:#BA2121;font-style:italic;">&quot;&quot;&quot;</span>
<span style="color:#BA2121;font-style:italic;">    Pastebin API error.</span>

<span style="color:#BA2121;font-style:italic;">    The error message returned by the web application is stored as the Python</span>
<span style="color:#BA2121;font-style:italic;">    exception message.</span>
<span style="color:#BA2121;font-style:italic;">    &quot;&quot;&quot;</span>

<span style="color:#008000;font-weight:bold;">class</span> <span style="color:#0000FF;font-weight:bold;">Pastebin</span>(<span style="color:#008000;">object</span>):
    <span style="color:#BA2121;font-style:italic;">&quot;&quot;&quot;</span>
<span style="color:#BA2121;font-style:italic;">    Unofficial python interface to the Pastebin legacy API.</span>

<span style="color:#BA2121;font-style:italic;">    Unlike the official API, this one doesn&#039;t require an API key, so it&#039;s</span>
<span style="color:#BA2121;font-style:italic;">    virtually anonymous.</span>

<span style="color:#BA2121;font-style:italic;">    @warn: To be B{completely} anonymous you&#039;ll have to hide your IP address as</span>
<span style="color:#BA2121;font-style:italic;">        well, either by using an HTTP proxy or the Tor network.</span>

<span style="color:#BA2121;font-style:italic;">        To use an HTTP proxy, set the HTTP_PROXY environment variable as per</span>
<span style="color:#BA2121;font-style:italic;">        the documentation of the Python standard C{urllib} module:</span>
<span style="color:#BA2121;font-style:italic;">        U{http://docs.python.org/library/urllib.html}</span>

<span style="color:#BA2121;font-style:italic;">        To go through the Tor network, consult the following Wiki document:</span>
<span style="color:#BA2121;font-style:italic;">        U{https://trac.torproject.org/projects/tor/wiki/doc/TorifyHOWTO}</span>

<span style="color:#BA2121;font-style:italic;">    @type paste_expire_date: tuple(str)</span>
<span style="color:#BA2121;font-style:italic;">    @cvar paste_expire_date: Valid C{paste_expire_date} values, see L{submit}.</span>

<span style="color:#BA2121;font-style:italic;">    @type paste_format: tuple(str)</span>
<span style="color:#BA2121;font-style:italic;">    @cvar paste_format: Valid C{parse_format} values, see L{submit}.</span>
<span style="color:#BA2121;font-style:italic;">    &quot;&quot;&quot;</span>

    <span style="color:#408080;font-style:italic;"># Base domain name</span>
    _base_domain <span style="color:#666666;">=</span> <span style="color:#BA2121;">&#039;pastebin.com&#039;</span>

    <span style="color:#408080;font-style:italic;"># Valid Pastebin URLs begin with this string</span>
    _prefix_url <span style="color:#666666;">=</span> <span style="color:#BA2121;">&#039;http://</span><span style="color:#BB6688;font-weight:bold;">%s</span><span style="color:#BA2121;">/&#039;</span> <span style="color:#666666;">%</span> _base_domain

    <span style="color:#408080;font-style:italic;"># Valid Pastebin URLs with a custom subdomain begin with this string</span>
    _subdomain_url <span style="color:#666666;">=</span> <span style="color:#BA2121;">&#039;http://</span><span style="color:#BB6688;font-weight:bold;">%%</span><span style="color:#BA2121;">s.</span><span style="color:#BB6688;font-weight:bold;">%s</span><span style="color:#BA2121;">/&#039;</span> <span style="color:#666666;">%</span> _base_domain

    <span style="color:#408080;font-style:italic;"># URL to the POST API</span>
    _api_url <span style="color:#666666;">=</span> <span style="color:#BA2121;">&#039;http://</span><span style="color:#BB6688;font-weight:bold;">%s</span><span style="color:#BA2121;">/api_public.php&#039;</span> <span style="color:#666666;">%</span> _base_domain

    <span style="color:#408080;font-style:italic;"># Valid paste_expire_date values</span>
    paste_expire_date <span style="color:#666666;">=</span> (<span style="color:#BA2121;">&#039;N&#039;</span>, <span style="color:#BA2121;">&#039;10M&#039;</span>, <span style="color:#BA2121;">&#039;1H&#039;</span>, <span style="color:#BA2121;">&#039;1D&#039;</span>, <span style="color:#BA2121;">&#039;1M&#039;</span>)

    <span style="color:#408080;font-style:italic;"># Valid parse_format values</span>
    paste_format <span style="color:#666666;">=</span> (
        <span style="color:#BA2121;">&#039;4cs&#039;</span>,              <span style="color:#408080;font-style:italic;"># 4CS</span>
        <span style="color:#BA2121;">&#039;6502acme&#039;</span>,         <span style="color:#408080;font-style:italic;"># 6502 ACME Cross Assembler</span>
        <span style="color:#BA2121;">&#039;6502kickass&#039;</span>,      <span style="color:#408080;font-style:italic;"># 6502 Kick Assembler</span>
        <span style="color:#BA2121;">&#039;6502tasm&#039;</span>,         <span style="color:#408080;font-style:italic;"># 6502 TASM/64TASS</span>
        <span style="color:#BA2121;">&#039;abap&#039;</span>,             <span style="color:#408080;font-style:italic;"># ABAP</span>
        <span style="color:#BA2121;">&#039;actionscript&#039;</span>,     <span style="color:#408080;font-style:italic;"># ActionScript</span>
        <span style="color:#BA2121;">&#039;actionscript3&#039;</span>,    <span style="color:#408080;font-style:italic;"># ActionScript 3</span>
        <span style="color:#BA2121;">&#039;ada&#039;</span>,              <span style="color:#408080;font-style:italic;"># Ada</span>
        <span style="color:#BA2121;">&#039;algol68&#039;</span>,          <span style="color:#408080;font-style:italic;"># ALGOL 68</span>
        <span style="color:#BA2121;">&#039;apache&#039;</span>,           <span style="color:#408080;font-style:italic;"># Apache Log</span>
        <span style="color:#BA2121;">&#039;applescript&#039;</span>,      <span style="color:#408080;font-style:italic;"># AppleScript</span>
        <span style="color:#BA2121;">&#039;apt_sources&#039;</span>,      <span style="color:#408080;font-style:italic;"># APT Sources</span>
        <span style="color:#BA2121;">&#039;asm&#039;</span>,              <span style="color:#408080;font-style:italic;"># ASM (NASM)</span>
        <span style="color:#BA2121;">&#039;asp&#039;</span>,              <span style="color:#408080;font-style:italic;"># ASP</span>
        <span style="color:#BA2121;">&#039;autoconf&#039;</span>,         <span style="color:#408080;font-style:italic;"># autoconf</span>
        <span style="color:#BA2121;">&#039;autohotkey&#039;</span>,       <span style="color:#408080;font-style:italic;"># Autohotkey</span>
        <span style="color:#BA2121;">&#039;autoit&#039;</span>,           <span style="color:#408080;font-style:italic;"># AutoIt</span>
        <span style="color:#BA2121;">&#039;avisynth&#039;</span>,         <span style="color:#408080;font-style:italic;"># Avisynth</span>
        <span style="color:#BA2121;">&#039;awk&#039;</span>,              <span style="color:#408080;font-style:italic;"># Awk</span>
        <span style="color:#BA2121;">&#039;bascomavr&#039;</span>,        <span style="color:#408080;font-style:italic;"># BASCOM AVR</span>
        <span style="color:#BA2121;">&#039;bash&#039;</span>,             <span style="color:#408080;font-style:italic;"># Bash</span>
        <span style="color:#BA2121;">&#039;basic4gl&#039;</span>,         <span style="color:#408080;font-style:italic;"># Basic4GL</span>
        <span style="color:#BA2121;">&#039;bibtex&#039;</span>,           <span style="color:#408080;font-style:italic;"># BibTeX</span>
        <span style="color:#BA2121;">&#039;blitzbasic&#039;</span>,       <span style="color:#408080;font-style:italic;"># Blitz Basic</span>
        <span style="color:#BA2121;">&#039;bnf&#039;</span>,              <span style="color:#408080;font-style:italic;"># BNF</span>
        <span style="color:#BA2121;">&#039;boo&#039;</span>,              <span style="color:#408080;font-style:italic;"># BOO</span>
        <span style="color:#BA2121;">&#039;bf&#039;</span>,               <span style="color:#408080;font-style:italic;"># BrainFuck</span>
        <span style="color:#BA2121;">&#039;c&#039;</span>,                <span style="color:#408080;font-style:italic;"># C</span>
        <span style="color:#BA2121;">&#039;c_mac&#039;</span>,            <span style="color:#408080;font-style:italic;"># C for Macs</span>
        <span style="color:#BA2121;">&#039;cil&#039;</span>,              <span style="color:#408080;font-style:italic;"># C Intermediate Language</span>
        <span style="color:#BA2121;">&#039;csharp&#039;</span>,           <span style="color:#408080;font-style:italic;"># C#</span>
        <span style="color:#BA2121;">&#039;cpp&#039;</span>,              <span style="color:#408080;font-style:italic;"># C++</span>
        <span style="color:#BA2121;">&#039;cpp-qt&#039;</span>,           <span style="color:#408080;font-style:italic;"># C++ (with QT extensions)</span>
        <span style="color:#BA2121;">&#039;c_loadrunner&#039;</span>,     <span style="color:#408080;font-style:italic;"># C: Loadrunner</span>
        <span style="color:#BA2121;">&#039;caddcl&#039;</span>,           <span style="color:#408080;font-style:italic;"># CAD DCL</span>
        <span style="color:#BA2121;">&#039;cadlisp&#039;</span>,          <span style="color:#408080;font-style:italic;"># CAD Lisp</span>
        <span style="color:#BA2121;">&#039;cfdg&#039;</span>,             <span style="color:#408080;font-style:italic;"># CFDG</span>
        <span style="color:#BA2121;">&#039;chaiscript&#039;</span>,       <span style="color:#408080;font-style:italic;"># ChaiScript</span>
        <span style="color:#BA2121;">&#039;clojure&#039;</span>,          <span style="color:#408080;font-style:italic;"># Clojure</span>
        <span style="color:#BA2121;">&#039;klonec&#039;</span>,           <span style="color:#408080;font-style:italic;"># Clone C</span>
        <span style="color:#BA2121;">&#039;klonecpp&#039;</span>,         <span style="color:#408080;font-style:italic;"># Clone C++</span>
        <span style="color:#BA2121;">&#039;cmake&#039;</span>,            <span style="color:#408080;font-style:italic;"># CMake</span>
        <span style="color:#BA2121;">&#039;cobol&#039;</span>,            <span style="color:#408080;font-style:italic;"># COBOL</span>
        <span style="color:#BA2121;">&#039;coffeescript&#039;</span>,     <span style="color:#408080;font-style:italic;"># CoffeeScript</span>
        <span style="color:#BA2121;">&#039;cfm&#039;</span>,              <span style="color:#408080;font-style:italic;"># ColdFusion</span>
        <span style="color:#BA2121;">&#039;css&#039;</span>,              <span style="color:#408080;font-style:italic;"># CSS</span>
        <span style="color:#BA2121;">&#039;cuesheet&#039;</span>,         <span style="color:#408080;font-style:italic;"># Cuesheet</span>
        <span style="color:#BA2121;">&#039;d&#039;</span>,                <span style="color:#408080;font-style:italic;"># D</span>
        <span style="color:#BA2121;">&#039;dcs&#039;</span>,              <span style="color:#408080;font-style:italic;"># DCS</span>
        <span style="color:#BA2121;">&#039;delphi&#039;</span>,           <span style="color:#408080;font-style:italic;"># Delphi</span>
        <span style="color:#BA2121;">&#039;oxygene&#039;</span>,          <span style="color:#408080;font-style:italic;"># Delphi Prism (Oxygene)</span>
        <span style="color:#BA2121;">&#039;diff&#039;</span>,             <span style="color:#408080;font-style:italic;"># Diff</span>
        <span style="color:#BA2121;">&#039;div&#039;</span>,              <span style="color:#408080;font-style:italic;"># DIV</span>
        <span style="color:#BA2121;">&#039;dos&#039;</span>,              <span style="color:#408080;font-style:italic;"># DOS</span>
        <span style="color:#BA2121;">&#039;dot&#039;</span>,              <span style="color:#408080;font-style:italic;"># DOT</span>
        <span style="color:#BA2121;">&#039;e&#039;</span>,                <span style="color:#408080;font-style:italic;"># E</span>
        <span style="color:#BA2121;">&#039;ecmascript&#039;</span>,       <span style="color:#408080;font-style:italic;"># ECMAScript</span>
        <span style="color:#BA2121;">&#039;eiffel&#039;</span>,           <span style="color:#408080;font-style:italic;"># Eiffel</span>
        <span style="color:#BA2121;">&#039;email&#039;</span>,            <span style="color:#408080;font-style:italic;"># Email</span>
        <span style="color:#BA2121;">&#039;epc&#039;</span>,              <span style="color:#408080;font-style:italic;"># EPC</span>
        <span style="color:#BA2121;">&#039;erlang&#039;</span>,           <span style="color:#408080;font-style:italic;"># Erlang</span>
        <span style="color:#BA2121;">&#039;fsharp&#039;</span>,           <span style="color:#408080;font-style:italic;"># F#</span>
        <span style="color:#BA2121;">&#039;falcon&#039;</span>,           <span style="color:#408080;font-style:italic;"># Falcon</span>
        <span style="color:#BA2121;">&#039;fo&#039;</span>,               <span style="color:#408080;font-style:italic;"># FO Language</span>
        <span style="color:#BA2121;">&#039;f1&#039;</span>,               <span style="color:#408080;font-style:italic;"># Formula One</span>
        <span style="color:#BA2121;">&#039;fortran&#039;</span>,          <span style="color:#408080;font-style:italic;"># Fortran</span>
        <span style="color:#BA2121;">&#039;freebasic&#039;</span>,        <span style="color:#408080;font-style:italic;"># FreeBasic</span>
        <span style="color:#BA2121;">&#039;freeswitch&#039;</span>,       <span style="color:#408080;font-style:italic;"># FreeSWITCH</span>
        <span style="color:#BA2121;">&#039;gambas&#039;</span>,           <span style="color:#408080;font-style:italic;"># GAMBAS</span>
        <span style="color:#BA2121;">&#039;gml&#039;</span>,              <span style="color:#408080;font-style:italic;"># Game Maker</span>
        <span style="color:#BA2121;">&#039;gdb&#039;</span>,              <span style="color:#408080;font-style:italic;"># GDB</span>
        <span style="color:#BA2121;">&#039;genero&#039;</span>,           <span style="color:#408080;font-style:italic;"># Genero</span>
        <span style="color:#BA2121;">&#039;genie&#039;</span>,            <span style="color:#408080;font-style:italic;"># Genie</span>
        <span style="color:#BA2121;">&#039;gettext&#039;</span>,          <span style="color:#408080;font-style:italic;"># GetText</span>
        <span style="color:#BA2121;">&#039;go&#039;</span>,               <span style="color:#408080;font-style:italic;"># Go</span>
        <span style="color:#BA2121;">&#039;groovy&#039;</span>,           <span style="color:#408080;font-style:italic;"># Groovy</span>
        <span style="color:#BA2121;">&#039;gwbasic&#039;</span>,          <span style="color:#408080;font-style:italic;"># GwBasic</span>
        <span style="color:#BA2121;">&#039;haskell&#039;</span>,          <span style="color:#408080;font-style:italic;"># Haskell</span>
        <span style="color:#BA2121;">&#039;hicest&#039;</span>,           <span style="color:#408080;font-style:italic;"># HicEst</span>
        <span style="color:#BA2121;">&#039;hq9plus&#039;</span>,          <span style="color:#408080;font-style:italic;"># HQ9 Plus</span>
        <span style="color:#BA2121;">&#039;html4strict&#039;</span>,      <span style="color:#408080;font-style:italic;"># HTML</span>
        <span style="color:#BA2121;">&#039;html5&#039;</span>,            <span style="color:#408080;font-style:italic;"># HTML 5</span>
        <span style="color:#BA2121;">&#039;icon&#039;</span>,             <span style="color:#408080;font-style:italic;"># Icon</span>
        <span style="color:#BA2121;">&#039;idl&#039;</span>,              <span style="color:#408080;font-style:italic;"># IDL</span>
        <span style="color:#BA2121;">&#039;ini&#039;</span>,              <span style="color:#408080;font-style:italic;"># INI file</span>
        <span style="color:#BA2121;">&#039;inno&#039;</span>,             <span style="color:#408080;font-style:italic;"># Inno Script</span>
        <span style="color:#BA2121;">&#039;intercal&#039;</span>,         <span style="color:#408080;font-style:italic;"># INTERCAL</span>
        <span style="color:#BA2121;">&#039;io&#039;</span>,               <span style="color:#408080;font-style:italic;"># IO</span>
        <span style="color:#BA2121;">&#039;j&#039;</span>,                <span style="color:#408080;font-style:italic;"># J</span>
        <span style="color:#BA2121;">&#039;java&#039;</span>,             <span style="color:#408080;font-style:italic;"># Java</span>
        <span style="color:#BA2121;">&#039;java5&#039;</span>,            <span style="color:#408080;font-style:italic;"># Java 5</span>
        <span style="color:#BA2121;">&#039;javascript&#039;</span>,       <span style="color:#408080;font-style:italic;"># JavaScript</span>
        <span style="color:#BA2121;">&#039;jquery&#039;</span>,           <span style="color:#408080;font-style:italic;"># jQuery</span>
        <span style="color:#BA2121;">&#039;kixtart&#039;</span>,          <span style="color:#408080;font-style:italic;"># KiXtart</span>
        <span style="color:#BA2121;">&#039;latex&#039;</span>,            <span style="color:#408080;font-style:italic;"># Latex</span>
        <span style="color:#BA2121;">&#039;lb&#039;</span>,               <span style="color:#408080;font-style:italic;"># Liberty BASIC</span>
        <span style="color:#BA2121;">&#039;lsl2&#039;</span>,             <span style="color:#408080;font-style:italic;"># Linden Scripting</span>
        <span style="color:#BA2121;">&#039;lisp&#039;</span>,             <span style="color:#408080;font-style:italic;"># Lisp</span>
        <span style="color:#BA2121;">&#039;llvm&#039;</span>,             <span style="color:#408080;font-style:italic;"># LLVM</span>
        <span style="color:#BA2121;">&#039;locobasic&#039;</span>,        <span style="color:#408080;font-style:italic;"># Loco Basic</span>
        <span style="color:#BA2121;">&#039;logtalk&#039;</span>,          <span style="color:#408080;font-style:italic;"># Logtalk</span>
        <span style="color:#BA2121;">&#039;lolcode&#039;</span>,          <span style="color:#408080;font-style:italic;"># LOL Code</span>
        <span style="color:#BA2121;">&#039;lotusformulas&#039;</span>,    <span style="color:#408080;font-style:italic;"># Lotus Formulas</span>
        <span style="color:#BA2121;">&#039;lotusscript&#039;</span>,      <span style="color:#408080;font-style:italic;"># Lotus Script</span>
        <span style="color:#BA2121;">&#039;lscript&#039;</span>,          <span style="color:#408080;font-style:italic;"># LScript</span>
        <span style="color:#BA2121;">&#039;lua&#039;</span>,              <span style="color:#408080;font-style:italic;"># Lua</span>
        <span style="color:#BA2121;">&#039;m68k&#039;</span>,             <span style="color:#408080;font-style:italic;"># M68000 Assembler</span>
        <span style="color:#BA2121;">&#039;magiksf&#039;</span>,          <span style="color:#408080;font-style:italic;"># MagikSF</span>
        <span style="color:#BA2121;">&#039;make&#039;</span>,             <span style="color:#408080;font-style:italic;"># Make</span>
        <span style="color:#BA2121;">&#039;mapbasic&#039;</span>,         <span style="color:#408080;font-style:italic;"># MapBasic</span>
        <span style="color:#BA2121;">&#039;matlab&#039;</span>,           <span style="color:#408080;font-style:italic;"># MatLab</span>
        <span style="color:#BA2121;">&#039;mirc&#039;</span>,             <span style="color:#408080;font-style:italic;"># mIRC</span>
        <span style="color:#BA2121;">&#039;mmix&#039;</span>,             <span style="color:#408080;font-style:italic;"># MIX Assembler</span>
        <span style="color:#BA2121;">&#039;modula2&#039;</span>,          <span style="color:#408080;font-style:italic;"># Modula 2</span>
        <span style="color:#BA2121;">&#039;modula3&#039;</span>,          <span style="color:#408080;font-style:italic;"># Modula 3</span>
        <span style="color:#BA2121;">&#039;68000devpac&#039;</span>,      <span style="color:#408080;font-style:italic;"># Motorola 68000 HiSoft Dev</span>
        <span style="color:#BA2121;">&#039;mpasm&#039;</span>,            <span style="color:#408080;font-style:italic;"># MPASM</span>
        <span style="color:#BA2121;">&#039;mxml&#039;</span>,             <span style="color:#408080;font-style:italic;"># MXML</span>
        <span style="color:#BA2121;">&#039;mysql&#039;</span>,            <span style="color:#408080;font-style:italic;"># MySQL</span>
        <span style="color:#BA2121;">&#039;newlisp&#039;</span>,          <span style="color:#408080;font-style:italic;"># newLISP</span>
        <span style="color:#BA2121;">&#039;text&#039;</span>,             <span style="color:#408080;font-style:italic;"># None</span>
        <span style="color:#BA2121;">&#039;nsis&#039;</span>,             <span style="color:#408080;font-style:italic;"># NullSoft Installer</span>
        <span style="color:#BA2121;">&#039;oberon2&#039;</span>,          <span style="color:#408080;font-style:italic;"># Oberon 2</span>
        <span style="color:#BA2121;">&#039;objeck&#039;</span>,           <span style="color:#408080;font-style:italic;"># Objeck Programming Langua</span>
        <span style="color:#BA2121;">&#039;objc&#039;</span>,             <span style="color:#408080;font-style:italic;"># Objective C</span>
        <span style="color:#BA2121;">&#039;ocaml-brief&#039;</span>,      <span style="color:#408080;font-style:italic;"># OCalm Brief</span>
        <span style="color:#BA2121;">&#039;ocaml&#039;</span>,            <span style="color:#408080;font-style:italic;"># OCaml</span>
        <span style="color:#BA2121;">&#039;pf&#039;</span>,               <span style="color:#408080;font-style:italic;"># OpenBSD PACKET FILTER</span>
        <span style="color:#BA2121;">&#039;glsl&#039;</span>,             <span style="color:#408080;font-style:italic;"># OpenGL Shading</span>
        <span style="color:#BA2121;">&#039;oobas&#039;</span>,            <span style="color:#408080;font-style:italic;"># Openoffice BASIC</span>
        <span style="color:#BA2121;">&#039;oracle11&#039;</span>,         <span style="color:#408080;font-style:italic;"># Oracle 11</span>
        <span style="color:#BA2121;">&#039;oracle8&#039;</span>,          <span style="color:#408080;font-style:italic;"># Oracle 8</span>
        <span style="color:#BA2121;">&#039;oz&#039;</span>,               <span style="color:#408080;font-style:italic;"># Oz</span>
        <span style="color:#BA2121;">&#039;pascal&#039;</span>,           <span style="color:#408080;font-style:italic;"># Pascal</span>
        <span style="color:#BA2121;">&#039;pawn&#039;</span>,             <span style="color:#408080;font-style:italic;"># PAWN</span>
        <span style="color:#BA2121;">&#039;pcre&#039;</span>,             <span style="color:#408080;font-style:italic;"># PCRE</span>
        <span style="color:#BA2121;">&#039;per&#039;</span>,              <span style="color:#408080;font-style:italic;"># Per</span>
        <span style="color:#BA2121;">&#039;perl&#039;</span>,             <span style="color:#408080;font-style:italic;"># Perl</span>
        <span style="color:#BA2121;">&#039;perl6&#039;</span>,            <span style="color:#408080;font-style:italic;"># Perl 6</span>
        <span style="color:#BA2121;">&#039;php&#039;</span>,              <span style="color:#408080;font-style:italic;"># PHP</span>
        <span style="color:#BA2121;">&#039;php-brief&#039;</span>,        <span style="color:#408080;font-style:italic;"># PHP Brief</span>
        <span style="color:#BA2121;">&#039;pic16&#039;</span>,            <span style="color:#408080;font-style:italic;"># Pic 16</span>
        <span style="color:#BA2121;">&#039;pike&#039;</span>,             <span style="color:#408080;font-style:italic;"># Pike</span>
        <span style="color:#BA2121;">&#039;pixelbender&#039;</span>,      <span style="color:#408080;font-style:italic;"># Pixel Bender</span>
        <span style="color:#BA2121;">&#039;plsql&#039;</span>,            <span style="color:#408080;font-style:italic;"># PL/SQL</span>
        <span style="color:#BA2121;">&#039;postgresql&#039;</span>,       <span style="color:#408080;font-style:italic;"># PostgreSQL</span>
        <span style="color:#BA2121;">&#039;povray&#039;</span>,           <span style="color:#408080;font-style:italic;"># POV-Ray</span>
        <span style="color:#BA2121;">&#039;powershell&#039;</span>,       <span style="color:#408080;font-style:italic;"># Power Shell</span>
        <span style="color:#BA2121;">&#039;powerbuilder&#039;</span>,     <span style="color:#408080;font-style:italic;"># PowerBuilder</span>
        <span style="color:#BA2121;">&#039;proftpd&#039;</span>,          <span style="color:#408080;font-style:italic;"># ProFTPd</span>
        <span style="color:#BA2121;">&#039;progress&#039;</span>,         <span style="color:#408080;font-style:italic;"># Progress</span>
        <span style="color:#BA2121;">&#039;prolog&#039;</span>,           <span style="color:#408080;font-style:italic;"># Prolog</span>
        <span style="color:#BA2121;">&#039;properties&#039;</span>,       <span style="color:#408080;font-style:italic;"># Properties</span>
        <span style="color:#BA2121;">&#039;providex&#039;</span>,         <span style="color:#408080;font-style:italic;"># ProvideX</span>
        <span style="color:#BA2121;">&#039;purebasic&#039;</span>,        <span style="color:#408080;font-style:italic;"># PureBasic</span>
        <span style="color:#BA2121;">&#039;pycon&#039;</span>,            <span style="color:#408080;font-style:italic;"># PyCon</span>
        <span style="color:#BA2121;">&#039;python&#039;</span>,           <span style="color:#408080;font-style:italic;"># Python</span>
        <span style="color:#BA2121;">&#039;q&#039;</span>,                <span style="color:#408080;font-style:italic;"># q/kdb+</span>
        <span style="color:#BA2121;">&#039;qbasic&#039;</span>,           <span style="color:#408080;font-style:italic;"># QBasic</span>
        <span style="color:#BA2121;">&#039;rsplus&#039;</span>,           <span style="color:#408080;font-style:italic;"># R</span>
        <span style="color:#BA2121;">&#039;rails&#039;</span>,            <span style="color:#408080;font-style:italic;"># Rails</span>
        <span style="color:#BA2121;">&#039;rebol&#039;</span>,            <span style="color:#408080;font-style:italic;"># REBOL</span>
        <span style="color:#BA2121;">&#039;reg&#039;</span>,              <span style="color:#408080;font-style:italic;"># REG</span>
        <span style="color:#BA2121;">&#039;robots&#039;</span>,           <span style="color:#408080;font-style:italic;"># Robots</span>
        <span style="color:#BA2121;">&#039;rpmspec&#039;</span>,          <span style="color:#408080;font-style:italic;"># RPM Spec</span>
        <span style="color:#BA2121;">&#039;ruby&#039;</span>,             <span style="color:#408080;font-style:italic;"># Ruby</span>
        <span style="color:#BA2121;">&#039;gnuplot&#039;</span>,          <span style="color:#408080;font-style:italic;"># Ruby Gnuplot</span>
        <span style="color:#BA2121;">&#039;sas&#039;</span>,              <span style="color:#408080;font-style:italic;"># SAS</span>
        <span style="color:#BA2121;">&#039;scala&#039;</span>,            <span style="color:#408080;font-style:italic;"># Scala</span>
        <span style="color:#BA2121;">&#039;scheme&#039;</span>,           <span style="color:#408080;font-style:italic;"># Scheme</span>
        <span style="color:#BA2121;">&#039;scilab&#039;</span>,           <span style="color:#408080;font-style:italic;"># Scilab</span>
        <span style="color:#BA2121;">&#039;sdlbasic&#039;</span>,         <span style="color:#408080;font-style:italic;"># SdlBasic</span>
        <span style="color:#BA2121;">&#039;smalltalk&#039;</span>,        <span style="color:#408080;font-style:italic;"># Smalltalk</span>
        <span style="color:#BA2121;">&#039;smarty&#039;</span>,           <span style="color:#408080;font-style:italic;"># Smarty</span>
        <span style="color:#BA2121;">&#039;sql&#039;</span>,              <span style="color:#408080;font-style:italic;"># SQL</span>
        <span style="color:#BA2121;">&#039;systemverilog&#039;</span>,    <span style="color:#408080;font-style:italic;"># SystemVerilog</span>
        <span style="color:#BA2121;">&#039;tsql&#039;</span>,             <span style="color:#408080;font-style:italic;"># T-SQL</span>
        <span style="color:#BA2121;">&#039;tcl&#039;</span>,              <span style="color:#408080;font-style:italic;"># TCL</span>
        <span style="color:#BA2121;">&#039;teraterm&#039;</span>,         <span style="color:#408080;font-style:italic;"># Tera Term</span>
        <span style="color:#BA2121;">&#039;thinbasic&#039;</span>,        <span style="color:#408080;font-style:italic;"># thinBasic</span>
        <span style="color:#BA2121;">&#039;typoscript&#039;</span>,       <span style="color:#408080;font-style:italic;"># TypoScript</span>
        <span style="color:#BA2121;">&#039;unicon&#039;</span>,           <span style="color:#408080;font-style:italic;"># Unicon</span>
        <span style="color:#BA2121;">&#039;uscript&#039;</span>,          <span style="color:#408080;font-style:italic;"># UnrealScript</span>
        <span style="color:#BA2121;">&#039;vala&#039;</span>,             <span style="color:#408080;font-style:italic;"># Vala</span>
        <span style="color:#BA2121;">&#039;vbnet&#039;</span>,            <span style="color:#408080;font-style:italic;"># VB.NET</span>
        <span style="color:#BA2121;">&#039;verilog&#039;</span>,          <span style="color:#408080;font-style:italic;"># VeriLog</span>
        <span style="color:#BA2121;">&#039;vhdl&#039;</span>,             <span style="color:#408080;font-style:italic;"># VHDL</span>
        <span style="color:#BA2121;">&#039;vim&#039;</span>,              <span style="color:#408080;font-style:italic;"># VIM</span>
        <span style="color:#BA2121;">&#039;visualprolog&#039;</span>,     <span style="color:#408080;font-style:italic;"># Visual Pro Log</span>
        <span style="color:#BA2121;">&#039;vb&#039;</span>,               <span style="color:#408080;font-style:italic;"># VisualBasic</span>
        <span style="color:#BA2121;">&#039;visualfoxpro&#039;</span>,     <span style="color:#408080;font-style:italic;"># VisualFoxPro</span>
        <span style="color:#BA2121;">&#039;whitespace&#039;</span>,       <span style="color:#408080;font-style:italic;"># WhiteSpace</span>
        <span style="color:#BA2121;">&#039;whois&#039;</span>,            <span style="color:#408080;font-style:italic;"># WHOIS</span>
        <span style="color:#BA2121;">&#039;winbatch&#039;</span>,         <span style="color:#408080;font-style:italic;"># Winbatch</span>
        <span style="color:#BA2121;">&#039;xbasic&#039;</span>,           <span style="color:#408080;font-style:italic;"># XBasic</span>
        <span style="color:#BA2121;">&#039;xml&#039;</span>,              <span style="color:#408080;font-style:italic;"># XML</span>
        <span style="color:#BA2121;">&#039;xorg_conf&#039;</span>,        <span style="color:#408080;font-style:italic;"># Xorg Config</span>
        <span style="color:#BA2121;">&#039;xpp&#039;</span>,              <span style="color:#408080;font-style:italic;"># XPP</span>
        <span style="color:#BA2121;">&#039;yaml&#039;</span>,             <span style="color:#408080;font-style:italic;"># YAML</span>
        <span style="color:#BA2121;">&#039;z80&#039;</span>,              <span style="color:#408080;font-style:italic;"># Z80 Assembler</span>
        <span style="color:#BA2121;">&#039;zxbasic&#039;</span>,          <span style="color:#408080;font-style:italic;"># ZXBasic</span>
    )

    <span style="color:#AA22FF;">@classmethod</span>
    <span style="color:#008000;font-weight:bold;">def</span> <span style="color:#0000FF;">submit</span>(cls, paste_code,
                paste_name <span style="color:#666666;">=</span> <span style="color:#008000;">None</span>, paste_private <span style="color:#666666;">=</span> <span style="color:#008000;">None</span>,
                paste_expire_date <span style="color:#666666;">=</span> <span style="color:#008000;">None</span>, paste_format <span style="color:#666666;">=</span> <span style="color:#008000;">None</span>):
        <span style="color:#BA2121;font-style:italic;">&quot;&quot;&quot;</span>
<span style="color:#BA2121;font-style:italic;">        Submit a code snippet to Pastebin.</span>

<span style="color:#BA2121;font-style:italic;">        @type  paste_code: str</span>
<span style="color:#BA2121;font-style:italic;">        @param paste_code: Code or text to send to U{http://pastebin.com}.</span>

<span style="color:#BA2121;font-style:italic;">        @type  paste_name: str</span>
<span style="color:#BA2121;font-style:italic;">        @param paste_name: (Optional) Name of the author of the paste.</span>
<span style="color:#BA2121;font-style:italic;">            Default is to paste anonymously.</span>

<span style="color:#BA2121;font-style:italic;">        @type  paste_private: bool</span>
<span style="color:#BA2121;font-style:italic;">        @param paste_private: (Optional) C{True} if the paste is private (only</span>
<span style="color:#BA2121;font-style:italic;">            visible with the link), C{False} if it&#039;s public (indexed and</span>
<span style="color:#BA2121;font-style:italic;">            searchable). The Pastebin FAQ (U{http://pastebin.com/faq}) claims</span>
<span style="color:#BA2121;font-style:italic;">            private pastes are not indexed by search engines (aka Google).</span>

<span style="color:#BA2121;font-style:italic;">        @type  paste_expire_date: str</span>
<span style="color:#BA2121;font-style:italic;">        @param paste_expire_date: (Optional) Expiration date for the paste.</span>
<span style="color:#BA2121;font-style:italic;">            Once past this date the paste is deleted automatically. Valid</span>
<span style="color:#BA2121;font-style:italic;">            values are found in the L{Pastebin.paste_expire_date} class member.</span>
<span style="color:#BA2121;font-style:italic;">            If not provided, the paste never expires.</span>

<span style="color:#BA2121;font-style:italic;">        @type  paste_format: str</span>
<span style="color:#BA2121;font-style:italic;">        @param paste_format: (Optional) Programming language of the code being</span>
<span style="color:#BA2121;font-style:italic;">            pasted. This enables syntax highlighting when reading the code in</span>
<span style="color:#BA2121;font-style:italic;">            U{http://pastebin.com}. Default is no syntax highlighting (text is</span>
<span style="color:#BA2121;font-style:italic;">            just text and not source code).</span>

<span style="color:#BA2121;font-style:italic;">        @rtype:  str</span>
<span style="color:#BA2121;font-style:italic;">        @return: Returns the URL to the newly created paste.</span>

<span style="color:#BA2121;font-style:italic;">        @raise PastebinError: The Pastebin API has returned an error message.</span>

<span style="color:#BA2121;font-style:italic;">        @raise IOError: An error occurred when contacting the Pastebin web</span>
<span style="color:#BA2121;font-style:italic;">            application. This is typically caused by network errors.</span>
<span style="color:#BA2121;font-style:italic;">        &quot;&quot;&quot;</span>

        <span style="color:#408080;font-style:italic;"># Code snippet to submit</span>
        argv <span style="color:#666666;">=</span> { <span style="color:#BA2121;">&#039;paste_code&#039;</span> : <span style="color:#008000;">str</span>(paste_code) }

        <span style="color:#408080;font-style:italic;"># Name of the poster</span>
        <span style="color:#008000;font-weight:bold;">if</span> paste_name <span style="color:#AA22FF;font-weight:bold;">is</span> <span style="color:#AA22FF;font-weight:bold;">not</span> <span style="color:#008000;">None</span>:
            argv[<span style="color:#BA2121;">&#039;paste_name&#039;</span>] <span style="color:#666666;">=</span> <span style="color:#008000;">str</span>(paste_name)

        <span style="color:#408080;font-style:italic;"># Is the snippet private?</span>
        <span style="color:#008000;font-weight:bold;">if</span> paste_private <span style="color:#AA22FF;font-weight:bold;">is</span> <span style="color:#AA22FF;font-weight:bold;">not</span> <span style="color:#008000;">None</span>:
            argv[<span style="color:#BA2121;">&#039;paste_private&#039;</span>] <span style="color:#666666;">=</span> <span style="color:#008000;">int</span>(<span style="color:#008000;">bool</span>(<span style="color:#008000;">int</span>(paste_private)))

        <span style="color:#408080;font-style:italic;"># Expiration for the snippet</span>
        <span style="color:#008000;font-weight:bold;">if</span> paste_expire_date <span style="color:#AA22FF;font-weight:bold;">is</span> <span style="color:#AA22FF;font-weight:bold;">not</span> <span style="color:#008000;">None</span>:
            paste_expire_date <span style="color:#666666;">=</span> <span style="color:#008000;">str</span>(paste_expire_date)<span style="color:#666666;">.</span>strip()<span style="color:#666666;">.</span>upper()
            argv[<span style="color:#BA2121;">&#039;paste_expire_date&#039;</span>] <span style="color:#666666;">=</span> paste_expire_date

        <span style="color:#408080;font-style:italic;"># Syntax highlighting</span>
        <span style="color:#008000;font-weight:bold;">if</span> paste_format <span style="color:#AA22FF;font-weight:bold;">is</span> <span style="color:#AA22FF;font-weight:bold;">not</span> <span style="color:#008000;">None</span>:
            paste_format <span style="color:#666666;">=</span> <span style="color:#008000;">str</span>(paste_format)<span style="color:#666666;">.</span>strip()<span style="color:#666666;">.</span>lower()
            argv[<span style="color:#BA2121;">&#039;paste_format&#039;</span>] <span style="color:#666666;">=</span> paste_format

        <span style="color:#408080;font-style:italic;"># Make the request to the Pastebin API</span>
        fd <span style="color:#666666;">=</span> urllib<span style="color:#666666;">.</span>urlopen(cls<span style="color:#666666;">.</span>_api_url, urllib<span style="color:#666666;">.</span>urlencode(argv))
        <span style="color:#008000;font-weight:bold;">try</span>:
            response <span style="color:#666666;">=</span> fd<span style="color:#666666;">.</span>read()
        <span style="color:#008000;font-weight:bold;">finally</span>:
            fd<span style="color:#666666;">.</span>close()
        <span style="color:#008000;font-weight:bold;">del</span> fd

        <span style="color:#408080;font-style:italic;"># Return the new snippet URL on success, raise exception on error</span>
        <span style="color:#008000;font-weight:bold;">if</span> <span style="color:#AA22FF;font-weight:bold;">not</span> response<span style="color:#666666;">.</span>startswith(cls<span style="color:#666666;">.</span>_prefix_url):
            <span style="color:#008000;font-weight:bold;">raise</span> PastebinError(response)
        <span style="color:#008000;font-weight:bold;">return</span> response

<span style="color:#408080;font-style:italic;"># Simple interface.</span>
submit <span style="color:#666666;">=</span> Pastebin<span style="color:#666666;">.</span>submit

<span style="color:#008000;font-weight:bold;">if</span> __name__ <span style="color:#666666;">==</span> <span style="color:#BA2121;">&quot;__main__&quot;</span>:
    <span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">sys</span>
    <span style="color:#008000;font-weight:bold;">import</span> <span style="color:#0000FF;font-weight:bold;">optparse</span>

    <span style="color:#408080;font-style:italic;"># Build the command line parser</span>
    parser <span style="color:#666666;">=</span> optparse<span style="color:#666666;">.</span>OptionParser(usage <span style="color:#666666;">=</span> <span style="color:#BA2121;">&#039;%prog &lt;file&gt; [options]&#039;</span>)
    parser<span style="color:#666666;">.</span>add_option(<span style="color:#BA2121;">&quot;-n&quot;</span>, <span style="color:#BA2121;">&quot;--name&quot;</span>,
                      action<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;store&quot;</span>, <span style="color:#008000;">type</span><span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;string&quot;</span>, metavar<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;NAME&quot;</span>,
                      help<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;author of the code to submit&quot;</span>)
    parser<span style="color:#666666;">.</span>add_option(<span style="color:#BA2121;">&quot;--private&quot;</span>,
                      action<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;store_true&quot;</span>,
                      help<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;the snippet is private&quot;</span>)
    parser<span style="color:#666666;">.</span>add_option(<span style="color:#BA2121;">&quot;--public&quot;</span>,
                      action<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;store_false&quot;</span>, dest<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;private&quot;</span>,
                      help<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;the snippet is public&quot;</span>)
    parser<span style="color:#666666;">.</span>add_option(<span style="color:#BA2121;">&quot;-e&quot;</span>, <span style="color:#BA2121;">&quot;--expire&quot;</span>,
                      action<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;store&quot;</span>, <span style="color:#008000;">type</span><span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;string&quot;</span>, metavar<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;TIME&quot;</span>,
                      help<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;expiration time: N (never), 10M (10 minutes), 1H (1 hour), 1D (1 day), 1M (1 month)&quot;</span>)
    parser<span style="color:#666666;">.</span>add_option(<span style="color:#BA2121;">&quot;-f&quot;</span>, <span style="color:#BA2121;">&quot;--format&quot;</span>, <span style="color:#BA2121;">&quot;--syntax&quot;</span>, <span style="color:#BA2121;">&quot;--highlight&quot;</span>,
                      action<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;store&quot;</span>, <span style="color:#008000;">type</span><span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;string&quot;</span>, metavar<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;FORMAT&quot;</span>, dest<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;format&quot;</span>,
                      help<span style="color:#666666;">=</span><span style="color:#BA2121;">&quot;syntax highlighting, use one of the following: &quot;</span> <span style="color:#666666;">+</span> \
                           <span style="color:#BA2121;">&#039;, &#039;</span><span style="color:#666666;">.</span>join(Pastebin<span style="color:#666666;">.</span>paste_format))

    <span style="color:#408080;font-style:italic;"># Parse the command line and submit each snippet</span>
    options, args <span style="color:#666666;">=</span> parser<span style="color:#666666;">.</span>parse_args(sys<span style="color:#666666;">.</span>argv)
    args <span style="color:#666666;">=</span> args[<span style="color:#666666;">1</span>:]
    <span style="color:#008000;font-weight:bold;">if</span> <span style="color:#AA22FF;font-weight:bold;">not</span> args:
        parser<span style="color:#666666;">.</span>print_help()
    <span style="color:#008000;font-weight:bold;">for</span> filename <span style="color:#AA22FF;font-weight:bold;">in</span> args:
        data <span style="color:#666666;">=</span> <span style="color:#008000;">open</span>(filename, <span style="color:#BA2121;">&#039;rb&#039;</span>)<span style="color:#666666;">.</span>read()
        url <span style="color:#666666;">=</span> Pastebin<span style="color:#666666;">.</span>submit(paste_code <span style="color:#666666;">=</span> data,
                              paste_name <span style="color:#666666;">=</span> options<span style="color:#666666;">.</span>name,
                              paste_private <span style="color:#666666;">=</span> options<span style="color:#666666;">.</span>private,
                              paste_expire_date <span style="color:#666666;">=</span> options<span style="color:#666666;">.</span>expire,
                              paste_format <span style="color:#666666;">=</span> options<span style="color:#666666;">.</span>format)
        <span style="color:#008000;font-weight:bold;">print</span> <span style="color:#BA2121;">&quot;</span><span style="color:#BB6688;font-weight:bold;">%s</span><span style="color:#BA2121;"> --&gt; </span><span style="color:#BB6688;font-weight:bold;">%s</span><span style="color:#BA2121;">&quot;</span> <span style="color:#666666;">%</span> (filename, url)
</pre>
</div>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/tools/'>Tools</a>, <a href='http://breakingcode.wordpress.com/category/web-applications/'>Web applications</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a>, <a href='http://breakingcode.wordpress.com/tag/web/'>web</a>, <a href='http://breakingcode.wordpress.com/tag/webapp/'>webapp</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/362/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=362&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2010/03/06/using-the-pastebin-api-with-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
		<item>
		<title>One-time pad encryption in Python</title>
		<link>http://breakingcode.wordpress.com/2010/02/17/one-time-pad-encryption-in-python/</link>
		<comments>http://breakingcode.wordpress.com/2010/02/17/one-time-pad-encryption-in-python/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 04:58:19 +0000</pubDate>
		<dc:creator>Mario Vilas</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[PRNG]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://breakingcode.wordpress.com/?p=341</guid>
		<description><![CDATA[I cooked up a one-time pad crypto implementation in Python. This speaks volumes, not of my talent as a cryptographer (which is none at all) but the sad state of my social life these days (which happens to be the same amount). Download: http://winappdbg.sourceforge.net/blog/otp.py<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=341&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:120%;">After some crypto sillyness with @<a href="http://twitter.com/feliam">feliam</a>, @<a href="http://twitter.com/julianor">julianor</a> and @<a href="http://twitter.com/ortegaalfredo">ortegaalfredo</a> on Twitter I cooked up a one-time pad crypto implementation in Python. This speaks volumes, not of my talent as a cryptographer (which is none at all) but the sad state of my social life these days (which happens to be the same amount).</span></p>
<p>
<h3>What is one-time pad encryption?</h3>
</p>
<p><span style="font-size:120%;">Feel free to skip this section if you already know the answer. Especially so you don&#8217;t have to suffer my layman&#8217;s explanations of cryptography. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">To put it simply, a <a href="http://en.wikipedia.org/wiki/One-time_pad">one-time pad cipher</a> is one in which the plaintext (i.e. the original message) is encoded using a completely new, random key each time it&#8217;s sent. When properly used (and I hope I have) this system is provably <strong>unbreakable</strong>. That means the ciphertext (that is, the encoded message) can never be decoded without the proper key &#8211; even if the encoding algorithm is very simple, like a bitwise XOR operation on each byte.</span></p>
<p><span style="font-size:120%;">There are a few <strong>caveats</strong>: first of all, the key can <strong>never</strong> be reused. If you do, the system not only <a href="http://en.wikipedia.org/wiki/VENONA_project">ceases to be unbreakable</a> but it&#8217;s also as strong as the encoding algorithm you used. So if you chose XOR encoding and were tempted to use the key twice, you might as well have used a &#8220;magic ring&#8221; from a cereal box. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </span></p>
<p><span style="font-size:120%;">The second caveat: the key must be <strong>truly random</strong>. For this reason need a random generator that can guarantee a certain amount of entropy, for example <em>/dev/random</em> on many Unix systems, to get the one-time pads, instead of the <a href="http://docs.python.org/library/random.html">random</a> module, which is only a <a href="http://en.wikipedia.org/wiki/Pseudorandom_number_generator">PRNG</a> (pseudo-random generator). PRNGs can only produce a <em>seemingly random</em> stream of numbers, all derived from a single value (called the <strong>seed</strong> number) &#8211; so it&#8217;s &#8220;randomness&#8221; is just as good as the seed number from which all others are calculated. (This is a useful property in other contexts, like avoiding to have to store the contents of all malformed files produced by a fuzzer in order to reproduce the crashes, but I digress).</span></p>
<p><span style="font-size:120%;">The third caveat: the key must <strong>never be transmitted</strong> over an <strong>insecure medium</strong>.  Sounds pretty much like a no-brainer, I know, but it&#8217;s worth mentioning that <a href="http://en.wikipedia.org/wiki/Public-key_cryptography">public key crypto</a> doesn&#8217;t suffer from this problem. (Now you know why GPG is so much better than this). Real-life uses of one-time pads include storing the keys in codebooks, which the recipient of the message would carry everywhere. Then the encrypted messages could be safely sent in the clear, say on some radio frequency by a <a href="http://en.wikipedia.org/wiki/Numbers_station">numbers station</a>, until the codebook was used up.</span></p>
<p>
<h3>How does this code work?</h3>
</p>
<p><span style="font-size:120%;">If you weren&#8217;t among the lucky ones who skipped over my ramblings in the previous section you can easily guess by now: we&#8217;ll be using a bitwise XOR encoding of each byte of the plaintext against the corresponding byte of the one-time pad to produce the ciphertext. This is how we generate a one-time pad of any given size:</span></p>
<pre>    $ ./otp.py generate test.key -s 1024
    $ ls -l test.key
    -rw-r--r-- 1 user group 1024 2010-02-17 01:23 test.key
    $</pre>
<p><span style="font-size:120%;">The alternative for the lazy is to pass the name of the file we want to encrypt. A one-time pad of the exact same size will be generated. We&#8217;ll use the -f flag this time to force overwriting the previous file.</span></p>
<pre>    $ ./otp.py generate test.key conscience.txt -f
    $ ls -l test.key conscience.txt
    -rw-r--r-- 1 user group 3880 2010-02-17 01:22 conscience.txt
    -rw-r--r-- 1 user group 3880 2010-02-17 01:24 test.key
    $</pre>
<p><span style="font-size:120%;">And to satisfy all audiences, there&#8217;s also an option for the paranoid: the -p flag uses <em>/dev/random</em> for maximum security instead of the much faster <em>/dev/urandom</em>. It does take considerably longer to generate even small one-time pads, that&#8217;s why this option is disabled by default.</span></p>
<pre>    $ ./otp.py generate test.key conscience.txt -f -p
    $ ls -l test.key conscience.txt
    -rw-r--r-- 1 user group 3880 2010-02-17 01:22 conscience.txt
    -rw-r--r-- 1 user group 3880 2010-02-17 01:38 test.key
    $</pre>
<p><span style="font-size:120%;">Now that we have our one-time pad we can encrypt the message:</span></p>
<pre>    $ ./otp.py encrypt conscience.txt test.key conscience.crypto
    $ ls -l conscience.*
    -rw-r--r-- 1 user group 3880 2010-02-17 01:38 conscience.crypto
    -rw-r--r-- 1 user group 3880 2010-02-17 01:22 conscience.txt
    $</pre>
<p><span style="font-size:120%;">Both files are the same size but have different contents. Since it&#8217;s no longer ASCII trying to <em>cat</em> the file only renders a bunch of garbage in the terminal. Finally, this is how you decrypt it:</span></p>
<pre>    $ ./otp.py decrypt conscience.crypto test.key conscience2.txt
    $ ls -l conscience*
    -rw-r--r-- 1 user group 3880 2010-02-17 01:38 conscience2.txt
    -rw-r--r-- 1 user group 3880 2010-02-17 01:38 conscience.crypto
    -rw-r--r-- 1 user group 3880 2010-02-17 01:22 conscience.txt
    $ cmp conscience.txt conscience2.txt
    $</pre>
<p><span style="font-size:120%;">After decryption, <em>conscience2.txt</em> is identical to the original file and contains the familiar text of <a href="http://www.phrack.org/issues.html?issue=7&amp;id=3&amp;mode=txt">The Conscience of a Hacker</a>.</span></p>
<p><span style="font-size:120%;">As always, the code is available for download below. Enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p>
<h2>Updates</h2>
</p>
<ul>
<li><strong>24-Jul-2011</strong>: Small update to the command like parsing and the documentation.</li>
</ul>
<p>
<h2>Download</h2>
</p>
<p>
<h3><a href="http://winappdbg.sourceforge.net/blog/otp.py">otp.py</a></h3>
</p>
<p>
<h2>Source code</h2>
</p>
<p><span id="more-341"></span></p>
<pre><font face="Lucida,Courier New"><font color="#008000">#!/usr/bin/env python</font>

<font color="#008000"># One-time pad example in Python</font>
<font color="#008000"># Copyright (c) 2009-2011, Mario Vilas</font>
<font color="#008000"># All rights reserved.</font>
<font color="#008000">#</font>
<font color="#008000"># Redistribution and use in source and binary forms, with or without</font>
<font color="#008000"># modification, are permitted provided that the following conditions are met:</font>
<font color="#008000">#</font>
<font color="#008000">#     * Redistributions of source code must retain the above copyright notice,</font>
<font color="#008000">#       this list of conditions and the following disclaimer.</font>
<font color="#008000">#     * Redistributions in binary form must reproduce the above copyright</font>
<font color="#008000">#       notice,this list of conditions and the following disclaimer in the</font>
<font color="#008000">#       documentation and/or other materials provided with the distribution.</font>
<font color="#008000">#     * Neither the name of the copyright holder nor the names of its</font>
<font color="#008000">#       contributors may be used to endorse or promote products derived from</font>
<font color="#008000">#       this software without specific prior written permission.</font>
<font color="#008000">#</font>
<font color="#008000"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"</font>
<font color="#008000"># AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</font>
<font color="#008000"># IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</font>
<font color="#008000"># ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE</font>
<font color="#008000"># LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</font>
<font color="#008000"># CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</font>
<font color="#008000"># SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</font>
<font color="#008000"># INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN</font>
<font color="#008000"># CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)</font>
<font color="#008000"># ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</font>
<font color="#008000"># POSSIBILITY OF SUCH DAMAGE.</font>

<font color="#C00000">from</font> <font color="#000000">__future__</font> <font color="#C00000">import</font> <font color="#000000">with_statement</font>

<font color="#C00000">import</font> <font color="#000000">sys</font>
<font color="#C00000">import</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font>
<font color="#C00000">import</font> <font color="#000000">optparse</font>

<font color="#C00000">try</font><font color="#0000C0">:</font>
    <font color="#C00000">import</font> <font color="#000000">psyco</font>
    <font color="#C00000">from</font> <font color="#000000">psyco</font><font color="#0000C0">.</font><font color="#000000">classes</font> <font color="#C00000">import</font> <font color="#0000C0">*</font>
<font color="#C00000">except</font> <font color="#000000">ImportError</font><font color="#0000C0">:</font>
    <font color="#C00000">pass</font>

<font color="#C00000">class</font> <font color="#000000">OneTimePad</font><font color="#0000C0">(</font><font color="#000000">object</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
    <font color="#004080">"""
This is a simple one-time pad cipher implementation in Python.
For more information on one-time pads:

http://en.wikipedia.org/wiki/One-time_pad

A word of warning: while I made my best effort to avoid programming mistakes
and one time pads are not that hard to implement, I'm not a cryptographer. So
until a proper cryptographer can validate this code, use it at your own risk!

It's best to use /dev/random here, instead of the "random" module. The reason
for that is that the random module doesn't truly provide random numbers, but
pseudo-random numbers that are calculated from a seed number. So the entire
amount of information contained in a stream of pseudo-random numbers fits
into the seed number... using this would be no more secure than just picking
a single number, defeating the whole purpose of using a one-time pad.

It's also not a good idea to limit /dev/random to printable characters only,
so if the user wants printable files we'll have to proceed as usual and later
encode the results.

One-time pad generation only works on Unix systems, but it should be possible
to port it to Windows by deriving this class and reimplementing the check_dev()
and random() methods to use Win32 crypto API. Encryption and decryption should
work in all platforms.
    """</font>

    <font color="#008000"># Buffer size for file access</font>
    <font color="#000000">block_size</font> <font color="#0000C0">=</font> <font color="#0080C0">65536</font>

    <font color="#008000"># Paranoid mode (use /dev/random instead of the faster /dev/urandom)</font>
    <font color="#000000">paranoid</font> <font color="#0000C0">=</font> <font color="#000000">False</font>

    <font color="#008000"># Placeholder for random generator device (open file)</font>
    <font color="#000000">dev</font> <font color="#0000C0">=</font> <font color="#000000">None</font>

    <font color="#008000"># Check for the presence of the required random generator device</font>
    <font color="#C00000">def</font> <font color="#000000">check_dev</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#C00000">if</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">paranoid</font><font color="#0000C0">:</font>
            <font color="#C00000">return</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#004080">'/dev/random'</font><font color="#0000C0">)</font>
        <font color="#C00000">return</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#004080">'/dev/urandom'</font><font color="#0000C0">)</font>

    <font color="#008000"># Generate a string of random bytes</font>
    <font color="#C00000">def</font> <font color="#000000">random</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">,</font> <font color="#000000">size</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">dev</font><font color="#0000C0">:</font>
            <font color="#C00000">if</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">paranoid</font><font color="#0000C0">:</font>
                <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">dev</font> <font color="#0000C0">=</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#004080">'/dev/random'</font><font color="#0000C0">,</font> <font color="#004080">'r'</font><font color="#0000C0">)</font>
            <font color="#C00000">else</font><font color="#0000C0">:</font>
                <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">dev</font> <font color="#0000C0">=</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#004080">'/dev/urandom'</font><font color="#0000C0">,</font> <font color="#004080">'r'</font><font color="#0000C0">)</font>
        <font color="#C00000">return</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">dev</font><font color="#0000C0">.</font><font color="#000000">read</font><font color="#0000C0">(</font><font color="#000000">size</font><font color="#0000C0">)</font>

    <font color="#008000"># Get the size of an open file</font>
    <font color="#C00000">def</font> <font color="#000000">filesize</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">,</font> <font color="#000000">fd</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">fd</font><font color="#0000C0">.</font><font color="#000000">seek</font><font color="#0000C0">(</font><font color="#0080C0">0</font><font color="#0000C0">,</font><font color="#0080C0">2</font><font color="#0000C0">)</font>
        <font color="#000000">n</font> <font color="#0000C0">=</font> <font color="#000000">fd</font><font color="#0000C0">.</font><font color="#000000">tell</font><font color="#0000C0">(</font><font color="#0000C0">)</font>
        <font color="#000000">fd</font><font color="#0000C0">.</font><font color="#000000">seek</font><font color="#0000C0">(</font><font color="#0080C0">0</font><font color="#0000C0">,</font><font color="#0080C0">0</font><font color="#0000C0">)</font>
        <font color="#C00000">return</font> <font color="#000000">n</font>

    <font color="#008000"># Generate a random one-time pad</font>
    <font color="#C00000">def</font> <font color="#000000">generate</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">,</font> <font color="#000000">padfile</font><font color="#0000C0">,</font> <font color="#000000">total_size</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">random</font> <font color="#0000C0">=</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">random</font>
        <font color="#000000">block_size</font> <font color="#0000C0">=</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">block_size</font>
        <font color="#C00000">while</font> <font color="#000000">total_size</font> <font color="#0000C0">&gt;</font> <font color="#0080C0">0</font><font color="#0000C0">:</font>
            <font color="#000000">block</font> <font color="#0000C0">=</font> <font color="#000000">random</font><font color="#0000C0">(</font> <font color="#000000">min</font><font color="#0000C0">(</font><font color="#000000">block_size</font><font color="#0000C0">,</font> <font color="#000000">total_size</font><font color="#0000C0">)</font> <font color="#0000C0">)</font>
            <font color="#000000">padfile</font><font color="#0000C0">.</font><font color="#000000">write</font><font color="#0000C0">(</font><font color="#000000">block</font><font color="#0000C0">)</font>
            <font color="#000000">total_size</font> <font color="#0000C0">=</font> <font color="#000000">total_size</font> <font color="#0000C0">-</font> <font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">block</font><font color="#0000C0">)</font>

    <font color="#008000"># Encrypt or decrypt a file using a one-time pad</font>
    <font color="#C00000">def</font> <font color="#000000">cipher</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">,</font> <font color="#000000">infile</font><font color="#0000C0">,</font> <font color="#000000">outfile</font><font color="#0000C0">,</font> <font color="#000000">padfile</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">block_size</font> <font color="#0000C0">=</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">block_size</font>
        <font color="#C00000">while</font> <font color="#0080C0">1</font><font color="#0000C0">:</font>
            <font color="#000000">data</font> <font color="#0000C0">=</font> <font color="#000000">infile</font><font color="#0000C0">.</font><font color="#000000">read</font><font color="#0000C0">(</font><font color="#000000">block_size</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">data</font><font color="#0000C0">:</font>
                <font color="#C00000">break</font>
            <font color="#000000">pad</font> <font color="#0000C0">=</font> <font color="#000000">padfile</font><font color="#0000C0">.</font><font color="#000000">read</font><font color="#0000C0">(</font><font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">data</font><font color="#0000C0">)</font><font color="#0000C0">)</font>
            <font color="#000000">encoded</font> <font color="#0000C0">=</font> <font color="#004080">''</font><font color="#0000C0">.</font><font color="#000000">join</font><font color="#0000C0">(</font><font color="#0000C0">[</font> <font color="#000000">chr</font><font color="#0000C0">(</font><font color="#000000">ord</font><font color="#0000C0">(</font><font color="#000000">a</font><font color="#0000C0">)</font> <font color="#0000C0">^</font> <font color="#000000">ord</font><font color="#0000C0">(</font><font color="#000000">b</font><font color="#0000C0">)</font><font color="#0000C0">)</font> <font color="#C00000">for</font> <font color="#000000">a</font><font color="#0000C0">,</font> <font color="#000000">b</font> <font color="#C00000">in</font> <font color="#000000">zip</font><font color="#0000C0">(</font><font color="#000000">data</font><font color="#0000C0">,</font> <font color="#000000">pad</font><font color="#0000C0">)</font> <font color="#0000C0">]</font><font color="#0000C0">)</font>
            <font color="#000000">outfile</font><font color="#0000C0">.</font><font color="#000000">write</font><font color="#0000C0">(</font><font color="#000000">encoded</font><font color="#0000C0">)</font>

    <font color="#008000"># Main function (most of it is command line parsing stuff)</font>
    <font color="#C00000">def</font> <font color="#000000">run</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">)</font><font color="#0000C0">:</font>

        <font color="#008000"># Define a command line parser</font>
        <font color="#000000">banner</font> <font color="#0000C0">=</font> <font color="#0000C0">(</font>
            <font color="#004080">"One-time pad example in Python\n"</font>
            <font color="#004080">"by Mario Vilas (mvilas at gmail dot com)\n"</font>
            <font color="#004080">"http://breakingcode.wordpress.com/"</font>
                        <font color="#004080">"2010/02/17/one-time-pad-encryption-in-python\n"</font>
        <font color="#0000C0">)</font>
        <font color="#000000">usage</font> <font color="#0000C0">=</font> <font color="#0000C0">(</font>
            <font color="#004080">"\n\n"</font>
            <font color="#004080">"Create a one-time pad:\n"</font>
            <font color="#004080">"    ./%prog generate -k example.key -s size\n"</font>
            <font color="#004080">"    ./%prog generate -k example.key -t example.txt\n"</font>
            <font color="#004080">"Encrypt a file:\n"</font>
            <font color="#004080">"    ./%prog encrypt -t example.txt -k example.key -c example.cipher\n"</font>
            <font color="#004080">"Decrypt a file:\n"</font>
            <font color="#004080">"    ./%prog decrypt -c example.cipher -k example.key -t example.txt"</font>
        <font color="#0000C0">)</font>
        <font color="#000000">formatter</font> <font color="#0000C0">=</font> <font color="#000000">MyHelpFormatter</font><font color="#0000C0">(</font><font color="#000000">banner</font><font color="#0000C0">,</font> <font color="#000000">max_help_position</font><font color="#0000C0">=</font><font color="#0080C0">26</font><font color="#0000C0">)</font>
        <font color="#000000">parser</font> <font color="#0000C0">=</font> <font color="#000000">optparse</font><font color="#0000C0">.</font><font color="#000000">OptionParser</font><font color="#0000C0">(</font><font color="#000000">usage</font><font color="#0000C0">=</font><font color="#000000">usage</font><font color="#0000C0">,</font> <font color="#000000">formatter</font><font color="#0000C0">=</font><font color="#000000">formatter</font><font color="#0000C0">)</font>
        <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">add_option</font><font color="#0000C0">(</font><font color="#004080">"-t"</font><font color="#0000C0">,</font> <font color="#004080">"--text"</font><font color="#0000C0">,</font> <font color="#000000">action</font><font color="#0000C0">=</font><font color="#004080">"store"</font><font color="#0000C0">,</font> <font color="#000000">type</font><font color="#0000C0">=</font><font color="#004080">"string"</font><font color="#0000C0">,</font>
                          <font color="#000000">metavar</font><font color="#0000C0">=</font><font color="#004080">"FILE"</font><font color="#0000C0">,</font> <font color="#000000">help</font><font color="#0000C0">=</font><font color="#004080">"plaintext filename"</font><font color="#0000C0">)</font>
        <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">add_option</font><font color="#0000C0">(</font><font color="#004080">"-c"</font><font color="#0000C0">,</font> <font color="#004080">"--cipher"</font><font color="#0000C0">,</font> <font color="#000000">action</font><font color="#0000C0">=</font><font color="#004080">"store"</font><font color="#0000C0">,</font> <font color="#000000">type</font><font color="#0000C0">=</font><font color="#004080">"string"</font><font color="#0000C0">,</font>
                          <font color="#000000">metavar</font><font color="#0000C0">=</font><font color="#004080">"FILE"</font><font color="#0000C0">,</font> <font color="#000000">help</font><font color="#0000C0">=</font><font color="#004080">"ciphertext filename"</font><font color="#0000C0">)</font>
        <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">add_option</font><font color="#0000C0">(</font><font color="#004080">"-k"</font><font color="#0000C0">,</font> <font color="#004080">"--key"</font><font color="#0000C0">,</font> <font color="#000000">action</font><font color="#0000C0">=</font><font color="#004080">"store"</font><font color="#0000C0">,</font> <font color="#000000">type</font><font color="#0000C0">=</font><font color="#004080">"string"</font><font color="#0000C0">,</font>
                          <font color="#000000">metavar</font><font color="#0000C0">=</font><font color="#004080">"FILE"</font><font color="#0000C0">,</font> <font color="#000000">help</font><font color="#0000C0">=</font><font color="#004080">"one-time pad filename"</font><font color="#0000C0">)</font>
        <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">add_option</font><font color="#0000C0">(</font><font color="#004080">"-s"</font><font color="#0000C0">,</font> <font color="#004080">"--size"</font><font color="#0000C0">,</font> <font color="#000000">action</font><font color="#0000C0">=</font><font color="#004080">"store"</font><font color="#0000C0">,</font> <font color="#000000">type</font><font color="#0000C0">=</font><font color="#004080">"int"</font><font color="#0000C0">,</font>
                          <font color="#000000">metavar</font><font color="#0000C0">=</font><font color="#004080">"NUM"</font><font color="#0000C0">,</font> <font color="#000000">help</font><font color="#0000C0">=</font><font color="#004080">"one-time pad size in bytes"</font><font color="#0000C0">)</font>
        <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">add_option</font><font color="#0000C0">(</font><font color="#004080">"-f"</font><font color="#0000C0">,</font> <font color="#004080">"--force"</font><font color="#0000C0">,</font> <font color="#000000">action</font><font color="#0000C0">=</font><font color="#004080">"store_true"</font><font color="#0000C0">,</font> <font color="#000000">default</font><font color="#0000C0">=</font><font color="#000000">False</font><font color="#0000C0">,</font>
                          <font color="#000000">help</font><font color="#0000C0">=</font><font color="#004080">"force overwriting of any output files"</font><font color="#0000C0">)</font>
        <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">add_option</font><font color="#0000C0">(</font><font color="#004080">"-p"</font><font color="#0000C0">,</font> <font color="#004080">"--paranoid"</font><font color="#0000C0">,</font> <font color="#000000">action</font><font color="#0000C0">=</font><font color="#004080">"store_true"</font><font color="#0000C0">,</font> <font color="#000000">default</font><font color="#0000C0">=</font><font color="#000000">False</font><font color="#0000C0">,</font>
                          <font color="#000000">help</font><font color="#0000C0">=</font><font color="#004080">"use /dev/random instead of /dev/urandom (slower!)"</font><font color="#0000C0">)</font>

        <font color="#008000"># Parse the command line</font>
        <font color="#000000">args</font> <font color="#0000C0">=</font> <font color="#000000">list</font><font color="#0000C0">(</font><font color="#000000">sys</font><font color="#0000C0">.</font><font color="#000000">argv</font><font color="#0000C0">)</font>
        <font color="#C00000">if</font> <font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">args</font><font color="#0000C0">)</font> <font color="#0000C0">==</font> <font color="#0080C0">1</font><font color="#0000C0">:</font>
            <font color="#000000">args</font> <font color="#0000C0">=</font> <font color="#000000">args</font> <font color="#0000C0">+</font> <font color="#0000C0">[</font> <font color="#004080">'--help'</font> <font color="#0000C0">]</font>
        <font color="#000000">options</font><font color="#0000C0">,</font> <font color="#000000">args</font> <font color="#0000C0">=</font> <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">parse_args</font><font color="#0000C0">(</font><font color="#000000">args</font><font color="#0000C0">)</font>

        <font color="#008000"># Set paranoid mode if requested</font>
        <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">paranoid</font> <font color="#0000C0">=</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">paranoid</font>

        <font color="#008000"># Check command is present</font>
        <font color="#C00000">if</font> <font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">args</font><font color="#0000C0">)</font> <font color="#0000C0">&lt;</font> <font color="#0080C0">2</font><font color="#0000C0">:</font>
            <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"missing command"</font><font color="#0000C0">)</font>
        <font color="#000000">command</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#0080C0">1</font><font color="#0000C0">]</font><font color="#0000C0">.</font><font color="#000000">strip</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#0000C0">.</font><font color="#000000">lower</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#0000C0">[</font><font color="#0080C0">0</font><font color="#0000C0">:</font><font color="#0080C0">1</font><font color="#0000C0">]</font>
        <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">command</font><font color="#0000C0">:</font>
            <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"missing command"</font><font color="#0000C0">)</font>

        <font color="#008000"># If more parameters are present, try to guess what they are</font>
        <font color="#C00000">if</font> <font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">args</font><font color="#0000C0">)</font> <font color="#0000C0">&gt;</font> <font color="#0080C0">2</font><font color="#0000C0">:</font>
            <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#0080C0">2</font>
            <font color="#C00000">try</font><font color="#0000C0">:</font>
                <font color="#C00000">if</font> <font color="#000000">command</font> <font color="#0000C0">==</font> <font color="#004080">'g'</font><font color="#0000C0">:</font>
                    <font color="#008000"># g key size</font>
                    <font color="#008000"># g key text</font>
                    <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                    <font color="#C00000">try</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">size</font> <font color="#0000C0">=</font> <font color="#000000">int</font><font color="#0000C0">(</font><font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font><font color="#0000C0">)</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                    <font color="#C00000">except</font> <font color="#000000">ValueError</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                <font color="#C00000">elif</font> <font color="#000000">command</font> <font color="#0000C0">==</font> <font color="#004080">'e'</font><font color="#0000C0">:</font>
                    <font color="#008000"># e text key cipher</font>
                    <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                    <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                    <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                <font color="#C00000">elif</font> <font color="#000000">command</font> <font color="#0000C0">==</font> <font color="#004080">'d'</font><font color="#0000C0">:</font>
                    <font color="#008000"># d cipher key text</font>
                    <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                    <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                    <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">:</font>
                        <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font> <font color="#0000C0">=</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#000000">p</font><font color="#0000C0">]</font>
                        <font color="#000000">p</font> <font color="#0000C0">=</font> <font color="#000000">p</font> <font color="#0000C0">+</font> <font color="#0080C0">1</font>
                <font color="#C00000">else</font><font color="#0000C0">:</font>
                    <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"too many arguments"</font><font color="#0000C0">)</font>
            <font color="#C00000">except</font> <font color="#000000">IndexError</font><font color="#0000C0">:</font>
                <font color="#C00000">pass</font>
            <font color="#C00000">if</font> <font color="#000000">p</font> <font color="#0000C0">&lt;</font> <font color="#000000">len</font><font color="#0000C0">(</font><font color="#000000">args</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"too many arguments"</font><font color="#0000C0">)</font>

        <font color="#008000"># The one-time pad filename is always required</font>
        <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">:</font>
            <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"missing one-time pad filename"</font><font color="#0000C0">)</font>

        <font color="#008000"># Plaintext and ciphertext files are required for "decrypt" and "encrypt"</font>
        <font color="#C00000">if</font> <font color="#000000">command</font> <font color="#C00000">in</font> <font color="#0000C0">(</font><font color="#004080">'d'</font><font color="#0000C0">,</font> <font color="#004080">'e'</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"missing plaintext filename"</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"missing ciphertext filename"</font><font color="#0000C0">)</font>

        <font color="#008000"># Generate a one-time pad file</font>
        <font color="#C00000">if</font> <font color="#000000">command</font> <font color="#0000C0">==</font> <font color="#004080">'g'</font><font color="#0000C0">:</font>
            <font color="#C00000">if</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"unused argument: ciphertext filename"</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">check_dev</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"random generator not available"</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">force</font> <font color="#C00000">and</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"file already exists: %s"</font> <font color="#0000C0">%</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">:</font>
                <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                    <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"can't find file: %s"</font> <font color="#0000C0">%</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">)</font>
                <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">,</font> <font color="#004080">'r'</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">textfile</font><font color="#0000C0">:</font>
                    <font color="#000000">size</font> <font color="#0000C0">=</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">filesize</font><font color="#0000C0">(</font><font color="#000000">textfile</font><font color="#0000C0">)</font>
            <font color="#C00000">elif</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">size</font><font color="#0000C0">:</font>
                <font color="#000000">size</font> <font color="#0000C0">=</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">size</font>
            <font color="#C00000">else</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"either plaintext file or one-time pad size is required"</font><font color="#0000C0">)</font>
            <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">,</font> <font color="#004080">'w'</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">padfile</font><font color="#0000C0">:</font>
                <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">generate</font><font color="#0000C0">(</font><font color="#000000">padfile</font><font color="#0000C0">,</font> <font color="#000000">size</font><font color="#0000C0">)</font>

        <font color="#008000"># Encrypt a file using a one-time pad</font>
        <font color="#C00000">elif</font> <font color="#000000">command</font> <font color="#0000C0">==</font> <font color="#004080">'e'</font><font color="#0000C0">:</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"can't find file: %s"</font> <font color="#0000C0">%</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"can't find file: %s"</font> <font color="#0000C0">%</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">force</font> <font color="#C00000">and</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"file already exists: %s"</font> <font color="#0000C0">%</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">)</font>
            <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">,</font> <font color="#004080">'r'</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">padfile</font><font color="#0000C0">:</font>
                <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">,</font> <font color="#004080">'r'</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">textfile</font><font color="#0000C0">:</font>
                    <font color="#C00000">if</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">filesize</font><font color="#0000C0">(</font><font color="#000000">textfile</font><font color="#0000C0">)</font> <font color="#0000C0">&gt;</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">filesize</font><font color="#0000C0">(</font><font color="#000000">padfile</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                        <font color="#C00000">raise</font> <font color="#000000">RuntimeError</font><font color="#0000C0">(</font><font color="#004080">"Not enough bytes in the one-time pad for this file!"</font><font color="#0000C0">)</font>
                    <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">,</font> <font color="#004080">'w'</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">cipherfile</font><font color="#0000C0">:</font>
                        <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">(</font><font color="#000000">textfile</font><font color="#0000C0">,</font> <font color="#000000">cipherfile</font><font color="#0000C0">,</font> <font color="#000000">padfile</font><font color="#0000C0">)</font>

        <font color="#008000"># Decrypt a file using a one-time pad</font>
        <font color="#C00000">elif</font> <font color="#000000">command</font> <font color="#0000C0">==</font> <font color="#004080">'d'</font><font color="#0000C0">:</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"can't find file: %s"</font> <font color="#0000C0">%</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"can't find file: %s"</font> <font color="#0000C0">%</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">)</font>
            <font color="#C00000">if</font> <font color="#C00000">not</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">force</font> <font color="#C00000">and</font> <font color="#000000">os</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">exists</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"file already exists: %s"</font> <font color="#0000C0">%</font> <font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">)</font>
            <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">key</font><font color="#0000C0">,</font> <font color="#004080">'r'</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">padfile</font><font color="#0000C0">:</font>
                <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">,</font> <font color="#004080">'r'</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">cipherfile</font><font color="#0000C0">:</font>
                    <font color="#C00000">if</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">filesize</font><font color="#0000C0">(</font><font color="#000000">cipherfile</font><font color="#0000C0">)</font> <font color="#0000C0">&gt;</font> <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">filesize</font><font color="#0000C0">(</font><font color="#000000">padfile</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
                        <font color="#C00000">raise</font> <font color="#000000">RuntimeError</font><font color="#0000C0">(</font><font color="#004080">"Not enough bytes in the one-time pad for this file!"</font><font color="#0000C0">)</font>
                    <font color="#C00000">with</font> <font color="#000000">open</font><font color="#0000C0">(</font><font color="#000000">options</font><font color="#0000C0">.</font><font color="#000000">text</font><font color="#0000C0">,</font> <font color="#004080">'w'</font><font color="#0000C0">)</font> <font color="#C00000">as</font> <font color="#000000">textfile</font><font color="#0000C0">:</font>
                        <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">cipher</font><font color="#0000C0">(</font><font color="#000000">cipherfile</font><font color="#0000C0">,</font> <font color="#000000">textfile</font><font color="#0000C0">,</font> <font color="#000000">padfile</font><font color="#0000C0">)</font>

        <font color="#008000"># Unknown command</font>
        <font color="#C00000">else</font><font color="#0000C0">:</font>
            <font color="#000000">parser</font><font color="#0000C0">.</font><font color="#000000">error</font><font color="#0000C0">(</font><font color="#004080">"unknown command: %s"</font> <font color="#0000C0">%</font> <font color="#000000">args</font><font color="#0000C0">[</font><font color="#0080C0">1</font><font color="#0000C0">]</font><font color="#0000C0">)</font>

<font color="#008000"># Just a small tweak to optparse to be able to print a banner.</font>
<font color="#008000"># (Why is there an epilog but no prolog in optparse?)</font>
<font color="#C00000">class</font> <font color="#000000">MyHelpFormatter</font><font color="#0000C0">(</font><font color="#000000">optparse</font><font color="#0000C0">.</font><font color="#000000">IndentedHelpFormatter</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
    <font color="#C00000">def</font> <font color="#000000">__init__</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">,</font> <font color="#000000">banner</font><font color="#0000C0">,</font> <font color="#0000C0">*</font><font color="#000000">argv</font><font color="#0000C0">,</font> <font color="#0000C0">**</font><font color="#000000">argd</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">banner</font> <font color="#0000C0">=</font> <font color="#000000">banner</font>
        <font color="#000000">optparse</font><font color="#0000C0">.</font><font color="#000000">IndentedHelpFormatter</font><font color="#0000C0">.</font><font color="#000000">__init__</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">,</font> <font color="#0000C0">*</font><font color="#000000">argv</font><font color="#0000C0">,</font> <font color="#0000C0">**</font><font color="#000000">argd</font><font color="#0000C0">)</font>
    <font color="#C00000">def</font> <font color="#000000">format_usage</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">,</font> <font color="#000000">usage</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
        <font color="#000000">msg</font> <font color="#0000C0">=</font> <font color="#000000">optparse</font><font color="#0000C0">.</font><font color="#000000">IndentedHelpFormatter</font><font color="#0000C0">.</font><font color="#000000">format_usage</font><font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">,</font> <font color="#000000">usage</font><font color="#0000C0">)</font>
        <font color="#C00000">return</font> <font color="#004080">'%s\n%s'</font> <font color="#0000C0">%</font> <font color="#0000C0">(</font><font color="#000000">self</font><font color="#0000C0">.</font><font color="#000000">banner</font><font color="#0000C0">,</font> <font color="#000000">msg</font><font color="#0000C0">)</font>

<font color="#008000"># Run from the command line, try to use Psyco for acceleration</font>
<font color="#C00000">if</font> <font color="#000000">__name__</font> <font color="#0000C0">==</font> <font color="#004080">"__main__"</font><font color="#0000C0">:</font>
    <font color="#C00000">try</font><font color="#0000C0">:</font>
        <font color="#000000">psyco</font><font color="#0000C0">.</font><font color="#000000">full</font><font color="#0000C0">(</font><font color="#0000C0">)</font>
    <font color="#C00000">except</font> <font color="#000000">NameError</font><font color="#0000C0">:</font>
        <font color="#C00000">pass</font>
    <font color="#000000">OneTimePad</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#0000C0">.</font><font color="#000000">run</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<br />Filed under: <a href='http://breakingcode.wordpress.com/category/cryptography/'>Cryptography</a> Tagged: <a href='http://breakingcode.wordpress.com/tag/crypto/'>crypto</a>, <a href='http://breakingcode.wordpress.com/tag/linkedin/'>LinkedIn</a>, <a href='http://breakingcode.wordpress.com/tag/linux/'>linux</a>, <a href='http://breakingcode.wordpress.com/tag/open-source/'>open source</a>, <a href='http://breakingcode.wordpress.com/tag/prng/'>PRNG</a>, <a href='http://breakingcode.wordpress.com/tag/python/'>python</a>, <a href='http://breakingcode.wordpress.com/tag/tool/'>tool</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/breakingcode.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/breakingcode.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/breakingcode.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/breakingcode.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/breakingcode.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/breakingcode.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/breakingcode.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/breakingcode.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/breakingcode.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/breakingcode.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/breakingcode.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/breakingcode.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/breakingcode.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/breakingcode.wordpress.com/341/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=breakingcode.wordpress.com&amp;blog=5671286&amp;post=341&amp;subd=breakingcode&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://breakingcode.wordpress.com/2010/02/17/one-time-pad-encryption-in-python/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">mvilas</media:title>
		</media:content>
	</item>
	</channel>
</rss>
