in reply to Base64 and byte arrays
Strings are internally stored "C" byte arrays. You can even do some traditionally numerical operations on them.
use MIME::Base64 qw( decode_base64 ); my $scrambled = decode_base64($_); my $orig = substr($scrambled, 0, -1) ^ substr($scrambled, 1);
But if you prefer to deal with an array of numbers, no problem! ord converts allows a character to be treated as a number, and chr does the inverse.
use MIME::Base64 qw( decode_base64 ); my $scrambled = decode_base64($_); my @scrambled = map ord, split //, $scrambled; my @orig = map { $scrambled[$_-1] ^ $scrambled[$_] } 1..$#scrambl +ed; my $orig = join '', map chr, @orig;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Base64 and byte arrays
by joec_ (Scribe) on Feb 05, 2009 at 00:50 UTC | |
|
Re^2: Base64 and byte arrays
by jwkrahn (Abbot) on Feb 05, 2009 at 02:52 UTC | |
by ikegami (Patriarch) on Feb 05, 2009 at 03:18 UTC | |
by jwkrahn (Abbot) on Feb 05, 2009 at 04:38 UTC | |
by ikegami (Patriarch) on Feb 05, 2009 at 05:01 UTC | |
|
Re^2: Base64 and byte arrays
by gone2015 (Deacon) on Feb 05, 2009 at 16:36 UTC |