use Modern::Perl; use Data::Dump qw/dump/; use Crypt::CBC; my $cipher = Crypt::CBC->new( -key => 'password', -cipher => 'Blowfish', -header => 'randomiv', ); my $ciphertext = $cipher->encrypt("This data is hush hush"); my $plaintext = $cipher->decrypt($ciphertext); say unpack("H*", $ciphertext); say $plaintext; |
=info Author: 523066680 Date: 2017-12-20 =cut use Modern::Perl; use Win32::Console; use Crypt::CBC; use File::Slurp; use Time::HiRes qw/sleep/; use IO::Handle; STDOUT->autoflush(1); our $IN=Win32::Console->new(STD_INPUT_HANDLE); our $OUT=Win32::Console->new(STD_OUTPUT_HANDLE); our $IN_DEFAULT = $IN->Mode(); $IN->Mode(ENABLE_MOUSE_INPUT); my $key = get_password(); cipher("encrypt", $key, __FILE__ , __FILE__ ."_enc.txt", ); cipher("decrypt", $key, __FILE__ ."_enc.txt" , __FILE__ ."_dec.txt", ); pause(); sub get_password { my @st; my $inp = ""; print "Password:"; while (1) { sleep 0.01; @st = $IN->Input(); next if ($#st < 0); if ( $st[0] == 1 and $st[1] == 1 ) { if ( chr($st[5]) =~ /[\x20-\x7e]/ ) { print "*"; $inp .= chr($st[5]) } elsif ( $st[5] == 27 ) { exit } elsif ( $st[5] == 13 ) { print "\n"; last } elsif ( $st[5] == 8 ) { backspace( \$inp ) } } } return $inp; } sub backspace { my $s_ref = shift; if ( length($$s_ref) > 0 ) { print "\b \b"; $$s_ref =~ s/.$//; } } sub pause { print "Press any key to continue ..."; my @st; while (1) { sleep 0.02; @st = $IN->Input(); next if ($#st < 0); exit if ( $st[0] == 1 and $st[1] == 1 ); } } sub cipher { my ($mode, $key, $src, $dst) = @_; say "${mode}ing"; my $cipher = Crypt::CBC->new( -key => $key, -cipher => 'Blowfish' ); my $stream = read_file( $src, binmode => ":raw" ); my $result = $cipher->$mode( $stream ); write_file( $dst, { binmode => ":raw" }, $result ); } |
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |