...

View Full Version : Encryption Cypher



Phil Jackson
07-22-2010, 08:03 AM
<?php

header('Content-Type: text/html; charset=utf-8');
function ACT_encrypt_cipher($str, $key){
if( is_string($str) && is_string($key) ) {
$str = mb_convert_encoding($str, 'HTML-ENTITIES', "UTF-8");
$sl = strlen($str); $kl = strlen($key);
$fk = str_split(str_repeat($key, ceil($sl/$kl)));
$es = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&;:[]<>!"$%^*_-=+.,/\\()@?\'`';
$ea = array( 'a' => array(), 'm' => array(), 'c' => array());
foreach( str_split( $es ) as $key => $char ) { $ea['a'][] = $key; $ea['m'][] = md5($char); $ea['c'][] = $char; }
$ns = '';
$sp = str_split($str);
foreach( $fk as $k => $_char ) {
if( ! isset( $sp[$k] ) ) { break; }
$cm = md5($sp[$k]);
if( in_array( $cm, $ea['m'] ) ) {
$kk = array_keys( $ea['m'], $cm );
if( in_array( md5($_char), $ea['m'] ) ) {
$sk = array_keys( $ea['m'], md5($_char) );
$n = $ea['a'][$kk[0]] - $ea['a'][$sk[0]];
if( $n < 0 )
$n = $n + (strlen($es));
$ns .= $es[$n];
}else
$ns .= $_char;
}else
$ns .= $_char;
}
return $ns;
}
}
function ACT_decrypt_cipher($str, $key){
if( is_string($str) && is_string($key) ) {
$str = mb_convert_encoding($str, 'HTML-ENTITIES', "UTF-8");
$sl = strlen($str); $kl = strlen($key);
$fk = str_split(str_repeat($key, ceil($sl/$kl)));
$es = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&;:[]<>!"$%^*_-=+.,/\\()@?\'`';
$ea = array( 'a' => array(), 'm' => array(), 'c' => array());
foreach( str_split( $es ) as $key => $char ) { $ea['a'][] = $key; $ea['m'][] = md5($char); $ea['c'][] = $char; }
$ns = '';
$sp = str_split($str);
foreach( $fk as $k => $_char ) {
if( ! isset( $sp[$k] ) ) { break; }
$cm = md5($sp[$k]);
if( in_array( $cm, $ea['m'] ) ) {
$kk = array_keys( $ea['m'], $cm );
if( in_array( md5($_char), $ea['m'] ) ) {
$sk = array_keys( $ea['m'], md5($_char) );
$n = $ea['a'][$kk[0]] + $ea['a'][$sk[0]];
if( $n > (strlen($es)-1) )
$n = $n - strlen($es);
$ns .= $es[$n];
}else
$ns .= $_char;
}else
$ns .= $_char;
}
return $ns;
}
}

$keyd = 's3cr3t';
$str = 'Me `and` my "email" [foo@example.co.uk], website (http://www.example.co.uk) went 4 a\ walk WHICH I might add cost \'0.00\' (or $0.00?).';
$en = ACT_encrypt_cipher($str, $keyd);
$de = ACT_decrypt_cipher($en, $keyd);

echo "<strong>String:</strong> $str<br />";
echo "<strong>Encrypted:</strong> " . htmlentities($en) . "<br />";
echo "<strong>Decrypted:</strong> $de";

?>


output:



String: Me `and` my "email" [foo@example.co.uk], website (http://www.example.co.uk) went 4 a\ walk WHICH I might add cost '0.00' (or $0.00?).

Encrypted: tM?"I(*G?)6!ZMj%Q/ZH&=W)]Mu%U@\M-*W7bS;&Hc_Jp,1*"Beb1@Tz+e4c8Mu%U@\M-*W7bS/$4*)1?MH";Ht%T,"\Eq&n">?)Q-+1?%L^"Kla1!>gm?2(*hX9?G>H,?Z!0?-I?][x

Decrypted: Me `and` my "email" [foo@example.co.uk], website (http://www.example.co.uk) went 4 a\ walk WHICH I might add cost '0.00' (or $0.00?).

saudzforum
09-01-2010, 05:58 AM
Very nice script.

Phil Jackson
09-18-2010, 10:55 PM
Cheers, I enjoyed writing it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum