#!/usr/bin/perl
##############
#Script to take words from input.txt and descramble them against wordlist.txt #
#@words - hold cleaned words #
#@wordlist - holds all wordlist words #
#@curWord - array of current @word elements chars #
#@curWordList - array of current wordlist word chars #
# ###########
#array to hold the input words
@words;
#array to hold the descrambled words
@descrambled;
#string for output
$output="";
open(input, "input.txt");
@input=;
close input;
#foreach $a(@input)
#{
# print "precleaned word:$a" . "\n";
#}
#clean leading shit off, then push onto words array
for($i=0; $i<10; $i++)
{
$input[$i] =~ tr/# \'//d;
$input[$i] =~ s/^\s+//;
$input[$i] =~ s/\s+$//;
$words[$i]=$input[$i];
print "input word:$words[$i]" . "\n";
}
#open and send all wordlist words to their own array
open(f, "wordlist.txt");
@truewordlist=;
close f;
@wordlist = grep (!/.*?\d+.*/, @truewordlist);
#loop through each input word
foreach $word(@words)
{
#split into chars
@curWord=split(//, $word);
foreach $letter(@curWord)
{
print "$letter ";
}
print "############\n";
#loop through each wordlist word
foreach $curListWord(@wordlist)
{
print "current word:" . $curListWord . "\n";
$wordListCopy=$curListWord;
#split into chars
@curWordList=split(//, $curListWord);
foreach $letter(@curWordList)
{
print $letter . " ";
}
print "\n";
#if they arent the same length, cant be same word
if ($#curWordList != $#curWord)
{
next;
}
for($i=0; $i<$#curWord; $i++)
{
#print "$curWord[$i]\n";
for($j=0; $j<$#curWordList; $j++)
{
if($curWord[$i] eq $curWordList[$j])
{
delete $curWord[$i];
delete $curWordList[$j];
break;
}
}
}
if($#curWord == 0)
{
push(@descrambled, $wordListCopy);
}
}
}
for($i=0; $i<10; $i++)
{
$output.=$descrambled[$i] . ",";
}
$output=substr($output, 0, -1);
print $output . "\n";