A lot of people might find it useless but its something i made when i first started learning php.
Yes i know the code isn't that good. But i was learning back then.
Its a simple php implementation of a text cipher crypto that was from the time of the romans.
Hence the name of the cipher: Ceasar
How the cipher works is you have the standard alphabet and a number you call the key. For instance you take the number 3 to use that key for the cipher you move every character up the number of spaces in the alphabet table.
a -> d, b -> e, c -> f
And so on.
Its extremely simple source and simple form provided.
A lot of cryptology is based on this simple concept. And with that i don't mean the advanced cryptology(its moved beyond this). But for example the cipher text crypto's and things like base64 encoding.
Code:
<?php
$word = '';
$result = '';
$mod = 0;
if (isset($_POST['word']))
{
$word = $_POST['word'];
$savedWord = 'value=\''.$_POST['word'].'\'';
}
if (isset($_POST['mod']))
{
$mod = $_POST['mod'];
}
if (isset($_POST['action']) && $_POST['action'] == 'cipher')
{
$length = strlen($word);
while($mod > 26)
{
$mod = $mod-26;
}
for($i=0;$i<$length;$i++) {
$cclass = ord($word[$i]);
if($cclass > 64&& $cclass < 91) {
$cclass = $cclass + $mod;
if($cclass > 90) {
$cclass = $cclass-26;
}
}elseif($cclass > 96 && $cclass < 123) {
$cclass = $cclass + $mod;
if($cclass > 122) {
$cclass = $cclass-26;
}
}elseif($cclass == 32) {
$cclass = 32;
}else{
$cclass = 0;
}
$result .= chr($cclass);
}
}
elseif ($_POST['action'] == 'showall')
{
$length = strlen($word);
while($mod > 26)
{
$mod = $mod-26;
}
for($mod=0;$mod<26;$mod++){
if($mod < 10) {
$result .= 'Option 0'.$mod.': ';
}else{
$result .= 'Option '.$mod.': ';
}
for($i=0;$i<$length;$i++) {
$cclass = ord($word[$i]);
if($cclass > 64&& $cclass < 91) {
$cclass = $cclass + $mod;
if($cclass > 90) {
$cclass = $cclass-26;
}
}elseif($cclass > 96 && $cclass < 123) {
$cclass = $cclass + $mod;
if($cclass > 122) {
$cclass = $cclass-26;
}
}elseif($cclass == 32) {
$cclass = 32;
}else{
$cclass = 0;
}
$result .= chr($cclass);
}
$result .= '<br />';
}
}
?>
<html>
<head>
<title>Simple Ceasar script example</title>
</head>
<body>
<form action='<?PHP echo $PHP_SELF;?>' method='post'>
<input type='text' name='word' id='word' <?php echo $savedWord; ?> />Text<br />
<input type='text' name='mod' id='mod' maxlength='3' value='<?php echo $mod; ?>' />Mod = 1-26(+)<br />
<select name='action' id='action'>
<option value='cipher'>Ciphertext it!</option>
<option value='showall'>Show all ciphers possible</option>
</select>
<input type='submit' value='ciphertext it!' />
</form>
<p><?php echo $result; ?></p>
</body>
</html>
Its that easy. Only supports characters a-z both capital and non capital.