Hi! I'm doing things with Crypt::RC4 (via a modified PDF::API2 library) and have found the same input doesn't always produce the same output, as it should. I'm currently at a loss figuring out why and would really like some help. what's happening is when it's called from a) my webpage, the encrypted output is blowing up to many times the size of the input after several iterations. when I call it from b) a cgi test script, apparently with identical arguments, it behaves nicely and does what I think it should. In both cases the outputs are repeatable. diving into the RC4 package I found when I have a message string of, say, 32 bytes, in case a) the line:
my @message = unpack "C*", substr($message, $piece * $MAX_CHUNK_SI +ZE, $MAX_CHUNK_SIZE);
in the RC4 sub, produces an array of 37 characters! even when I alter the substr call and set the last argument to 32, still, the size of @message is 37... when I feed the output of the RC4 back into itself (as in the algorithm for producing the O val for a PDF file encryption dictionary, revision 3), the size of @message blows up to several kb, when it should stay at 32 bytes... I've checked the arguments to the RC4 sub in cases a) and b) and they are the same, and yet the output is different. does anyone know of any reason this could happen? if it helps the inputs to the RC4 function are (converted to hex so you can read them, the actual function gets the ascii strings):
RC4(36A756FC8BA497CA34532CA4A1086AD0, 637573746F6D65726E616D6528BF4E5E +4E758A4164004E56FFFA01082E2E00B6)
the first iteration output (in hex) in case a) is: DFB79756C2D1B49F540DC80A3C39290C6F6B61539635BE03CC2E82990C6A974503ABBC84A2 and in case b): DFB79756C2D1B49F540DC80A3C44D81C7F509ED0787494557D82402EE1FE96FB
you can see they are the same up to character 13 (26th character in the hex representation). it seems like somehow in case a) there's some strange characters getting into the end of the string that in effect are saying to unpack, 'hey, keep reading characters, go on!'. any clues? let me know if you need any more info. thanks,

In reply to perplexing inconsistency using RC4 and unpack by oddmedley

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.