<?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/"
	>

<channel>
	<title>Snipd</title>
	<atom:link href="http://snipd.net/feed" rel="self" type="application/rss+xml" />
	<link>http://snipd.net</link>
	<description>Handy snippets of code</description>
	<lastBuildDate>Sat, 12 May 2012 11:40:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>(Python) ARC4</title>
		<link>http://snipd.net/python-arc4</link>
		<comments>http://snipd.net/python-arc4#comments</comments>
		<pubDate>Thu, 10 May 2012 12:10:04 +0000</pubDate>
		<dc:creator>SnipBot</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[arc4]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Key]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rc4]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10728</guid>
		<description><![CDATA[This is a pure Python implementation of raw ARC4, sans any improvements. For instance, it could take a nonce, use multiple state spaces (parallelizable), automatically discard the first 4K of the state space(s), use a more complex transformation than a simple swap, limit the # of bytes encrypted per nonce, etc.. The size of the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a pure Python implementation of raw ARC4, sans any improvements. For instance, it could take a nonce, use multiple state spaces (parallelizable), automatically discard the first 4K of the state space(s), use a more complex transformation than a simple swap, limit the # of bytes encrypted per nonce, etc.. The size of the state space is a parameter&#8211;the size of the key must not exceed the size of the state space.</p>
<p><span id="more-10728"></span></p>
<div class='sniplrcode'>
<ol class="python" style="font-family:monospace;">
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> prepare_state<span style="color: black;">&#40;</span>key, state_size=<span style="color: #ff4500;">256</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; key_size &nbsp; &nbsp;= <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; state &nbsp; &nbsp; &nbsp; = <span style="color: black;">&#91;</span>i <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>state_size<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; j &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #ff4500;">0</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>state_size<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; j = <span style="color: black;">&#40;</span>j + state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> + key<span style="color: black;">&#91;</span>i <span style="color: #66cc66;">%</span> key_size<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> state_size</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> ^= state<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; state<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span> ^= state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> ^= state<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> state</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> pseudorandom_generator<span style="color: black;">&#40;</span>state<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; size &nbsp; &nbsp;= <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>state<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; i &nbsp; &nbsp; &nbsp; = <span style="color: #ff4500;">0</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; j &nbsp; &nbsp; &nbsp; = <span style="color: #ff4500;">0</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; i = <span style="color: black;">&#40;</span>i + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> size</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; j = <span style="color: black;">&#40;</span>j + state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> size</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> ^= state<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; state<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span> ^= state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> ^= state<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span> state<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>state<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> + state<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> size<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> ARC4<span style="color: black;">&#40;</span>key, text<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; state &nbsp; &nbsp; &nbsp; = prepare_state<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; keystream &nbsp; = pseudorandom_generator<span style="color: black;">&#40;</span>state<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> key_byte, text_byte <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">zip</span><span style="color: black;">&#40;</span>keystream, text<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span> key_byte ^ text_byte</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>__name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">pprint</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">pprint</span> <span style="color: #ff7700;font-weight:bold;">as</span> pp</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; encryption &nbsp;= ARC4<span style="color: black;">&#40;</span>b<span style="color: #483d8b;">&#8216;Key&#8217;</span>, b<span style="color: #483d8b;">&#8216;Plaintext&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; ciphertext &nbsp;= <span style="color: #dc143c;">bytes</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>next<span style="color: black;">&#40;</span>encryption<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>b<span style="color: #483d8b;">&#8216;Plaintext&#8217;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; pp<span style="color: black;">&#40;</span>ciphertext<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; decryption &nbsp;= ARC4<span style="color: black;">&#40;</span>b<span style="color: #483d8b;">&#8216;Key&#8217;</span>, ciphertext<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; plaintext &nbsp; = <span style="color: #dc143c;">bytes</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>next<span style="color: black;">&#40;</span>decryption<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>ciphertext<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; pp<span style="color: black;">&#40;</span>plaintext<span style="color: black;">&#41;</span></div>
</li>
</ol>
</div>
<ul class='snippet-meta'>
<li><strong><a href='http://snipplr.com/view/64835/arc4'>ARC4</a></strong></li>
<li><small>Posted by <a href='http://snipplr.com/users/weilawei'>weilawei</a> on May 10th, 2012</small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/python-arc4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Python) All-Or-Nothing Transform</title>
		<link>http://snipd.net/python-all-or-nothing-transform</link>
		<comments>http://snipd.net/python-all-or-nothing-transform#comments</comments>
		<pubDate>Tue, 08 May 2012 19:20:02 +0000</pubDate>
		<dc:creator>SnipBot</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[chunk]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[hmac]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[transform]]></category>
		<category><![CDATA[xor]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10725</guid>
		<description><![CDATA[Performs an all-or-nothing transform on a stream of chunks. The data can only be decrypted if every block is present to generate an HMAC for. The list of HMACs is then XOR&#8217;d against the final block from the transform, yielding the decryption key for the blocks. Currently uses the HMAC key for encryption as well [...]]]></description>
			<content:encoded><![CDATA[<p>Performs an all-or-nothing transform on a stream of chunks. The data can only be decrypted if every block is present to generate an HMAC for. The list of HMACs is then XOR&#8217;d against the final block from the transform, yielding the decryption key for the blocks.</p>
<p>Currently uses the HMAC key for encryption as well (TODO: change this). Reports a hash of the encrypted chunk for storage/retrieval without needing to calculate HMAC until decryption.</p>
<p>Needs a lot of cleanup and some fixes. Makes a lot of assumptions, for instance, that current_block, total_blocks, and data_size only occupy 1 byte apiece. Currently doesn&#8217;t strip padding after decoding, and doesn&#8217;t convert original integers for current_block, total_blocks, and data_size back from bytes.</p>
<p><span id="more-10725"></span></p>
<div class='sniplrcode'>
<ol class="python" style="font-family:monospace;">
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">from</span> stream <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">chunk</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">hmac</span> <span style="color: #ff7700;font-weight:bold;">import</span> HMAC, pad_key</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">from</span> Crypto.<span style="color: black;">Random</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> bytearray_to_bytes<span style="color: black;">&#40;</span>a_bytearray<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">bytes</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>a_byte <span style="color: #ff7700;font-weight:bold;">for</span> a_byte <span style="color: #ff7700;font-weight:bold;">in</span> a_bytearray<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> encode<span style="color: black;">&#40;</span>a_hash, hmac_key, a_cipher, data, block_size, block_key=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> block_key:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; block_key = <span style="color: #dc143c;">bytes</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">randint</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>a_hash.<span style="color: black;">digest_size</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; hmac_key &nbsp; &nbsp;= pad_key<span style="color: black;">&#40;</span>a_hash, hmac_key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; block_key &nbsp; = pad_key<span style="color: black;">&#40;</span>a_hash, block_key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; encrypter &nbsp; = a_cipher.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>block_key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; final_block = <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span>block_key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> a_block <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">chunk</span><span style="color: black;">&#40;</span>data, block_size<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; a_hasher &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= a_hash.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; a_block &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span>a_block<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>:<span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> + a_block<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; encrypted_block &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span>encrypter.<span style="color: black;">encrypt</span><span style="color: black;">&#40;</span>bytearray_to_bytes<span style="color: black;">&#40;</span>a_block<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; encrypted_block_hmac &nbsp; &nbsp;= HMAC<span style="color: black;">&#40;</span>a_hash, hmac_key, encrypted_block<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; final_block &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> ^ x<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">zip</span><span style="color: black;">&#40;</span>final_block, encrypted_block_hmac<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; a_hasher.<span style="color: black;">update</span><span style="color: black;">&#40;</span>bytearray_to_bytes<span style="color: black;">&#40;</span>encrypted_block<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#91;</span>encrypted_block, a_hasher.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; a_hasher = a_hash.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; a_hasher.<span style="color: black;">update</span><span style="color: black;">&#40;</span>bytearray_to_bytes<span style="color: black;">&#40;</span>final_block<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#91;</span>final_block, a_hasher.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> decode<span style="color: black;">&#40;</span>a_hash, hmac_key, a_cipher, blocks, block_size<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; hmac_key &nbsp; &nbsp;= pad_key<span style="color: black;">&#40;</span>a_hash, hmac_key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; block_key &nbsp; = blocks<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; blocks &nbsp; &nbsp; &nbsp;= blocks<span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> a_block <span style="color: #ff7700;font-weight:bold;">in</span> blocks:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; block_key = <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> ^ x<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">zip</span><span style="color: black;">&#40;</span>block_key, HMAC<span style="color: black;">&#40;</span>a_hash, hmac_key, a_block<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; a_decrypter = a_cipher.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>bytearray_to_bytes<span style="color: black;">&#40;</span>block_key<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> a_block <span style="color: #ff7700;font-weight:bold;">in</span> blocks:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; a_decrypted_block &nbsp; = <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span>a_decrypter.<span style="color: black;">decrypt</span><span style="color: black;">&#40;</span>bytearray_to_bytes<span style="color: black;">&#40;</span>a_block<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; plaintext &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = a_decrypted_block<span style="color: black;">&#91;</span>-block_size:<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; data_size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = a_decrypted_block<span style="color: black;">&#91;</span>-block_size-<span style="color: #ff4500;">1</span>:-block_size<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; total_blocks &nbsp; &nbsp; &nbsp; &nbsp;= a_decrypted_block<span style="color: black;">&#91;</span>-block_size-<span style="color: #ff4500;">2</span>:-block_size-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; current_block &nbsp; &nbsp; &nbsp; = a_decrypted_block<span style="color: black;">&#91;</span>-block_size-<span style="color: #ff4500;">3</span>:-block_size-<span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#91;</span>current_block, total_blocks, data_size, plaintext<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>__name__ == <span style="color: #483d8b;">&#8216;__main__&#8217;</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">from</span> Crypto.<span style="color: black;">Hash</span> <span style="color: #ff7700;font-weight:bold;">import</span> RIPEMD</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">from</span> Crypto.<span style="color: black;">Cipher</span> <span style="color: #ff7700;font-weight:bold;">import</span> ARC4</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">pprint</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; pp = <span style="color: #dc143c;">pprint</span>.<span style="color: #dc143c;">pprint</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; data = b<span style="color: #483d8b;">&quot;all your base are belong to us&quot;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; pp<span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;<span style="color: #000099; font-weight: bold;">\n</span>&#8216;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; blocks = <span style="color: black;">&#91;</span>a_block <span style="color: #ff7700;font-weight:bold;">for</span> a_block <span style="color: #ff7700;font-weight:bold;">in</span> encode<span style="color: black;">&#40;</span>RIPEMD, b<span style="color: #483d8b;">&#8216;an_hmac_key&#8217;</span>, ARC4, data, <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; pp<span style="color: black;">&#40;</span>blocks<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;<span style="color: #000099; font-weight: bold;">\n</span>&#8216;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; hashes &nbsp; &nbsp; &nbsp;= <span style="color: black;">&#91;</span>a_block<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> a_block <span style="color: #ff7700;font-weight:bold;">in</span> blocks<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; blocks &nbsp; &nbsp; &nbsp;= <span style="color: black;">&#91;</span>a_block<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> a_block <span style="color: #ff7700;font-weight:bold;">in</span> blocks<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; pp<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>a_block <span style="color: #ff7700;font-weight:bold;">for</span> a_block <span style="color: #ff7700;font-weight:bold;">in</span> decode<span style="color: black;">&#40;</span>RIPEMD, b<span style="color: #483d8b;">&#8216;an_hmac_key&#8217;</span>, ARC4, blocks, <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
</ol>
</div>
<ul class='snippet-meta'>
<li><strong><a href='http://snipplr.com/view/64825/allornothing-transform'>All-Or-Nothing Transform</a></strong></li>
<li><small>Posted by <a href='http://snipplr.com/users/weilawei'>weilawei</a> on May 9th, 2012</small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/python-all-or-nothing-transform/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Python) Chunk Data for Streaming</title>
		<link>http://snipd.net/python-chunk-data-for-streaming</link>
		<comments>http://snipd.net/python-chunk-data-for-streaming#comments</comments>
		<pubDate>Tue, 08 May 2012 19:10:02 +0000</pubDate>
		<dc:creator>SnipBot</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[chunk]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[streaming]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10724</guid>
		<description><![CDATA[Chunks data into block_size blocks for streaming, adds null padding. import math &#160; is_debug = False &#160; def chunk&#40;data, block_size, padding=b&#8216;\x00&#8242;&#41;: &#160; &#160; data_size &#160; &#160; &#160; = len&#40;data&#41; &#160; &#160; padding_size &#160; &#160;= block_size &#8211; &#40;data_size % block_size&#41; if &#40;data_size &#62; block_size&#41; else &#40;block_size &#8211; data_size&#41; &#160; &#160; is_padded &#160; &#160; &#160; = &#40;padding_size [...]]]></description>
			<content:encoded><![CDATA[<p>Chunks data into block_size blocks for streaming, adds null padding.</p>
<p><span id="more-10724"></span></p>
<div class='sniplrcode'>
<ol class="python" style="font-family:monospace;">
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">math</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">is_debug = <span style="color: #008000;">False</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #dc143c;">chunk</span><span style="color: black;">&#40;</span>data, block_size, padding=b<span style="color: #483d8b;">&#8216;<span style="color: #000099; font-weight: bold;">\x</span>00&#8242;</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; data_size &nbsp; &nbsp; &nbsp; = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; padding_size &nbsp; &nbsp;= block_size &#8211; <span style="color: black;">&#40;</span>data_size <span style="color: #66cc66;">%</span> block_size<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>data_size <span style="color: #66cc66;">&gt;</span> block_size<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#40;</span>block_size &#8211; data_size<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; is_padded &nbsp; &nbsp; &nbsp; = <span style="color: black;">&#40;</span>padding_size <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: black;">&#40;</span>padding_size <span style="color: #66cc66;">!</span>= block_size<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; total_blocks &nbsp; &nbsp;= <span style="color: #dc143c;">math</span>.<span style="color: black;">ceil</span><span style="color: black;">&#40;</span>data_size / block_size<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; current_block &nbsp; = <span style="color: #ff4500;">0</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; block_slice &nbsp; &nbsp; = <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>block_size <span style="color: #66cc66;">*</span> current_block<span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span>block_size <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span>current_block + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> is_debug:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;data_size: %d&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>data_size,<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;padding_size: %d&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>padding_size,<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;is_padded: %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>is_padded,<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;total_blocks: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>total_blocks,<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> current_block <span style="color: #66cc66;">&lt;</span> total_blocks:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; a_block = <span style="color: #008000;">slice</span><span style="color: black;">&#40;</span>block_slice<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, block_slice<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>is_padded <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: black;">&#40;</span>current_block == <span style="color: black;">&#40;</span>total_blocks &#8211; <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#91;</span>current_block, total_blocks, data_size, data<span style="color: black;">&#91;</span>a_block<span style="color: black;">&#93;</span> + <span style="color: black;">&#40;</span>padding_size <span style="color: #66cc66;">*</span> padding<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span> <span style="color: black;">&#91;</span>current_block, total_blocks, data_size, data<span style="color: black;">&#91;</span>a_block<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; current_block &nbsp; += <span style="color: #ff4500;">1</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; block_slice<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> &nbsp;+= block_size</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; block_slice<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> &nbsp;+= block_size</div>
</li>
</ol>
</div>
<ul class='snippet-meta'>
<li><strong><a href='http://snipplr.com/view/64823/chunk-data-for-streaming'>Chunk Data for Streaming</a></strong></li>
<li><small>Posted by <a href='http://snipplr.com/users/weilawei'>weilawei</a> on May 9th, 2012</small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/python-chunk-data-for-streaming/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Python) HMAC</title>
		<link>http://snipd.net/python-hmac</link>
		<comments>http://snipd.net/python-hmac#comments</comments>
		<pubDate>Tue, 08 May 2012 19:10:02 +0000</pubDate>
		<dc:creator>SnipBot</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[hmac]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10723</guid>
		<description><![CDATA[HMAC, pass a hash from Crypto.Hash in PyCrypto. Key should be a bytes object. Returns a bytearray. def pad_key&#40;a_hash, a_key&#41;: &#160; &#160; block_size = a_hash.digest_size &#160; &#160; &#160; if &#40;len&#40;a_key&#41; &#62; block_size&#41;: &#160; &#160; &#160; &#160; a_hasher = a_hash.new&#40;&#41; &#160; &#160; &#160; &#160; a_hash.update&#40;a_key&#41; &#160; &#160; &#160; &#160; return a_hasher.digest&#40;&#41; &#160; &#160; elif &#40;len&#40;a_key&#41; &#60; [...]]]></description>
			<content:encoded><![CDATA[<p>HMAC, pass a hash from Crypto.Hash in PyCrypto. Key should be a bytes object. Returns a bytearray.</p>
<p><span id="more-10723"></span></p>
<div class='sniplrcode'>
<ol class="python" style="font-family:monospace;">
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> pad_key<span style="color: black;">&#40;</span>a_hash, a_key<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; block_size = a_hash.<span style="color: black;">digest_size</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a_key<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> block_size<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; a_hasher = a_hash.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; a_hash.<span style="color: black;">update</span><span style="color: black;">&#40;</span>a_key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> a_hasher.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a_key<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> block_size<span style="color: black;">&#41;</span>: </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> a_key + <span style="color: black;">&#40;</span>b<span style="color: #483d8b;">&#8216;<span style="color: #000099; font-weight: bold;">\x</span>00&#8242;</span> <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span>block_size &#8211; <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a_key<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> a_key</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7700;font-weight:bold;">def</span> HMAC<span style="color: black;">&#40;</span>a_hash, a_key, data<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; block_size &nbsp;= a_hash.<span style="color: black;">digest_size</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; a_key &nbsp; &nbsp; &nbsp; = pad_key<span style="color: black;">&#40;</span>a_hash, a_key<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; block_range = <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>i <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>block_size<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; xor_5c &nbsp; &nbsp; &nbsp;= <span style="color: #dc143c;">bytearray</span>.<span style="color: black;">maketrans</span><span style="color: black;">&#40;</span>block_range, <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>i ^ 0x5c <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>block_size<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; xor_36 &nbsp; &nbsp; &nbsp;= <span style="color: #dc143c;">bytearray</span>.<span style="color: black;">maketrans</span><span style="color: black;">&#40;</span>block_range, <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>i ^ 0&#215;36 <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>block_size<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; inner_hasher = a_hash.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; outer_hasher = inner_hasher.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; final_hasher = inner_hasher.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; inner_hasher.<span style="color: black;">update</span><span style="color: black;">&#40;</span>a_key.<span style="color: black;">translate</span><span style="color: black;">&#40;</span>xor_36<span style="color: black;">&#41;</span> + data<span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; outer_hasher.<span style="color: black;">update</span><span style="color: black;">&#40;</span>a_key.<span style="color: black;">translate</span><span style="color: black;">&#40;</span>xor_5c<span style="color: black;">&#41;</span> + inner_hasher.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; final_hasher.<span style="color: black;">update</span><span style="color: black;">&#40;</span>outer_hasher.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">bytearray</span><span style="color: black;">&#40;</span>final_hasher.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
</ol>
</div>
<ul class='snippet-meta'>
<li><strong><a href='http://snipplr.com/view/64824/hmac'>HMAC</a></strong></li>
<li><small>Posted by <a href='http://snipplr.com/users/weilawei'>weilawei</a> on May 9th, 2012</small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/python-hmac/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Java) Quicksort in Java, with Enforced Suckitude</title>
		<link>http://snipd.net/java-quicksort-in-java-with-enforced-suckitude</link>
		<comments>http://snipd.net/java-quicksort-in-java-with-enforced-suckitude#comments</comments>
		<pubDate>Mon, 07 May 2012 14:10:03 +0000</pubDate>
		<dc:creator>SnipBot</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10713</guid>
		<description><![CDATA[It&#8217;s no fun implementing QuickSort unless you can force it out of its blister-fast, O(n log n) speed and humiliate it with its worst-case, O(n^2) runtime. So that&#8217;s what I set out to do. My naive partition simply pivots around the low item, but my randomized partition defeats the sucky inputs by choosing a random [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s no fun implementing QuickSort unless you can force it out of its blister-fast, O(n log n) speed and humiliate it with its worst-case, O(n^2) runtime. So that&#8217;s what I set out to do.</p>
<p>My naive partition simply pivots around the low item, but my randomized partition defeats the sucky inputs by choosing a random pivot. (If you&#8217;re interested in checking out a QuickSort which naively partitions until it hits an attempt to get it to run in quadratic time, check out IntroSort &#8212; which simply  fails over to Merge Sort when it exceeds its optimal recursion depth.)</p>
<p><span id="more-10713"></span></p>
<div class='sniplrcode'>
<ol class="java" style="font-family:monospace;">
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.SimpleDateFormat</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Random</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp;* </span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp;*/</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp;* @author Roger</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp;*</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp;*/</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyQuickSort <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp; &nbsp; &nbsp;* @param args</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> files <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;lincoln2.txt&quot;</span>, <span style="color: #0000ff;">&quot;lincoln.txt&quot;</span>, <span style="color: #0000ff;">&quot;twain2.txt&quot;</span>, </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;twain3.txt&quot;</span>, <span style="color: #0000ff;">&quot;twain.txt&quot;</span>, <span style="color: #0000ff;">&quot;eliot.txt&quot;</span>, <span style="color: #0000ff;">&quot;tolstoy.txt&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//String[] files = { &quot;lincoln2.txt&quot;, &quot;lincoln.txt&quot;, &quot;twain2.txt&quot;};</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; MyQuickSort sort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyQuickSort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asimpledateformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">SimpleDateFormat</span></a> format <span style="color: #339933;">=</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asimpledateformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">SimpleDateFormat</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;EEE MMM dd HH:mm:ss-SSS zzz yyyy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> sortTest <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> suckySortTest <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&#8212;&#8212;&#8212;TEST QUICK SORT &#8212;&#8212;&#8212;&#8212;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> files.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> testCase <span style="color: #339933;">=</span> MergeTest.<span style="color: #006633;">readFile</span><span style="color: #009900;">&#40;</span>files<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> start <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adate+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Date</span></a> now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adate+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Date</span></a><span style="color: #009900;">&#40;</span>start<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;File: &quot;</span> <span style="color: #339933;">+</span> files<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Total words: &quot;</span> <span style="color: #339933;">+</span> testCase.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;begin test: &quot;</span> <span style="color: #339933;">+</span> format.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>now<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sortTest <span style="color: #339933;">=</span> sort.<span style="color: #006633;">quickSort</span><span style="color: #009900;">&#40;</span>testCase, <span style="color: #cc66cc;">0</span>, testCase.<span style="color: #006633;">length</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> end <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adate+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Date</span></a><span style="color: #009900;">&#40;</span>end<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;end test: &quot;</span> <span style="color: #339933;">+</span> format.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>now<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;total time: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>end <span style="color: #339933;">-</span> start<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Make it suck&#8230;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> reverseTest <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span>sortTest.<span style="color: #006633;">length</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> sortTest.<span style="color: #006633;">length</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span>, j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&#8211;</span>, j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reverseTest<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> sortTest<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; start <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adate+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Date</span></a><span style="color: #009900;">&#40;</span>start<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&#8212;&#8212;-SUCKY VERSION&#8212;&#8212;&#8212;-&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;File: &quot;</span> <span style="color: #339933;">+</span> files<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Total words: &quot;</span> <span style="color: #339933;">+</span> testCase.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;begin test: &quot;</span> <span style="color: #339933;">+</span> format.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>now<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; suckySortTest <span style="color: #339933;">=</span> sort.<span style="color: #006633;">quickSort</span><span style="color: #009900;">&#40;</span>testCase, <span style="color: #cc66cc;">0</span>, testCase.<span style="color: #006633;">length</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; now <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adate+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Date</span></a><span style="color: #009900;">&#40;</span>end<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;end test: &quot;</span> <span style="color: #339933;">+</span> format.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>now<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;total time: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>end <span style="color: #339933;">-</span> start<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//for (int i = 0; i &lt; sortTest.length; i++) {</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// &nbsp; &nbsp;System.out.println(sortTest[i]);</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//}</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> quickSort<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> list, <span style="color: #000066; font-weight: bold;">int</span> low, <span style="color: #000066; font-weight: bold;">int</span> high<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>high <span style="color: #339933;">&lt;=</span> low<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> list<span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//int pivot = &nbsp;partition(list, low, high);</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> pivot <span style="color: #339933;">=</span> &nbsp;nonSuckyPartition<span style="color: #009900;">&#40;</span>list, low, high<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; quickSort<span style="color: #009900;">&#40;</span>list, low, pivot<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; quickSort<span style="color: #009900;">&#40;</span>list, pivot<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, high<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> list<span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp; &nbsp; &nbsp;* Sucky version of partition &#8212; it uses the first element as the partition.</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp; &nbsp; &nbsp;* @param list</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp; &nbsp; &nbsp;* @param low</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp; &nbsp; &nbsp;* @param high</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp; &nbsp; &nbsp;* @return</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000; font-style: italic; font-weight: bold;">&nbsp; &nbsp; &nbsp;*/</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> partition<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> list, <span style="color: #000066; font-weight: bold;">int</span> low, <span style="color: #000066; font-weight: bold;">int</span> high<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> low <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> high<span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> high<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#91;</span>high<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// do nothing</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#91;</span>high<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#91;</span><span style="color: #339933;">&#8211;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>j <span style="color: #339933;">==</span> low<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&gt;=</span> j<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; swap<span style="color: #009900;">&#40;</span>list, i, j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; swap<span style="color: #009900;">&#40;</span>list, i, high<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> i<span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> nonSuckyPartition<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> list, <span style="color: #000066; font-weight: bold;">int</span> low, <span style="color: #000066; font-weight: bold;">int</span> high<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> low <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> high<span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> partition <span style="color: #339933;">=</span> randomizeInRange<span style="color: #009900;">&#40;</span>low, high<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> high<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#91;</span>partition<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// do nothing</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#91;</span>partition<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#91;</span><span style="color: #339933;">&#8211;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>j <span style="color: #339933;">==</span> low<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&gt;=</span> j<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; swap<span style="color: #009900;">&#40;</span>list, i, j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; swap<span style="color: #009900;">&#40;</span>list, i, high<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> i<span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> swap<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> list, <span style="color: #000066; font-weight: bold;">int</span> i, <span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> swap <span style="color: #339933;">=</span> list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> list<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; list<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> swap<span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> randomizeInRange<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> low, <span style="color: #000066; font-weight: bold;">int</span> high<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #009900;">&#40;</span>low <span style="color: #339933;">&lt;</span> high<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> retval <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arandom+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Random</span></a> rand <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arandom+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Random</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// get the range value</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> range <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span><span style="color: #009900;">&#41;</span>high <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span><span style="color: #009900;">&#41;</span>low <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> fraction <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>range <span style="color: #339933;">*</span> rand.<span style="color: #006633;">nextDouble</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; retval <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>fraction <span style="color: #339933;">+</span> low<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> retval<span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#125;</span></div>
</li>
</ol>
</div>
<ul class='snippet-meta'>
<li><strong><a href='http://snipplr.com/view/64808/quicksort-in-java-with-enforced-suckitude'>Quicksort in Java, with Enforced Suckitude</a></strong></li>
<li><small>Posted by <a href='http://snipplr.com/users/rtperson'>rtperson</a> on May 8th, 2012</small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/java-quicksort-in-java-with-enforced-suckitude/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(PHP) auto complete like google suggestion</title>
		<link>http://snipd.net/php-auto-complete-like-google-suggestion</link>
		<comments>http://snipd.net/php-auto-complete-like-google-suggestion#comments</comments>
		<pubDate>Mon, 07 May 2012 07:20:09 +0000</pubDate>
		<dc:creator>SnipBot</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[suggestions]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10712</guid>
		<description><![CDATA[auto complete code snippet like google suggestions &#60;link href=&#34;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css&#34; rel=&#34;stylesheet&#34; type=&#34;text/css&#34;/&#62; &#160; &#60;script src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js&#34;&#62;&#60;/script&#62; &#160; &#60;script src=&#34;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js&#34;&#62;&#60;/script&#62; &#160; &#160; &#60;script&#62; &#160; $&#40;document&#41;.ready&#40;function&#40;&#41; &#123; &#160; &#160; $&#40;&#34;input#s&#34;&#41;.autocomplete&#40;&#123; &#160; &#160; source: &#91;&#34;Sydney&#34;, &#34;Wollongong&#34;, &#34;Whyalla&#34;, &#34;Warrnambool&#34;, &#34;Wagga Wagga&#34;, &#34;Traralgon&#34; &#160; &#160; &#160; &#160; &#160; &#160; &#160;, &#34;Townsville&#34;, &#34;Toowoomba&#34;, &#34;Tewantin-Noosa&#34;, &#34;Taree&#34;, &#34;Tamworth&#34;, &#34;Sunshine Coast&#34;, &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>auto complete code snippet like google suggestions</p>
<p><span id="more-10712"></span></p>
<div class='sniplrcode'>
<ol class="php" style="font-family:monospace;">
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #339933;">&lt;</span>link href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; <span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;input#s&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>autocomplete<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; source<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Sydney&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Wollongong&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Whyalla&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Warrnambool&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Wagga Wagga&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Traralgon&quot;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Townsville&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Toowoomba&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Tewantin-Noosa&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Taree&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Tamworth&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Sunshine Coast&quot;</span><span style="color: #339933;">,</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Sunbury&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Shoalhaven&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Shoalhaven&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Shepparton-Mooroopna&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Roebourne&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Rockhampton&quot;</span><span style="color: #339933;">,</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Richmond-Windsor&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Queanbeyan&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Port Macquarie&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Perth&quot;</span> <span style="color: #339933;">,</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Palmerston&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Newcastle&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Mount Isa&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Mount Gambier&quot;</span><span style="color: #009900;">&#93;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; <span style="color: #009933; font-style: italic;">/** get enty http://wwp.greenwichmeantime.com/time-zone/australia/city/index.htm **/</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; <span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">/*************************************************************/</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">/*************************** POINT 2 *************************/</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">/*************************************************************/</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">$<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#8216;input#s&#8217;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>autocomplete<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">&quot;Melbourne&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Kyneton&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Edinburgh&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Castlemaine&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Ballarat&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Bendigo&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;New York&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Tokyo&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;Beijing&quot;</span><span style="color: #339933;">,</span> </div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">&quot;London&quot;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minLength<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>focus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>data<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autocomplete&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>search<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></div>
</li>
</ol>
</div>
<ul class='snippet-meta'>
<li><strong><a href='http://snipplr.com/view/64807/auto-complete-like-google-suggestion'>auto complete like google suggestion</a></strong></li>
<li><small>Posted by <a href='http://snipplr.com/users/webtechdev'>webtechdev</a> on May 7th, 2012</small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/php-auto-complete-like-google-suggestion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom prolog and epilog for a function in C++</title>
		<link>http://snipd.net/custom-prolog-and-epilog-for-a-function-in-c</link>
		<comments>http://snipd.net/custom-prolog-and-epilog-for-a-function-in-c#comments</comments>
		<pubDate>Sun, 15 Apr 2012 19:34:29 +0000</pubDate>
		<dc:creator>FY</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Assembly]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[epilog]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[hooking]]></category>
		<category><![CDATA[naked]]></category>
		<category><![CDATA[Prolog]]></category>
		<category><![CDATA[register]]></category>
		<category><![CDATA[virtual class member functions]]></category>
		<category><![CDATA[x86]]></category>
		<category><![CDATA[__declspec(naked)]]></category>
		<category><![CDATA[__LOCAL_SIZE]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10466</guid>
		<description><![CDATA[Traditionally, the compiler is responsible for creating the prolog and epilog of a function. However, custom prolog and epilog code can be written if a function has been declared with the naked attribute. The snippet below demonstrates a naked function with custom prolog and epilog code. __declspec(naked) void foo(){ // Prolog __asm { push ebp [...]]]></description>
			<content:encoded><![CDATA[<p>Traditionally, the compiler is responsible for creating the <a href="http://msdn.microsoft.com/en-us/library/tawsa7cb(v=vs.80).aspx">prolog</a> and <a href="http://msdn.microsoft.com/en-us/library/tawsa7cb(v=vs.80).aspx">epilog</a> of a function. However, custom prolog and epilog code can be written if a function has been declared with the <a href="http://msdn.microsoft.com/en-us/library/h5w10wxs(v=vs.80).aspx">naked</a> attribute.</p>
<p>The snippet below demonstrates a naked function with custom prolog and epilog code.</p>
<pre class="brush: cpp; gutter: true">__declspec(naked) void foo(){

	// Prolog
	__asm {
		push ebp		// Push the Extended Base Pointer
		mov ebp, esp		// Set frame pointer
		sub esp, __LOCAL_SIZE	// Reserve space for local variables
		pushad			// Push all general-purpose registers
	}

	// Do stuff

	// Epilog
	__asm {
		popad			// Pop all general-purpose registers
		mov esp, ebp		// Restore stack pointer
		pop ebp			// Restore the Extended Base Pointer
		retn			// Return
	}

}</pre>
<p>The <a href="http://msdn.microsoft.com/en-us/library/aa273416(v=vs.60).aspx">__LOCAL_SIZE</a> symbol can be used to let the compiler determine the amount of space needed for variables.</p>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/custom-prolog-and-epilog-for-a-function-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hooking with the Microsoft Detours library in C++</title>
		<link>http://snipd.net/hooking-with-the-microsoft-detours-library-in-c</link>
		<comments>http://snipd.net/hooking-with-the-microsoft-detours-library-in-c#comments</comments>
		<pubDate>Mon, 09 Apr 2012 17:12:10 +0000</pubDate>
		<dc:creator>FY</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[call]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[debugview]]></category>
		<category><![CDATA[detours]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[dll injection]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[hooking]]></category>
		<category><![CDATA[intercept]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Registry]]></category>
		<category><![CDATA[RegOpenKeyExW]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10331</guid>
		<description><![CDATA[The DLL Injection example described how to inject a DLL into an existing process. The snippets below demonstrate a combination of hooking and DLL injection in C++ with the Microsoft Detours library. Quote: In computer programming, the term hooking covers a range of techniques used to alter or augment the behavior of an operating system, [...]]]></description>
			<content:encoded><![CDATA[<p>The <a title="DLL injection in C++" href="http://snipd.net/dll-injection-in-c">DLL Injection</a> example described how to inject a DLL into an existing process. The snippets below demonstrate a combination of hooking and DLL injection in C++ with the Microsoft <a href="http://research.microsoft.com/en-us/projects/detours/">Detours</a> library.</p>
<p>Quote:</p>
<blockquote><p>In computer programming, the term hooking covers a range of techniques used to alter or augment the behavior of an operating system, of applications, or of other software components by intercepting function calls or messages or events passed between software components. Code that handles such intercepted function calls, events or messages is called a &#8220;hook&#8221;.</p></blockquote>
<p>The <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724897(v=vs.85).aspx">RegOpenKeyExW </a>function within <a href="http://en.wikipedia.org/wiki/Microsoft_Windows_library_files#Kernel32.dll">kernel32.dll</a> is responsible for opening a specified <a href="http://en.wikipedia.org/wiki/Windows_Registry">registry</a> key. To demonstrate hooking, the RegOpenKeyExW function will be intercepted within the <a href="https://www.google.com/chrome">Google Chrome</a> process. A message will be logged at each call of RegOpenKeyExW. These messages can be viewed with <a href="http://technet.microsoft.com/en-us/sysinternals/bb896647">DebugView</a>.</p>
<p><span id="more-10331"></span></p>
<p><strong>DLLInjector.cpp: Responsible for launching Google Chrome and injecting the specified DLL into the process</strong></p>
<pre class="brush: cpp; gutter: true">// DLLInjector.cpp : Defines the entry point for the console application.
//
#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;Psapi.h&gt;
#include &lt;string.h&gt;
#include &quot;stdafx.h&quot;
#include &quot;detours.h&quot;

#pragma comment(lib, &quot;detours.lib&quot;)

#define DLL_PATH &quot;\\..\\Debug\\exampledll.dll&quot; // The DLL we would like to inject
#define PROC_DIR &quot;C:\\Users\\Ferhat\\AppData\\Local\\Google\\Chrome\\Application&quot;
#define PROC_PATH &quot;C:\\Users\\Ferhat\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe&quot; // Google Chrome

int _tmain(int argc, _TCHAR* argv[])
{
	STARTUPINFO si;
	PROCESS_INFORMATION pi;

	ZeroMemory( &amp;si, sizeof(si) );
	si.cb = sizeof(si);
	ZeroMemory( &amp;pi, sizeof(pi) );

	TCHAR currentDir[MAX_PATH];
	TCHAR dllDir[MAX_PATH];
	GetCurrentDirectory(MAX_PATH,currentDir);

	strcpy(dllDir,currentDir);
	strcat(dllDir,DLL_PATH);

	printf(&quot;Current directory: %s\n&quot;, currentDir);
	printf(&quot;DLL path: %s\n&quot;, dllDir);
	printf(&quot;Process path: %s\n&quot;, PROC_PATH);

	bool detourProcess = DetourCreateProcessWithDll(PROC_PATH,&quot;&quot;,0,0,FALSE,CREATE_DEFAULT_ERROR_MODE,0,PROC_DIR,&amp;si,&amp;pi, dllDir, NULL);

	if(detourProcess){
		printf(&quot;Injected DLL: %s\n&quot;, dllDir);
	} else {
		printf(&quot;Failed to inject DLL: %s\n&quot;, dllDir);
		system(&quot;PAUSE&quot;);
	}

	return 0;
}</pre>
<p><strong>FunctionHook: represents a hook</strong></p>
<p><strong>Header file</strong></p>
<pre class="brush: cpp; gutter: true">#pragma once

#include &lt;Windows.h&gt;
#include &lt;string&gt;

using namespace std;

// Used for detouring class virtual member functions
#define Naked __declspec( naked )

class FunctionHook
{
public:
	FunctionHook(void);
	~FunctionHook(void);

	// Used for fetching the hook (e.g. &quot;CPlayer::ctor&quot; or &quot;sprintf&quot;)
	string Identifier;

	// Optional module (e.g. &quot;msvcrt.dll&quot;)
	string Module;

	// Signature of the function in memory
	string Signature;

	// Mask
	string Mask;

	// The original address of the function
	DWORD OriginalAddress;

	// The detour function
	PBYTE Detour;

	// The address of the detour function
	DWORD DetourAddress;
};</pre>
<p><strong>CPP file</strong></p>
<pre class="brush: cpp; gutter: true">#include &quot;FunctionHook.h&quot;

FunctionHook::FunctionHook(void)
{
	this-&gt;Identifier = &quot;&quot;;
	this-&gt;Module = &quot;&quot;;
	this-&gt;Mask = &quot;&quot;;
	this-&gt;Signature = &quot;&quot;;
	this-&gt;DetourAddress = 0;
	this-&gt;OriginalAddress = 0;
}

FunctionHook::~FunctionHook(void)
{
}</pre>
<p><strong>HookManager: responsible for hooking, retrieving hooks and keeping a list of active hooks</strong></p>
<p><strong>Header file</strong></p>
<pre class="brush: cpp; gutter: true">#pragma once

#include &lt;Windows.h&gt;
#include &lt;vector&gt;
#include &quot;FunctionHook.h&quot;
#include &quot;Hook.h&quot;
#include &quot;detours.h&quot;
#include &quot;Log.h&quot;

#pragma comment(lib, &quot;ws2_32.lib&quot;)
#pragma comment(lib, &quot;psapi.lib&quot;)
#pragma comment(lib, &quot;dbghelp.lib&quot;)
#pragma comment(lib, &quot;detours.lib&quot;)

using namespace std;

typedef std::tr1::shared_ptr&lt;FunctionHook&gt; fhPtr;

class HookManager
{
public:
	HookManager(void);
	~HookManager(void);
	vector&lt;fhPtr&gt; Hooks;
	FunctionHook* GetHook(char* identifier);
	void CreateHook(FunctionHook* hook);
	static HookManager* Instance();
};</pre>
<p><strong>CPP file</strong></p>
<pre class="brush: cpp; gutter: true">#include &quot;HookManager.h&quot;

static HookManager* instance;

HookManager::HookManager(void)
{

}

HookManager::~HookManager(void)
{
}

HookManager* HookManager::Instance(){
	if(!instance){
		instance = new HookManager();
	}

	return instance;
}

void SignatureToByteArray(char* signature, BYTE* bytes){
	int tmp;
	for(int i=0;i&lt;strlen(signature)/2;i++){
		sscanf(signature+2*i,&quot;%2x&quot;,&amp;tmp);
		bytes[i] = tmp;
	}
}

void HookManager::CreateHook(FunctionHook* hook){
	DWORD functionAddress;
	DWORD detouredAddress;
	PBYTE foundAddress;

	FunctionHook* hookInst = new FunctionHook();
	hookInst-&gt;Detour = hook-&gt;Detour;
	hookInst-&gt;DetourAddress = hook-&gt;DetourAddress;
	hookInst-&gt;Identifier = hook-&gt;Identifier;
	hookInst-&gt;Mask = hook-&gt;Mask;
	hookInst-&gt;Module = hook-&gt;Module;
	hookInst-&gt;OriginalAddress = hook-&gt;OriginalAddress;
	hookInst-&gt;Signature = hook-&gt;Signature;

	if(strlen(hookInst-&gt;Module.c_str()) &lt;= 0){
		BYTE* sigArray = new BYTE[strlen(hookInst-&gt;Signature.c_str())/2];
		SignatureToByteArray(const_cast&lt;char*&gt;(hookInst-&gt;Signature.c_str()), sigArray);
		functionAddress = sigFindPattern(getMainModule(), sigArray, const_cast&lt;char*&gt;(hookInst-&gt;Mask.c_str()));
		hookInst-&gt;OriginalAddress = functionAddress;
		LogDebug(&quot;Hooking %s at @0x%08X\n&quot;, const_cast&lt;char*&gt;(hookInst-&gt;Identifier.c_str()), hookInst-&gt;OriginalAddress);
		detouredAddress = (DWORD)DetourFunction((PBYTE)functionAddress, hookInst-&gt;Detour);
		hookInst-&gt;DetourAddress = detouredAddress;
	} else {
		foundAddress = DetourFindFunction(const_cast&lt;char*&gt;(hookInst-&gt;Module.c_str()),const_cast&lt;char*&gt;(hookInst-&gt;Identifier.c_str()));
		hookInst-&gt;OriginalAddress = reinterpret_cast&lt;DWORD&gt;(foundAddress);
		LogDebug(&quot;Hooking %s at @0x%08X\n&quot;, const_cast&lt;char*&gt;(hookInst-&gt;Identifier.c_str()), hookInst-&gt;OriginalAddress);
		detouredAddress = (DWORD)DetourFunction(foundAddress, hookInst-&gt;Detour);
		hookInst-&gt;DetourAddress = detouredAddress;
	}

	// Add the hook to the list of hooks
	HookManager::Instance()-&gt;Hooks.push_back(fhPtr(hookInst));
}

FunctionHook* HookManager::GetHook(char* identifier){
	for(int i=0;i&lt;HookManager::Instance()-&gt;Hooks.size();i++){
		FunctionHook* functionHook = HookManager::Instance()-&gt;Hooks[i].get();
		if(functionHook != NULL){
			if(functionHook-&gt;Identifier == identifier){
				return functionHook;
			}
		}
	}

	LogDebug(&quot;Hook not found\n&quot;);
	return NULL;
}</pre>
<p><strong>Log: responsible for debug messages</strong></p>
<p><strong>Header file</strong></p>
<pre class="brush: cpp; gutter: true">#pragma once

#include &quot;stdafx.h&quot;

#ifndef LOG_H
#define LOG_H

void LogDebug(const char *format, ...);

void LogMsgBox(const char *format, ...);

void LogClearScreen();
void LogScreen(const char *format, ...);
void LogDraw();
void LogPrintScreen(int posX, int posY, int width, const char *format, ...);

#endif</pre>
<p><strong>CPP file</strong></p>
<pre class="brush: cpp; gutter: true">#define _CRT_SECURE_NO_WARNINGS
#include &lt;Windows.h&gt;
#include &lt;cstdio&gt;
#include &lt;string&gt;
#include &quot;Log.h&quot;

using namespace std;

string screenlogbuffer;

void LogScreen(const char *format, ...)
{
	va_list args;
	va_start(args, format);
	char tmp[1024];
	vsprintf(tmp, format, args);
	va_end(args);
	screenlogbuffer.append(tmp);
}

void LogDebug(const char *format, ...)
{
	char msgBuf[4096];
	va_list args;
	va_start(args, format);
	vsprintf(msgBuf, format, args);
	va_end(args);
	OutputDebugString(msgBuf);
}
</pre>
<p><strong>DLLMain: The DLL injected into the Google Chrome process</strong></p>
<p><strong>CPP file</strong></p>
<pre class="brush: cpp; gutter: true">// dllmain.cpp : Defines the entry point for the DLL application.
#define _CRT_SECURE_NO_WARNINGS
#include &lt;WinSock2.h&gt;
#include &lt;Windows.h&gt;
#include &lt;intrin.h&gt;
#include &lt;cstdio&gt;
#include &lt;cmath&gt;
#include &lt;ctime&gt;
#include &lt;set&gt;
#include &lt;vector&gt;

#include &quot;HookManager.h&quot;

#pragma comment(lib, &quot;ws2_32.lib&quot;)
#pragma comment(lib, &quot;psapi.lib&quot;)
#pragma comment(lib, &quot;dbghelp.lib&quot;)
#pragma comment(lib, &quot;detours.lib&quot;)

typedef LSTATUS (__stdcall* pRegOpenKeyExW)(HKEY, LPCWSTR, DWORD, REGSAM, PHKEY);
pRegOpenKeyExW pOriginalRegOpenKeyExW;

LSTATUS __stdcall MyRegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult){
	LogDebug(&quot;RegOpenKeyExW called: %S\n&quot;, lpSubKey);
	return pOriginalRegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult);
}

void main()
{
	FunctionHook* regOpenKeyExWHook = new FunctionHook();
	regOpenKeyExWHook-&gt;Identifier = &quot;RegOpenKeyExW&quot;;
	regOpenKeyExWHook-&gt;Module = &quot;kernel32.dll&quot;;
	regOpenKeyExWHook-&gt;Detour = (PBYTE)MyRegOpenKeyExW;
	HookManager::Instance()-&gt;CreateHook(regOpenKeyExWHook);
	pOriginalRegOpenKeyExW = (pRegOpenKeyExW)(HookManager::Instance()-&gt;GetHook(&quot;RegOpenKeyExW&quot;)-&gt;DetourAddress);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
	int processId = GetCurrentProcessId();

	if(fdwReason == DLL_PROCESS_ATTACH)
	{
		DWORD id;
		LogDebug(&quot;Attach...\n&quot;);
		LogDebug(&quot;Process ID: %d\n&quot;, processId);
		CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)main, NULL, 0, &amp;id);
	}
	if(fdwReason == DLL_PROCESS_DETACH)
	{
		char buffer[40];
		_strtime(buffer);
		LogDebug(&quot;Detach...\n&quot;);
		LogDebug(&quot;Time:%s\n&quot;, buffer);
	}
	return TRUE;
}</pre>
<p>The function MyRegOpenKeyExW represents the hook for RegOpenKeyExW. It prints a debug message and calls the original RegOpenKeyExW function.</p>
<p><strong>DebugView output</strong></p>
<div id="attachment_10337" class="wp-caption alignnone" style="width: 310px"><a href="http://snipd.net/wp-content/uploads/2012/04/DebugView_RegOpenKeyExW.png" rel="lightbox[10331]"><img class="size-medium wp-image-10337" title="DebugView_RegOpenKeyExW" src="http://snipd.net/wp-content/uploads/2012/04/DebugView_RegOpenKeyExW-300x169.png" alt="" width="300" height="169" /></a><p class="wp-caption-text">DebugView output</p></div>
<p>The archive containing the VC++ source code can be downloaded from <a href="http://snipd.net/code/DLLInjectionExampleWithHooking.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/hooking-with-the-microsoft-detours-library-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Bash) Download Directory with scp</title>
		<link>http://snipd.net/bash-download-directory-with-scp</link>
		<comments>http://snipd.net/bash-download-directory-with-scp#comments</comments>
		<pubDate>Wed, 04 Apr 2012 23:30:03 +0000</pubDate>
		<dc:creator>SnipBot</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[folder]]></category>
		<category><![CDATA[scp]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10179</guid>
		<description><![CDATA[download directory to localhost home folder new-dir-name $ scp -r yourusername@yourserver:~/public_html/directory/ ~/Downloads/new-dir-name Download Directory with scp Posted by zackn9ne on April 5th, 2012]]></description>
			<content:encoded><![CDATA[<p>download directory to localhost home folder new-dir-name</p>
<p><span id="more-10179"></span></p>
<div class='sniplrcode'>
<ol class="bash" style="font-family:monospace;">
<li style="font-weight: normal; vertical-align:top;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">$ <span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-r</span> yourusername<span style="color: #000000; font-weight: bold;">@</span>yourserver:~<span style="color: #000000; font-weight: bold;">/</span>public_html<span style="color: #000000; font-weight: bold;">/</span>directory<span style="color: #000000; font-weight: bold;">/</span> ~<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>new-dir-name</div>
</li>
</ol>
</div>
<ul class='snippet-meta'>
<li><strong><a href='http://snipplr.com/view/64362/download-directory-with-scp'>Download Directory with scp</a></strong></li>
<li><small>Posted by <a href='http://snipplr.com/users/zackn9ne'>zackn9ne</a> on April 5th, 2012</small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/bash-download-directory-with-scp/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assembling with nasm and disassembling with ndisasm</title>
		<link>http://snipd.net/assembling-with-nasm-and-disassembling-with-ndisasm</link>
		<comments>http://snipd.net/assembling-with-nasm-and-disassembling-with-ndisasm#comments</comments>
		<pubDate>Sun, 25 Mar 2012 15:40:09 +0000</pubDate>
		<dc:creator>FY</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Assembly]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[nasm]]></category>
		<category><![CDATA[ndisasm]]></category>
		<category><![CDATA[offset]]></category>
		<category><![CDATA[opcode]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://snipd.net/?p=10025</guid>
		<description><![CDATA[The following commands demonstrate assembling with nasm and disassembling with ndisasm. $ cat example.s mov eax,0 test eax,eax $ nasm example.s $ ndisasm example 00000000 66B800000000 mov eax,0x0 00000006 6685C0 test eax,eax The first column of the disassembly contains the file offset, the second column contains the opcodes and the third contains the assembly instructions. [...]]]></description>
			<content:encoded><![CDATA[<p>The following commands demonstrate assembling with <a href="http://linux.die.net/man/1/nasm">nasm</a> and disassembling with <a href="http://linux.die.net/man/1/ndisasm">ndisasm</a>.</p>
<pre class="brush: text; gutter: true">$ cat example.s
mov eax,0
test eax,eax
$ nasm example.s
$ ndisasm example
00000000  66B800000000      mov eax,0x0
00000006  6685C0            test eax,eax</pre>
<p>The first column of the disassembly contains the file offset, the second column contains the <a href="http://en.wikipedia.org/wiki/Opcode">opcodes</a> and the third contains the assembly instructions.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://snipd.net/assembling-with-nasm-and-disassembling-with-ndisasm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

