<?php

$plaintext 
stripslashes($_REQUEST["plaintext"]);
$cipheredtext stripslashes($_REQUEST["cipheredtext"]);

$keyword stripslashes($_REQUEST["keyword"]);

if(
$_REQUEST["action"] == "Encrypt")
        
$cipheredtext ascii_encrypt($plaintext);

if(
$_REQUEST["action"] == "Decrypt")
        
$plaintext ascii_decrypt($cipheredtext);

?>
<form method="post">
Your original message<br>
<textarea name="plaintext" cols="55" rows="6">
<?=$plaintext;?>
</textarea>
<br>
<input name="action" type="submit" value="Encrypt">
<br>
</form>

<br><br><br>

<form method="post">
Encrypted Message<br>
<textarea name="cipheredtext" cols="55" rows="6">
<?=$cipheredtext;?>
</textarea>
<br>
<input name="action" type="submit" value="Decrypt">
<br>
</form>

<?php

/*
   function str_split($string,$split_length=1){
       $count = strlen($string); 
       if($split_length < 1){
           return false; 
       } elseif($split_length > $count){
           return array($string);
       } else {
           $num = (int)ceil($count/$split_length); 
           $ret = array(); 
           for($i=0;$i<$num;$i++){ 
               $ret[] = substr($string,$i*$split_length,$split_length); 
           } 
           return $ret;
       }     
   }
*/


function ascii_decrypt($encryptedtext)
{
    
$encryptedtext str_replace(' '''$encryptedtext);
    
$encryptedtext str_replace("\n"''$encryptedtext);
    
$encryptedtext str_replace("\r"''$encryptedtext);

    
//$blockstack = explode(" ", $encryptedtext);
    
$blockstack str_split($encryptedtext8);
    
$plaintext "";
    while(list(
$key$val) = each($blockstack))
    {
        
$plaintext .= bin2ascii($val);
    }
    return 
$plaintext;
}

function 
ascii_encrypt($plaintext)
{
//echo $plaintext;
    
$plaintextlength strlen($plaintext);
//echo $plaintextlength;
    
for($x 0$x $plaintextlength$x++)
    {
//echo $x . "=";
//echo $plaintext[$x];
//echo "<br />";
        
$encryptedtext .= ascii2bin($plaintext[$x]);
        
$encryptedtext .= " ";
    }
    return 
$encryptedtext;
}

function 
ascii2bin($char)
{
    
$char decbin(ord($char));
    
$char str_pad($char8'0'STR_PAD_LEFT);
    return 
$char;
}

function 
bin2ascii($binary)
{
    
$char substr($binary$x8);
    
$char chr(bindec($char));
    return 
$char;
}



?>