Skip to content

Instantly share code, notes, and snippets.

@circulosmeos
Created August 31, 2016 16:58
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 circulosmeos/dfdbbadcb45e810babfee31945ba0172 to your computer and use it in GitHub Desktop.
Save circulosmeos/dfdbbadcb45e810babfee31945ba0172 to your computer and use it in GitHub Desktop.
Perl script to test 'triops' against multiple test generated files
#!/usr/bin/perl -w
#
# test triops against multiple test generated files
# random generated files with specified $INCREMENT length
# are encrypted with multiple options, and then decrypted
# and this output compared with the original file.
# Process stops when reaching $LOOPS or an error :-o
# Adjustments: $LOOPS, $INCREMENT, $INITIAL_FILE
#
# https://github.com/circulosmeos/triops
# https://circulosmeos.wordpress.com/2015/05/18/triops-a-multiplatform-cmdline-encryption-tool-using-chacha20-keccak/
# http://wp.me/p2FmmK-9H
# by circulosmeos, 2015-2016.
#
use strict;
use POSIX;
#$ENV{PATH}.=':/opt/csw/gnu';
my $TRIOPS='triops';
$TRIOPS='./'.$TRIOPS if $^O!~/^mswin/i;
my $LOG_FILE='triopsv9.0.tests.log';
# .................................................
# initial file length
my $INITIAL_FILE=0;
my $LOOPS=100;
my $INCREMENT=
1;
#ceil(rand(1000000));
# .................................................
my $TEST=2;
my $EXT='.ooo';
my @metadata=('', 'head', 'tail');
my $method=3;
my ($command, $file, $out, @compare);
sub create_file;
sub execute;
open fLog, '>>', $LOG_FILE;
$out='.out';
$file=$INITIAL_FILE;
do {
create_file($file);
foreach my $m (1..2) {
# $file
execute("$TRIOPS -P password.txt -m $metadata[$m] -e $method -o $file$out $file"); # $file.out
execute("cp $file $file$out.2"); # $file.out.2
execute("$TRIOPS -P password.txt -m $metadata[$m] -e $method $file$out.2"); # $file.out.2
execute("$TRIOPS -P password.txt -d $file$out.2$EXT"); # $file.out.2
execute("$TRIOPS -P password.txt -d -o $file$out.3 $file$out$EXT");# $file.out.3
execute("$TRIOPS -P password.txt -d -o $file$out.4 $file$out$EXT");# $file.out.4
execute("cat $file | $TRIOPS -P password.txt -e $method -m head -O > $file$out.5$EXT"); # $file.out.5
execute("cat $file | $TRIOPS -P password.txt -e $method -m tail -O > $file$out.7$EXT"); # $file.out.7
execute("$TRIOPS -P password.txt -d -O $file$out$EXT > $file$out.6");# $file.out.6
execute("$TRIOPS -P password.txt -d -O $file$out.7$EXT > $file$out.8");# $file.out.8
execute("cat $file$out.5$EXT | $TRIOPS -P password.txt -d -o $file$out.7"); # $file.out.7
print fLog execute("md5sum $file*"), "\n";
@compare=();
push @compare, execute("md5sum $file");
push @compare, execute("md5sum $file$out.2");
push @compare, execute("md5sum $file$out.3");
push @compare, execute("md5sum $file$out.4");
push @compare, execute("md5sum $file$out.6");
push @compare, execute("md5sum $file$out.7");
push @compare, execute("md5sum $file$out.8");
if ($compare[0] ne $compare[1] ||
$compare[1] ne $compare[2] ||
$compare[2] ne $compare[3] ||
$compare[3] ne $compare[4] ||
$compare[4] ne $compare[5] ||
$compare[5] ne $compare[6]) {
die "error @ $file\n";
}
###print join(',', @compare); print "\n";
execute("rm ${file}.out*");
}
execute("rm $file");
$file+=$INCREMENT;
print fLog "\n";
# if (($file/$INCREMENT)%10==0) {
# $|=1 ; # output print buffer
# print "$file, ";
# }
} while ($file < $INITIAL_FILE+($LOOPS*$INCREMENT) || $INCREMENT==0);
sub create_file {
my $file=shift;
my $buffer;
foreach ( 0 .. ($file-1) ) {
$buffer.= chr(rand(256));
}
# without ':raw', in Windows 0xd is converted to 0xad
open fOut, '>:raw', $file;
print fOut $buffer if $file>0;
close fOut;
}
sub execute {
my $command = shift;
print $command, "\n" if $TEST>0;
if ($command =~ /^md5sum.+[^\*]$/ ) {
my $output=`$command`;
chomp $output;
$output=~s/^([^\s]+) .+/$1/;
print $output, "<<< \n" if $TEST==1;
return $output;
}
return if $TEST==1 && $command=~/^rm /;
return `$command`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment