Skip to content

Instantly share code, notes, and snippets.

@heihachi
Last active January 18, 2016 07:41
Show Gist options
  • Save heihachi/63054396b8de4eed31e5 to your computer and use it in GitHub Desktop.
Save heihachi/63054396b8de4eed31e5 to your computer and use it in GitHub Desktop.
<?php
/* Program: Fallout 4 Terminal Guesser
* Purpose: This is for testing algorithms
* Programmer: Heihachi
*/
class FOTG
{
// Used https://www.youtube.com/watch?v=Sa4RUpXgzT4 for the terminal passwords and attempts.
private $words = array('shot', 'hurt', 'sell', 'give', 'sure', 'gear', 'sent', 'fire', 'glow', 'week', 'ones', 'sick');
private $attempt = array('sure'=>'1', 'sent'=>'2');
public function check()
{
// count our matching
$correct = 0;
foreach($this->attempt as $word=>$alike)
{
echo "Trying ".$word." with likeness of ".$alike."\n";
if($alike > 0)
{
foreach($this->words as $wordbase)
{
if($word != $wordbase)
{
for($i=0;$i<strlen($word);$i++)
{
if($word[$i] == $wordbase[$i])
{
//set a int to how many we got correct if doesnt contain the right letters we will pop
$correct++;
}
}
}
if($correct != $alike) // no matches so remove
{
if(($key = array_search($wordbase, $this->words)) !== false)
{
unset($this->words[$key]);
}
}
$correct = 0;
}
}
}
}
public function output()
{
echo "Last attempt!\nWe have these words left that match the likeness of past attempts.\n".implode(', ',$this->words)."\nGood Luck!\n";
}
/* Example of our structure for hints
* string[1]['s'] = 'shot, etc'
* ['g'] = 'give, etc'
* string[2]['e'] = 'gear, etc'
* ['u'] = 'hurt, etc'
*/
public function findCOmmon()
{
echo "* We will attempt to find the mostlikely password. *\n";
echo "* This will check each word for other words that *\n";
echo "* share similar letters. This should help find the *\n";
echo "* correct password or one that will help use. *\n";
$common = array();
foreach($this->words as $word)
{
for($i=0;$i<strlen($word);$i++)
{
//echo $word."|".$i."\n";
if(!isset($common[$i][$word[$i]]))
{
//if(!is_array($common[$i][$word[$i]]))
$common[$i][$word[$i]] = array();
}
array_push($common[$i][$word[$i]],$word);
}
}
$newWords = array();
foreach($this->words as $word)
{
$newWords[$word] = 0;
}
$total = 0;
foreach($common as $index)
{
foreach($index as $char=>$list)
{
$similar = count($list);
$total += $similar;
foreach($list as $index=>$needle)
{
$newWords[$needle] = $newWords[$needle]+$similar;
}
}
}
arsort($newWords);
foreach($newWords as $word=>$percentage)
{
$percentage = ($percentage * 100) / $total;
$percentage = round($percentage, 2);
$newWords[$word] = $percentage;
echo $word." | ".$percentage."%\n";
}
}
}
$f = new FOTG();
$f->findCOmmon();
$f->check();
$f->output();
/*
* * Result:
* * We will attempt to find the mostlikely password. *
* * This will check each word for other words that *
* * share similar letters. This should help find the *
* * correct password or one that will help use. *
* sure | 27.08%
* sent | 27.08%
* shot | 22.92%
* sell | 22.92%
* sick | 22.92%
* fire | 20.83%
* give | 20.83%
* week | 18.75%
* gear | 18.75%
* hurt | 18.75%
* glow | 14.58%
* ones | 10.42%
* Trying sure with likeness of 1
* Trying sent with likeness of 2
* Last attempt!
* We have these words left that match the likeness of past attempts.
* shot, sell
* Good Luck!
*
* shot is the correct password.
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment