Skip to content

Instantly share code, notes, and snippets.

Created August 17, 2015 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fa32c24a0d01f26b3922 to your computer and use it in GitHub Desktop.
Save anonymous/fa32c24a0d01f26b3922 to your computer and use it in GitHub Desktop.
echo 'foobar' | perl sccrypt.pl
echo 'foobar' | perl sccrypt.pl | perl scdecrypt.pl
use warnings;
use strict;
use MIME::Base64 qw(encode_base64);
my @stream = split //, do { local $/; <> };
my @rand = map { int rand 99 } (1) x 5;
my $out = '';
my $i = 0;
my @encrypted;
while ( $i < @stream ) {
push @encrypted, unpack( 'C', $stream[$i] ) ^ $rand[ $i++ % @rand ];
}
print encode_base64( pack( 'I5C*', @rand, @encrypted ) );
use warnings;
use strict;
use MIME::Base64 qw(decode_base64);
my $in = do { local $/; <> };
my ( @rand, @encrypted );
( @rand[ 0 .. 4 ], @encrypted ) = unpack( 'I5C*', decode_base64($in) );
my $i = 0;
my @decrypted;
while ( $i < @encrypted ) {
push @decrypted, pack( 'C', $encrypted[$i] ^ $rand[ $i++ % @rand ] );
}
print join '', @decrypted;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment