Skip to content

Instantly share code, notes, and snippets.

@SamMakesCode
Created July 30, 2021 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamMakesCode/6609a9bc6649c5f02a41560456dace28 to your computer and use it in GitHub Desktop.
Save SamMakesCode/6609a9bc6649c5f02a41560456dace28 to your computer and use it in GitHub Desktop.
<?php
/**
* @author CMDR SamMakesCode
*/
$phrase = "To the jewel that burns on the brow of the mother of galaxies! To the whisperer in witchspace, the siren of the deepest void! The parent's grief, the lover's woe, and the yearning of our vagabond hearts. To Raxxla!";
// Remove non-alpha characters
$phrase = str_replace(' ', '', $phrase);
$phrase = str_replace('!', '', $phrase);
$phrase = str_replace(',', '', $phrase);
$phrase = str_replace('.', '', $phrase);
$phrase = str_replace('\'', '', $phrase);
// The key we're using to find stuff
$key = 'raxxla';
// Start at position 0
$positionInToast = 0;
// Create an array to store the characters as we go
$characters = [];
// For each character in the key...
foreach (str_split($key) as $character) {
// Get the key's character number. E.g. a = 1, b = 2
$characterNumber = ord($character) - 96;
// Increase the position in the phrase
$positionInToast += $characterNumber;
//echo 'Position now ' . $positionInToast . "\n";
// Output the character's numerical value
echo $character . ' = ' . $characterNumber . "\n";
// Store the character we land on
$characters[] = str_split($phrase)[$positionInToast];
}
echo 'Result is: ' . implode('', $characters) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment