in reply to Re^2: Base64 and byte arrays
in thread Base64 and byte arrays

If you're going to use string xor, why do it a character at a time? The point of the second snippet was to show how to get an array of bytes for future reference.

And your solution doesn't work. It appends a junk character.

Replies are listed 'Best First'.
Re^4: Base64 and byte arrays
by jwkrahn (Abbot) on Feb 05, 2009 at 04:38 UTC
    If you're going to use string xor, why do it a character at a time?

    Why indeed?

    use MIME::Base64 qw( decode_base64 ); my $orig = decode_base64( $_ ); $orig ^= substr $orig, 1;
    And your solution doesn't work. It appends a junk character.

    joec_'s explaination didn't say what to do with the last byte so I left it in.

      There are two possibilities.

      • There's a bug resulting in a byte of information leaking.
      • There's an extra byte that serves as a key.

      The safer bet is the presumption that there is no bug, thus the extra byte is junk. This was confirmed when the OP said my solution worked perfectly.