Code to break Caesars Box encrpytion.
Useage:
Code:
tgo@localhost:~/perl$ perl cryp.pl HOUIY\!TO\!
HITOYOU!!
tgo@localhost:~/perl$ perl cryp.pl hoacfucdoowkach\?wdocwku?mwohoccluoduookacuccduwwhlhkclolwduihdo\!
howmuchwoodwouldawoodchuckchuckifawoodchuckcouldchuckwood??lawl!
tgo@localhost:~/perl$
The first loop finds the perfect square of the number and if it doesnt have one it prints a message and quits.
For the important part the outer loop loops from 0 to the perfect square. The inner loop goes through the string and grabs inner * perfect square + outer loop. So for instance if we had an easy one like abcdefghi and it just started the loops it would grab 0 * 3 + 0 and take that character which would be a. then it would grab 0 * 3 + 1 which would be d then 0 * 3 + 2 which would be g. and that would be the first row.
Code:
Code:
#!/usr/bin/perl
# Code to break Caesars Box encryption
# Coded by tgo
# http://www.anomalous-security.org
use warnings;
if (@ARGV != 1)
{
warn("Useage $0 <string>\n");
exit(1);
}
$string = $ARGV[0];
$length = length($string);
for ($x=1;$x<20;$x++)
{
$total = $x * $x;
if ($total == $length)
{
$num = $x;
last;
}
elsif ($total >= $length)
{
warn("The length of your string is a not a perfect square\n");
exit(1);
}
}
for ($y=0;$y<$num;$y++)
{
for($in=0;$in<$length-$num;$in++)
{
$spot = $in*$num+$y;
if ($spot > $length)
{
last;
}
if ($in == 0)
{
$curline = substr($string,$spot,1);
}
else
{
$curline .= substr($string,$spot,1);
}
}
print $curline;
}
print "\n";