// FIP Cryptic Message Center
// (c) 2006, Free Internet Press
// http://freeinternetpress.com
// Reuse is welcome, keeping this header intact.
$version = "1.0.1"; // Don't change this.
$max_keys = 15; // This is how many possible encryptions you'll be allowing.
$cipher_mode = 'cfb';
$debug = "0"; // Set this to 1 if you want to see some extra information.
// force user to https site.
//$https = $_SERVER['HTTPS'];
//if (!$https){
// header("Location: https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
//};
// Include headers here to customize for your site, if you include this
// on a web page.
//
// require_once("mainfile.php");
// include_once("../header.php");
$msg_data = $_POST[msg_data];
// Encryption/Decryption
if ($_POST[mode] == "encrypt"){
$msg_data = base64_encode($msg_data); // protect the data from odd user input.
while($count < $max_keys){
$count++;
$this_alog = $_POST[alog][$count];
$this_key = $_POST[key][$count];
if ((strlen($this_alog) > 0 ) && (strlen($this_key) > 0)){
$msg_data = encrypt_message($this_alog, $this_key, $cipher_mode, $msg_data, $debug);
};
};
$msg_data = base64_encode($msg_data); // make the data so it can be displayed.
$msg_data = chunk_split($msg_data); // this breaks the lines up into something manageable.
}elseif($_POST[mode] == "decrypt"){
$msg_data = base64_decode($msg_data); // return to original binary mesage format.
$count = $max_keys;
while ($count > 0){
$this_alog = $_POST[alog][$count];
$this_key = $_POST[key][$count];
if ((strlen($this_alog) > 0 ) && (strlen($this_key) > 0)){
$msg_data = decrypt_message($this_alog, $this_key, $cipher_mode, $msg_data, $debug);
};
$count--;
};
$msg_data = base64_decode($msg_data); // return the data to original displayed form.
};
// **************************************************************************************** //
// These are our encryption functions
// **************************************************************************************** //
function encrypt_message($this_alog, $this_key, $this_mode, $curmsg, $debug){
// these don't work in anything but stream mode.
if (("$this_alog" == "wake") ||
("$this_alog" == "enigma") ||
("$this_alog" == "arcfour")){
$this_mode = "stream";
};
$cipher = mcrypt_module_open($this_alog, '', $this_mode, '');
// Make Initialization Vector. If different IV's are used in encryption and decryption,
// it will corrupt result.
// This isn't terribly important to keep secret.
$iv = str_pad($iv, mcrypt_get_iv_size($this_alog, $this_mode), "0");
// Adjust key for this cipher.
$key_size = mcrypt_get_key_size($this_alog, $this_mode);
$this_key = str_pad($this_key, $key_size, '0'); $this_key = substr($this_key, 0, $key_size);
if ("$debug" == "1"){
print "** Encrypting with $this_alog :: $this_mode
Key($key_size) '$this_key'
";
};
// Encrypt message
mcrypt_generic_init($cipher, $this_key, $iv);
$newmsg = mcrypt_generic($cipher, $curmsg);
mcrypt_generic_deinit($cipher);
if (
(strlen($newmsg)< 1) ||
($curmsg == $newmsg) ||
(md5($curmsg) == md5($newmsg))
){
print "
Failed to encrypt data with $this_alog :: $this_mode
";
}else{
$curmsg = trim($newmsg, "\0");
};
return($curmsg);
};
function decrypt_message($this_alog, $this_key, $this_mode, $curmsg, $debug){
// these don't work in anything but stream mode.
if (("$this_alog" == "wake") ||
("$this_alog" == "enigma") ||
("$this_alog" == "arcfour")){
$this_mode = "stream";
};
$cipher = mcrypt_module_open($this_alog, '', $this_mode, '');
// Make Initialization Vector. If different IV's are used in encryption and decryption,
// it will corrupt result.
// This isn't terribly important to keep secret.
$iv = str_pad($iv, mcrypt_get_iv_size($this_alog, $this_mode), "0");
// Adjust key for this cipher.
$key_size = mcrypt_get_key_size($this_alog, $this_mode);
$this_key = str_pad($this_key, $key_size, '0'); $this_key = substr($this_key, 0, $key_size);
if ("$debug" == "1"){
print "** Decrypting with $this_alog :: $this_mode
Key($key_size) '$this_key'
";
};
// Decrypt Message
mcrypt_generic_init($cipher, $this_key, $iv);
$newmsg = mdecrypt_generic($cipher, $curmsg);
mcrypt_generic_deinit($cipher);
if (
(strlen($newmsg)< 1) ||
($curmsg == $newmsg) ||
(md5($curmsg) == md5($newmsg))
){
print "
Failed to decrypt data with $this_alog :: $this_mode
";
}else{
$curmsg = trim($newmsg, "\0");
};
return($curmsg);
};
// Below is the HTML of the page, for the user to input the message, ciphers, and keys.
?>
|
CryptMsg :: Cryptic Message Center Version print $version; ?> SSL Cipher: print $_SERVER[SSL_CIPHER]; ?> |