#!/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;
#clean leading shit off, then push onto words array
foreach $count(@input)
{
$input[$count] =~ s/\W/""/g;
$words[$count]=$input[$count];
}
#open and send all wordlist words to their own array
open(f, wordlist.txt);
@wordlist=;
close f;
#loop through each input word
foreach $word(@words)
{
#split into chars
@curWord=split(//, $word);
#loop through each wordlist word
foreach $curListWord(@wordlist)
{
$wordListCopy=$curListWord;
#split into chars
@curWordList=split(//, $curListWord);
#if they arent the same length, cant be same word
if ($#curWordList != $#curWord)
{
next;
}
for($i=0; $i<$#curWord; $i++)
{
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.=$words[$i];
}
$output=substr($output, 0, -1);
print $output . "\n";
}