Permalink
Browse files

improved script

Signed-off-by: Alexei Znamensky <russoz@cpan.org>
  • Loading branch information...
1 parent a524b45 commit 6d0b213132aaec0ff88f6e2d67acc9c125d1d233 @russoz committed Apr 20, 2012
Showing with 17 additions and 9 deletions.
  1. +17 −9 bin/was-xor-codec
View
26 bin/was-xor-codec
@@ -2,19 +2,27 @@
use MIME::Base64;
-my $orig = $ARGV[0];
+sub encode {
+ my @chars = unpack( 'C*', shift );
+ map { $_ ^= 0x5f } @chars;
+ my $res = pack( 'C*', @chars );
-if ( $orig =~ s/{xor}(.*)/$1/ ) {
- my $xor = decode_base64($orig);
+ return '{xor}' . encode_base64( $res, '' );
+}
+
+sub decode {
+ my $xor = decode_base64(shift);
my @chars = unpack( 'C*', $xor );
map { $_ ^= 0x5f } @chars;
- print pack( 'C*', @chars ) . "\n";
+ return pack( 'C*', @chars );
}
-else {
- my @chars = unpack( 'C*', $orig );
- map { $_ ^= 0x5f } @chars;
- my $res = pack( 'C*', @chars );
- print '{xor}' . encode_base64( $res, '' ) . "\n";
+my $orig = $ARGV[0];
+
+if ( $orig =~ s/{xor}(.*)/$1/ ) {
+ print decode($orig) . "\n";
+}
+else {
+ print encode( $orig ) . "\n";
}

0 comments on commit 6d0b213

Please sign in to comment.