<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Translate</title>
	<atom:link href="http://blog.didierstevens.com/programs/translate/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.didierstevens.com</link>
	<description>(blog 'DidierStevens)</description>
	<lastBuildDate>Mon, 15 Mar 2010 17:38:44 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: io</title>
		<link>http://blog.didierstevens.com/programs/translate/#comment-33104</link>
		<dc:creator>io</dc:creator>
		<pubDate>Fri, 11 Jul 2008 12:27:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.didierstevens.com/programs/translate/#comment-33104</guid>
		<description>I think the posting process somehow managed to steal some of my text (especially since the first function is copy&amp;pasted from your post), but yes, that&#039;s what I wanted to write. :)

And _especially_ for didactic reasons I think the code should be as good as possible, since other people are learning from it. The folks who don&#039;t understand bit operations should probably stay away from decryption &amp; malware analysis altogether... might do more harm than good. ;)

As for the optimality of the rest of the code, I&#039;ve only skimmed it I&#039;m affraid. I was actually looking for an efficient way of doing ROL/ROR in .py, and that&#039;s how I stumbled over your code. I have plenty of experience with Python, and by accident I work in the malware anlysis industry myself. :) Getting back to the efficiency issue, I&#039;m probably going to write a ROL/ROR module in C/asm to make it efficient enough. That code might even be worth including... 

Cheers!</description>
		<content:encoded><![CDATA[<p>I think the posting process somehow managed to steal some of my text (especially since the first function is copy&amp;pasted from your post), but yes, that&#8217;s what I wanted to write. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And _especially_ for didactic reasons I think the code should be as good as possible, since other people are learning from it. The folks who don&#8217;t understand bit operations should probably stay away from decryption &amp; malware analysis altogether&#8230; might do more harm than good. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>As for the optimality of the rest of the code, I&#8217;ve only skimmed it I&#8217;m affraid. I was actually looking for an efficient way of doing ROL/ROR in .py, and that&#8217;s how I stumbled over your code. I have plenty of experience with Python, and by accident I work in the malware anlysis industry myself. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Getting back to the efficiency issue, I&#8217;m probably going to write a ROL/ROR module in C/asm to make it efficient enough. That code might even be worth including&#8230; </p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Didier Stevens</title>
		<link>http://blog.didierstevens.com/programs/translate/#comment-33101</link>
		<dc:creator>Didier Stevens</dc:creator>
		<pubDate>Thu, 10 Jul 2008 21:05:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.didierstevens.com/programs/translate/#comment-33101</guid>
		<description>I believe you wanted to write this:

def rol(byte, count):
    byte = (byte &lt;&lt; count &#124; byte &gt;&gt; (8 - count)) &amp; 0xFF
    return byte

You&#039;ll be surprised by the gain in performance: about 10%
Translating a 3MB file with the original ROL (rolling 4 bits) takes 168 seconds, translating the same file with the faster ROL takes 155 seconds.

There is a huge overhead in the translation of each byte by the eval function:
outbyte = eval(command)

For every byte, Python has to parse, compile and execute the command. Parsing and compiling takes much more time than the loop in the original ROL command. This is _very_ ineffecient, but _very_ flexible. You can provide your own Python expression without having to edit the translate program.

I used a loop in the ROL and ROR commands for didactic reasons. Manipulating bits is very foreign for most people, even programmers. I believe my version is more readable and understandable, and thus extendable by other people.

But you&#039;re right, removing inner loops adds to the performance. But in this specific case, most CPU cycles go to the eval function, and not to the loop.

Anyways, thanks for your comment, I&#039;ll have to think about how to include your code. Maybe I can leave the original ROL and use your code for the ROR ;-)</description>
		<content:encoded><![CDATA[<p>I believe you wanted to write this:</p>
<p>def rol(byte, count):<br />
    byte = (byte &lt;&lt; count | byte &gt;&gt; (8 &#8211; count)) &amp; 0xFF<br />
    return byte</p>
<p>You&#8217;ll be surprised by the gain in performance: about 10%<br />
Translating a 3MB file with the original ROL (rolling 4 bits) takes 168 seconds, translating the same file with the faster ROL takes 155 seconds.</p>
<p>There is a huge overhead in the translation of each byte by the eval function:<br />
outbyte = eval(command)</p>
<p>For every byte, Python has to parse, compile and execute the command. Parsing and compiling takes much more time than the loop in the original ROL command. This is _very_ ineffecient, but _very_ flexible. You can provide your own Python expression without having to edit the translate program.</p>
<p>I used a loop in the ROL and ROR commands for didactic reasons. Manipulating bits is very foreign for most people, even programmers. I believe my version is more readable and understandable, and thus extendable by other people.</p>
<p>But you&#8217;re right, removing inner loops adds to the performance. But in this specific case, most CPU cycles go to the eval function, and not to the loop.</p>
<p>Anyways, thanks for your comment, I&#8217;ll have to think about how to include your code. Maybe I can leave the original ROL and use your code for the ROR <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: io</title>
		<link>http://blog.didierstevens.com/programs/translate/#comment-33091</link>
		<dc:creator>io</dc:creator>
		<pubDate>Thu, 10 Jul 2008 15:58:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.didierstevens.com/programs/translate/#comment-33091</guid>
		<description>This is _very_ inefficient:
def rol(byte, count):
    while count &gt; 0:
        byte = (byte &lt;&gt; 7) &amp; 0xFF
        count -= 1
    return byte

This should work faster:
def rol(byte, count):
    byte = (byte &lt;&gt; (8 - count)) &amp; 0xFF
    return byte</description>
		<content:encoded><![CDATA[<p>This is _very_ inefficient:<br />
def rol(byte, count):<br />
    while count &gt; 0:<br />
        byte = (byte &lt;&gt; 7) &amp; 0xFF<br />
        count -= 1<br />
    return byte</p>
<p>This should work faster:<br />
def rol(byte, count):<br />
    byte = (byte &lt;&gt; (8 &#8211; count)) &amp; 0xFF<br />
    return byte</p>
]]></content:encoded>
	</item>
</channel>
</rss>
