Location: PHPKode > scripts > CodeBreak - Hidden Morse Code > codebreak-hidden-morse-code/codebreak.php
<?php
/********************************************************************************

    CodeBreak - Hidden Morse Code
    Version 1.1.4
    Copyright 2001-2008, Rudy Green[e]
    http://www.rudygreene.com/projects/codebreak/
    CodeBreak hides your secret message into a sentence that can be read using morse code as the key. After encoding your message, simply cover the upper or lower parts of the characters to reveal the hidden message.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

********************************************************************************/

// CONNECT TO THE DATABASE
include("functions.inc.php");
database_connect();

// FUNCTIONS FIRST
function encode_morse($morse, $cn)
{
    global $output_text;
    $result = mysql_query("SELECT words FROM dictionary WHERE code_" . $_POST["encode_method"] . " = '" . $morse . "'");
    if (($num_rows = mysql_num_rows($result)) != 0) {
        $output_text .= "<select name=\"" . $cn . "\">\n";
        while ($row = mysql_fetch_array($result)) {
            $output_text .= "  <option value=\"" . trim($row["words"]) . "\">" . trim($row["words"]) . "</option>\n";  // remove line breaks from string
        }
        $output_text .= "</select>\n";
    } else {
        $output_text .= $morse;  // if it can't find a word match, then just display original morse code
    }
}

function encode_single_dot()
{
    global $output_text;
    if ($_POST["encode_method"] == "upper") {
        $random_number = mt_rand(1, 4);
        if ($random_number == 1) {
            $output_text .= "A";
        } elseif ($random_number == 2) {
            $output_text .= "I";
        } elseif ($random_number == 3) {
            $output_text .= "J";
        } elseif ($random_number == 4) {
            $output_text .= "L";
        }
    } elseif ($_POST["encode_method"] == "lower") {
        $random_number = mt_rand(1, 6);
        if ($random_number == 1) {
            $output_text .= "F";
        } elseif ($random_number == 2) {
            $output_text .= "I";
        } elseif ($random_number == 3) {
            $output_text .= "P";
        } elseif ($random_number == 4) {
            $output_text .= "T";
        } elseif ($random_number == 5) {
            $output_text .= "V";
        } elseif ($random_number == 6) {
            $output_text .= "Y";
        }
    }
}

function encode_double_dot()
{
    global $output_text;
    if ($_POST["encode_method"] == "upper") {
        $random_number = mt_rand(1, 8);
        if ($random_number == 1) {
            $output_text .= "H";
        } elseif ($random_number == 2) {
            $output_text .= "K";
        } elseif ($random_number == 3) {
            $output_text .= "M";
        } elseif ($random_number == 4) {
            $output_text .= "N";
        } elseif ($random_number == 5) {
            $output_text .= "U";
        } elseif ($random_number == 6) {
            $output_text .= "V";
        } elseif ($random_number == 7) {
            $output_text .= "X";
        } elseif ($random_number == 8) {
            $output_text .= "Y";
        }
    } elseif ($_POST["encode_method"] == "lower") {
        $random_number = mt_rand(1, 7);
        if ($random_number == 1) {
            $output_text .= "A";
        } elseif ($random_number == 2) {
            $output_text .= "H";
        } elseif ($random_number == 3) {
            $output_text .= "K";
        } elseif ($random_number == 4) {
            $output_text .= "N";
        } elseif ($random_number == 5) {
            $output_text .= "R";
        } elseif ($random_number == 6) {
            $output_text .= "W";
        } elseif ($random_number == 7) {
            $output_text .= "X";
        }
    }
}

function encode_triple_dot()
{
    global $output_text;
    if ($_POST["encode_method"] == "upper") {
        $output_text .= "W";
    } elseif ($_POST["encode_method"] == "lower") {
        $output_text .= "M";
    }
}

function encode_dash()
{
    global $output_text;
    if ($_POST["encode_method"] == "upper") {
        $random_number = mt_rand(1, 4);
        if ($random_number == 1) {
            $output_text .= "E";
        } elseif ($random_number == 2) {
            $output_text .= "F";
        } elseif ($random_number == 3) {
            $output_text .= "T";
        } elseif ($random_number == 4) {
            $output_text .= "Z";
        }
    } elseif ($_POST["encode_method"] == "lower") {
        $random_number = mt_rand(1, 3);
        if ($random_number == 1) {
            $output_text .= "E";
        } elseif ($random_number == 2) {
            $output_text .= "L";
        } elseif ($random_number == 3) {
            $output_text .= "Z";
        }
    }
}

function encode_letter_space()
{
    global $output_text;
    if ($_POST["encode_method"] == "upper") {
        $random_number = mt_rand(1, 4);
        if ($random_number == 1) {
            $output_text .= "B";
        } elseif ($random_number == 2) {
            $output_text .= "D";
        } elseif ($random_number == 3) {
            $output_text .= "P";
        } elseif ($random_number == 4) {
            $output_text .= "R";
        }
    } elseif ($_POST["encode_method"] == "lower") {
        $random_number = mt_rand(1, 2);
        if ($random_number == 1) {
            $output_text .= "B";
        } elseif ($random_number == 2) {
            $output_text .= "D";
        }
    }
}

function encode_word_space()
{
    global $output_text;
    if ($_POST["encode_method"] == "upper") {
        $random_number = mt_rand(1, 5);
        if ($random_number == 1) {
            $output_text .= "C";
        } elseif ($random_number == 2) {
            $output_text .= "G";
        } elseif ($random_number == 3) {
            $output_text .= "O";
        } elseif ($random_number == 4) {
            $output_text .= "Q";
        } elseif ($random_number == 5) {
            $output_text .= "S";
        }
    } elseif ($_POST["encode_method"] == "lower") {
        $random_number = mt_rand(1, 7);
        if ($random_number == 1) {
            $output_text .= "C";
        } elseif ($random_number == 2) {
            $output_text .= "G";
        } elseif ($random_number == 3) {
            $output_text .= "J";
        } elseif ($random_number == 4) {
            $output_text .= "O";
        } elseif ($random_number == 5) {
            $output_text .= "Q";
        } elseif ($random_number == 6) {
            $output_text .= "S";
        } elseif ($random_number == 7) {
            $output_text .= "U";
        }
    }
}

$input_text = strtoupper(trim($_POST["input_text"]));

if (empty($input_text)) {
    $output_text = "*** ENTER SOME TEXT TO ENCODE ***";
} else {
    include(dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $_POST["process_method"] . "_" . $_POST["output_method"] . ".inc.php");
}
?>
<html>

<head>
  <title>CodeBreak - Hidden Morse Code</title>
</head>

<body>

<h2>CodeBreak - Hidden Morse Code</h2>

<form method="post" action="codebreak.php">
<table width="100%" border="0">
  <tr>
    <td width="50%" valign="top">
      <h3>Input</h3>
      <textarea name="input_text" rows="10" cols="40">
<?php echo(stripslashes($input_text)); ?></textarea><br>
      <select name="process_method">
        <option value="encode"<?php if ($_POST["process_method"] == "encode") echo(" selected"); ?>>Encode</option>
        <option value="decode"<?php if ($_POST["process_method"] == "decode") echo(" selected"); ?>>Decode</option>
      </select>
      <select name="encode_method">
        <option value="upper"<?php if ($_POST["encode_method"] == "upper") echo(" selected"); ?>>Upper</option>
        <option value="lower"<?php if ($_POST["encode_method"] == "lower") echo(" selected"); ?>>Lower</option>
      </select>
      <select name="output_method">
<?php if ($option_database): ?>
        <option value="database"<?php if ($_POST["output_method"] == "database") echo(" selected"); ?>>Database</option>
<?php endif; ?>
        <option value="text"<?php if ($_POST["output_method"] == "text") echo(" selected"); ?>>Text</option>
      </select>
      <input type="submit" value="Process Input">
    </td>
    <td width="50%" valign="top">
      <h3>Output</h3>
<?php if ($_POST["process_method"] == "encode" && $_POST["output_method"] == "database"): ?>
<?php echo($output_text); ?>
<?php else: ?>
      <textarea rows="10" cols="40" readonly>
<?php echo($output_text); ?></textarea><br>
<?php endif; ?>
    </td>
  </tr>
</table>
</form>
<?php
if ($_POST["action"] == "Select") {
    $working_text = implode(" ", array_slice($_POST, 4, -1));  // combine array items and remove unwanted variables
    $working_text = strtoupper($working_text);
    echo("\n<hr>\n");
    for ($cn = 0; $cn < strlen($working_text); $cn++) {
        $box_gothic = substr($working_text, $cn, 1);
        if (ereg("^[[:alnum:]]+$", $box_gothic)) {
            echo("<img src=\"box_gothic/" . $box_gothic . ".png\" height=\"50\">");
        } else {
            echo("&nbsp;\n");
        }
    }
    echo("\n<hr>\n");
    echo($working_text);
    echo("\n<hr>\n");
}
?>

<p><b>About CodeBreak:</b> CodeBreak hides your secret message into a sentence that can be read using morse code as the key. After encoding your message, simply cover the upper or lower parts of the characters to reveal the hidden message.</p>
<p><b>Encoding Instructions:</b> CodeBreak will only encode alpha-numerical and the following characters: space, period, comma, colon, question mark, apostrophe, hyphen. All other characters will be ignored. Upper and Lower choose if you want to hide the code on the top or bottom of each letter. The database option lets you match the results against a database of words to try and make the encoded message readable.</p>
<p><b>Decoding Instructions:</b> Change the method to 'Decode' and choose the options that the message was originally encoded in. Enter the code into the 'Input' box and click on 'Process'. The decoded message will appear in the 'Output' box.</p>

<p><i>Copyright &copy; 2001-<?php echo(date("Y")); ?> <a href="http://www.rudygreene.com/">Rudy Green[e]</a></i></p>

</body>

</html>
Return current item: CodeBreak - Hidden Morse Code