Skip to content

Instantly share code, notes, and snippets.

@Deozaan
Created July 17, 2017 22:29
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 Deozaan/e7271c9da23d0bdd199980e4c3db6e9f to your computer and use it in GitHub Desktop.
Save Deozaan/e7271c9da23d0bdd199980e4c3db6e9f to your computer and use it in GitHub Desktop.
Secret Decoder Ring (Felcode)
Felcode
by Deozaan and Allen
https://www.donationcoder.com/forum/index.php?topic=3283.0
::Sample Dictionary::
================
It just follows each key's placement as to row 1, 2 or 3 and what numbers it's between, can be done in your head by looking at the keyboard but that will slow you down :-p
12 23 34 45 56 67 78 89 90 0-
1 Q W E R T Y U I O P
2 A S D F G H J K L
3 Z X C V B N M
So Hello would be:
267 134 290 290 190
H E L L O
This example is unable to encode numbers and symbols, so the default dictionary uses "999" to represent a space, numbers start with two zeroes, and most other symbols are just repeated three times.
<?php
//error_reporting(2047);
ob_start();
$codeArray = createArray();
$makeDict = new configParse;
$dictArray = $makeDict->parseFile($_POST['dictionary']);
if (isset($_POST['input'])) {
if (isset($_POST['encrypt']) && strlen($_POST['input']) > 1500) {
$error = '<h3>Cannot encrypt more than 1,500 characters</h3>';
$output = $_POST['input'];
}
$output = encrypt($_POST['input'], $_POST['double']);
} else {
$output = '';
}
if (isset($_POST['dictionary'])) { $dictionary = $_POST['dictionary']; } else { $dictionary = ''; }
echo "<title>FelCode - Deozaan.com</title>";
echo "<h1>FelCode -- Felicia's Code</h1>\n";
if (isset($error)) { echo $error; }
echo "As discussed at <a href=\"http://www.donationcoder.com/Forums/bb/index.php?topic=3283.0\">DonationCoder.com</a>.<br /><br />\n";
echo "<form method='post' action=''>\n";
echo "<textarea name=\"input\" style=\"width:100%\" rows=\"5\" cols=\"72\""
. " width=\"90%\" wrap=\"virtual\">$output</textarea><br />";
echo "<input type=\"submit\" name=\"encrypt\" value=\"Encrypt\" />\n";
echo "<input type=\"submit\" name=\"decrypt\" value=\"Decrypt\" />\n";
echo "<input type=\"checkbox\" name=\"double\" value=\"1\"";
if ($_POST['double'] == 1) { echo " checked=\"yes\""; }
echo " />Double Encryption/Decryption\n";
//echo '<br />Define your own dictionary:<br />';
//echo "<textarea name=\"dictionary\" style=\"width:100%\" rows=\"15\" cols=\"72\""
// . " width=\"90%\" wrap=\"virtual\">$dictionary</textarea><br />";
echo "</form>\n";
ob_end_flush();
function createArray() {
$codeArray['0'] = '000';
$codeArray['1'] = '001';
$codeArray['2'] = '002';
$codeArray['3'] = '003';
$codeArray['4'] = '004';
$codeArray['5'] = '005';
$codeArray['6'] = '006';
$codeArray['7'] = '007';
$codeArray['8'] = '008';
$codeArray['9'] = '009';
$codeArray['q'] = 112;
$codeArray['w'] = 123;
$codeArray['e'] = 134;
$codeArray['r'] = 145;
$codeArray['t'] = 156;
$codeArray['y'] = 167;
$codeArray['u'] = 178;
$codeArray['i'] = 189;
$codeArray['o'] = 190;
$codeArray['p'] = '10-';
$codeArray['a'] = 212;
$codeArray['s'] = 223;
$codeArray['d'] = 234;
$codeArray['f'] = 245;
$codeArray['g'] = 256;
$codeArray['h'] = 267;
$codeArray['j'] = 278;
$codeArray['k'] = 289;
$codeArray['l'] = 290;
$codeArray['z'] = 312;
$codeArray['x'] = 323;
$codeArray['c'] = 334;
$codeArray['v'] = 345;
$codeArray['b'] = 356;
$codeArray['n'] = 367;
$codeArray['m'] = 378;
$codeArray['Q'] = 412;
$codeArray['W'] = 423;
$codeArray['E'] = 434;
$codeArray['R'] = 445;
$codeArray['T'] = 456;
$codeArray['Y'] = 467;
$codeArray['U'] = 478;
$codeArray['I'] = 489;
$codeArray['O'] = 490;
$codeArray['P'] = '40-';
$codeArray['A'] = 512;
$codeArray['S'] = 523;
$codeArray['D'] = 534;
$codeArray['F'] = 545;
$codeArray['G'] = 556;
$codeArray['H'] = 567;
$codeArray['J'] = 578;
$codeArray['K'] = 589;
$codeArray['L'] = 590;
$codeArray['Z'] = 612;
$codeArray['X'] = 623;
$codeArray['C'] = 634;
$codeArray['V'] = 645;
$codeArray['B'] = 656;
$codeArray['N'] = 667;
$codeArray['M'] = 678;
$codeArray[' '] = 999;
return $codeArray;
}
function encrypt($input, $double) {
$codeArray = createArray();
$len = 1;
$dec = 3;
if (isset($_POST['decrypt'])) {
$codeArray = array_flip($codeArray);
$len = 3;
$dec = 'true';
}
$output = '';
for ($i=0;$i<strlen($input);$i+=$len) { // access each character ($i) of $input one at a time
$phrase = substr($input, $i, $len);
if (isset($codeArray[$phrase])) {
$output .= $codeArray[$phrase];
} else {
if ($dec === 'true') {
if ($phrase{0} === $phrase{1} && $phrase{1} === $phrase{2}) {
$output .= $phrase{0};
} else {
$output .= $phrase;
}
} else {
for ($j=0;$j<$dec;$j++) {
$output .= $phrase;
}
}
}
}
if ($double == 1) {
$output = encrypt($output, 0);
}
return $output;
}
class configParse {
var $file;
var $data;
function parseFile($file) {
$this->file = explode("\n",$file);
foreach ( $this->file as $option ) {
if ( !preg_match('#^;#im',$option) && strlen(trim($option)) > 3 ) {
if ( preg_match('#^((?!;)[^= ]+) *= *(.+)#im',$option,$option) ) {
$this->data[trim($option[1])] = trim($option[2]);
}
}
}
return $this->data;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment