#!/perl/bin/perl # title: Vigenere Pattern Grokker # author: Matt Rankin # purpose: To detect recurring patterns in a Vigenere ciphertext. # details: takes a file as an input, and some optional parameters to control what the program looks for and outputs. # usage: vpg 'filename' [size] [cutoff] open(F,$ARGV[0]) or die("Epic I/O fail!\n"); # take command line params, otherwise use default values of 2 and 5 my $size=(defined $ARGV[1])?$ARGV[1]:2; my $cutoff=(defined $ARGV[2])?$ARGV[2]:5; my $cipher; # pwn newlines while(my $line=){ chomp($line); $cipher.=$line; } close(F); my $l=length($cipher); my %pattern; for(my $i=0;$i<$l;$i++){ my $seq=substr($cipher,$i,$size); $pattern{$seq}++; } # sort key-value pairs into descending order on value # (i'd be lying if i claimed to know exactly how this works, such is Perl...) my @key=sort{$pattern{$b} <=> $pattern{$a}}keys(%pattern); my @val=sort{$b <=> $a}values(%pattern); my @pairs; for(my $i=0;$i1); print($seq[$i]-$seq[$i-1]); } print(")\n"); }