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

No need to split and then rejoin the string:

use MIME::Base64 qw( decode_base64 ); ( my $orig = decode_base64( $_ ) ) =~ s/(.)(?=(.))/ $1 ^ $2 /seg;

Replies are listed 'Best First'.
Re^3: Base64 and byte arrays
by ikegami (Patriarch) on Feb 05, 2009 at 03:18 UTC

    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.

      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.