<?xml version="1.0" encoding="windows-1252"?>
<node id="956075" title="Re: Perl Cipher &amp; questions on semantics/layout optimisation." created="2012-02-25 02:43:16" updated="2012-02-25 02:43:16">
<type id="11">
note</type>
<author id="665462">
repellent</author>
<data>
<field name="doctext">
Hi, and welcome to Perlmonks! Here's my take on your code:&lt;br&gt;
&lt;br&gt;
Find for the following line. It's in the first inner for-loop.&lt;br&gt;
&lt;c&gt;
$offsetpattern .= chr((ord(@karray[i])+ord(@karray[i2])+ ord($offset2[$i % length($key)]))%256);
&lt;/c&gt;
&lt;br&gt;
Notice that you have the bare variables &lt;c&gt;i&lt;/c&gt; and &lt;c&gt;i2&lt;/c&gt;. They ought to be &lt;c&gt;$i&lt;/c&gt; and &lt;c&gt;$i2&lt;/c&gt; instead (you forgot the &lt;c&gt;$&lt;/c&gt;). Also, the array &lt;c&gt;@offset2&lt;/c&gt; is not defined yet at this code point. Plus, indexing into an array should be &lt;c&gt;$karray[$i]&lt;/c&gt; instead of &lt;c&gt;@karray[$i]&lt;/c&gt;.&lt;br&gt;
&lt;br&gt;
Then, I notice that you call [doc://ord] and [doc://chr] a lot. You are joining characters only to split them later again, and that is (wasted) redundant work. In the case of the key array, you can start off by mapping the ordinals:&lt;br&gt;
&lt;c&gt;
my @karray = map ord, (split //, $key);
&lt;/c&gt;
&lt;br&gt;
That saves you the work of calling [doc://ord] like &lt;c&gt;ord($karray[$i2])&lt;/c&gt; a whole bunch of times. This can also apply to your &lt;c&gt;offset&lt;/c&gt; arrays. Keeping all your array elements as ordinals will make your code more concise; no need for intermediate strings.&lt;br&gt;
&lt;br&gt;
By the way:&lt;br&gt;
&lt;c&gt;
my @karray = map ord, (split //, $key);
my $len = length($key);

# prints true for both
print "true" if $len == @karray;
print "true" if $len-1 == $#karray;
&lt;/c&gt;</field>
<field name="root_node">
956063</field>
<field name="parent_node">
956063</field>
</data>
</node>
