#!/usr/bin/perl open(FILE1,"/usr/dict/linux.words"); $words="|".join("|",)."|"; close(FILE1); $words=~s/[\n\r]//g; $words=~y/A-Z/a-z/; open(FILE1,"encrypted.txt"); $msg1=join(" ",); $msg1=~s/[\n|\r]//g; while($msg1=~s/ / /g){;} $msg1=~y/A-Z/a-z/; close(FILE1); $bestfit="0"; $bestmsg=""; # ====== CAESER SHIFT ====== print "ENCRYPTED:\n"; print $msg1."\n"; print "decrypting...\n"; for($i=0;$i<26;$i++){ $msg1=~y/a-zA-Z/b-zaB-ZA/; @testwords=split(' ',$msg1); $msgwords=@testwords; $msgrealwords=0; for $test(@testwords){ if(index($words,$test)>0){ $msgrealwords++; } } if($msgrealwords>$bestfit){ $bestfit=$msgrealwords; $bestmsg=$msg1; print "better fit: $msg1\n"; } } end: print "\nBEST FIT:\n"; print $bestmsg."\n"; open(FILE1,">plaintext.txt"); print FILE1 $bestmsg; close FILE1;