Posting a huge amount of code like that is completely useless for all concerned, when you don't provide any sample data, and don't give us a clear idea of how the actual output differs from the intended output.

I'm able to tell that there are no syntax errors or compile-time warnings in your program, and I can see that it requires two input files, but I don't happen to have a file called "torah.cod" on my system, and there's no clue about what needs to be in a file called "temp.txt", so there's not much more I can do for you.

Maybe you could reduce the code to a shorter version that can demonstrate the problem, and post that along with just enough sample data so we can run it and see what the problem is.

You do seem to be doing some simple things in very complicated, bizarre ways, as in this part of the "enc()" sub that reads from "temp.txt" (I fixed the indenting a bit):

open (DAT, "$file") || die "$!\n"; while (<DAT>) { seek(DAT, $cc, 0); read(DAT, $tmpR, 1); $tmpR = sprintf("%02x", ord($tmpR)); my @lets = split(//, $tmpR); $data = process($lets[0]); $data = process($lets[1]); print hex($lets[1].$lets[0])." KEY\n"; $cc++; } close(DAT);
This reads a line of data from the file, then seeks to a byte offset that starts at 0 and increments on each iteration. Then, having done that seek, read one byte, and end up with two characters (in @lets) that are the hex digits for the high and low nibbles of the single byte you've just read, process those two letters, then do another full-line read (which starts at the byte following the one returned by "read(...)".

Okay, in some sense that actually does work. But what a lot of confusion and extra effort -- it ends up as one iteration of the while loop for every byte in the file, and the number of times each byte is read from the file is equal to the average line length times 2 -- when you really just need to read the data once, like this:

while (<DATA>) { for my $char ( split // ) { my @lets = split //, sprintf("%02x",ord($char)); process( $_ ) for ( @lets ); print ord( $char ), " KEY\n"; } }
I'm still puzzled why you bother assigning the return value from the "process()" sub to $data, but never use it for anything. BTW, in order for  hex($lets[1].$lets[0]) to equal  ord($char) -- which I assume is your intention -- you must be on a little-endian machine. Keep that in mind if you try to make this portable. (Update: Sorry, there's no way that hex($let[1].$let[0]) can be equal to ord($char), so either you code has it wrong, or else I'm just not able to understand why you wanted to print the values that way.)

There's probably a lot more confusion in the OP code, and it's not just a matter of hashes. Good luck -- if you can put together a coherent question, try posting that as a reply in this thread (or start a new thread), then maybe someone here can help.


In reply to Re: Hash confusion ?! by graff
in thread Hash confusion ?! by thenetfreaker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.