#!/usr/local/bin/pyrperl -w use strict; use warnings; use Time::HiRes qw( gettimeofday ); my ( %Account ); # Where you keep persistent values my ( $plaintext ); # Text to be en/decrypted my ( $CLOG ); # Log information open ( $CLOG, ">", "./Cipherlogs" ) || Die_Rtn(" ! open-40 $!"); # my $len=length($Account{Cipher}); # Cipher must be 32 bytes in size # print $CLOG "Cipher: |$len|$Account{Cipher}|\n"; # print $CLOG "$value ",length($plaintext),$plaintext,"\n"; # Shows what the text looks like # my $cipher = GetCipher( $Account{Cipher} ); # $Account{Cipher} is saved seed for the cipher my $seed = ""; my $stime = gettimeofday; for ( 1..32 ) { $seed .= chr(rand(255)); } print length($seed),"\t$seed\n"; my $cipher = GetCipher( $seed ); # Must get the cipher from the saved $seed print $CLOG " Loop Time Size of text Total calls\n"; # If you want to verify it's doing work! my ( $no, $value, $total ) = ( 1, 0, 0 ); if ( $cipher ) { while ( 1 ) { my $plaintext = chr($value) x $no; # this is the text to be encrypted my $encrypted = Encrypt( $cipher, $plaintext ); my $decrypted = Decrypt( $cipher, $encrypted ); if ( $decrypted ne $plaintext ) { print "NoGood! |$decrypted|$plaintext|\n"; } $value++; $total++; if ( $value > 255 ) { $stime = gettimeofday - $stime; print $CLOG "$stime \t$no \t\t$total\n"; # If you want to verify it's doing work! $value = 0; $no++; if ( $no > 2**16 ) { last; } $stime = gettimeofday; } } } exit; # Optional ## my $cipher = GetCipher( $key ); sub GetCipher { require Crypt::OpenSSL::AES; my $key = shift; if ( length($key) != 32 ) { return 0; } my $cipher = new Crypt::OpenSSL::AES($key); return $cipher; } ## my $encrypt = Encrypt( $cipher, $data ); sub Encrypt { require Crypt::OpenSSL::AES; my ( $cipher, $data ) = @_; my $encrypted = ""; my $len = length($data); $data = pack("N",$len) . $data; $len = length($data) % 16; if ( $len ) { $data .= "\0" x ( 16 - $len ); } while ( $data ) { $encrypted .= $cipher->encrypt(substr($data,0,16,"") ); } return $encrypted; } ## my $decrypt = Decrypt( $cipher, $encrypted ); sub Decrypt { require Crypt::OpenSSL::AES; my ( $cipher, $encrypted ) = @_; my $decrypted = ""; while ( $encrypted ) { $decrypted .= $cipher->decrypt(substr($encrypted,0,16,"") ); } my $len = unpack("N", substr($decrypted,0,4,"") ); return substr($decrypted,0,$len); } 1; __END__