note 24946 deleted from ref.mcrypt by jmcastagnetto

From: Date: Fri, 13 Sep 2002 23:12:02 +0000
Subject: note 24946 deleted from ref.mcrypt by jmcastagnetto
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-36654@lists.php.net to get a copy of this message
If you have PROBLEMS WITH MCRYPT and you NEED STRONG ENCRYPTION, you can use my algorythm... A flipping array is used as the key; the default key will generate about 480 characters of 255 possibilities... You can say it's like a 3840 bits key with about 256^480 possibilities I hope you have enough time before hackers find your key... Enough spoken, here is your code [scrypt class, based on strongcrypt full class] : class scrypt { var $key; function gen_key ($pass, $level=30) { for ($i=0; $i<$level; $i++) $mymd[$i]=md5(substr($pass,($i%strlen($pass)),1)); for ($a=0; $a<32; $a++) for ($i=0; $i<$level; $i++) $key.=substr($mymd[$i],$a,1); $this->key=$key; } function enc ($text, $method=1) { # 1=encrypt, 0=decrypt if ($method==0) { $key=str_replace("3", "j", str_replace("2", "i", str_replace("1", "h", str_replace("0", "g", $key)))); $key=str_replace("7", "n", str_replace("6", "m", str_replace("5", "l", str_replace("4", "k", $key)))); $key=str_replace("b", "4", str_replace("a", "5", str_replace("9", "6", str_replace("8", "7", $key)))); $key=str_replace("f", "0", str_replace("e", "1", str_replace("d", "2", str_replace("c", "3", $key)))); $key=str_replace("j", "c", str_replace("i", "d", str_replace("h", "e", str_replace("g", "f", $key)))); $key=str_replace("n", "8", str_replace("m", "9", str_replace("l", "a", str_replace("k", "b", $key)))); $text=base64_decode($text); } for ($i=0; $i<strlen($key); $i=$i+2) $d[$i/2]=hexdec(substr($key,$i,2)); for ($i=0, $ntext=""; substr($text, $i, 1) !=""; $i++) $ntext.=chr((ord(substr($text, $i, 1))+$d[($i%strlen($key))])%255); if ($method==1) $ntext=base64_encode($ntext); return ($ntext); } } you can use it like this : $sc=new scrypt; $pass="my pass"; $text="woow, what a text"; $sc->genkey($pass); # send the pass to generate the key echo $sc->encrypt($text); # crypted text you can share in your mysql db or other echo $sc->encrypt($encrypted,0); # shows you the decrypted text in the var called $encrypted if you want to become the full strongcrypt class : class strongcrypt { function genkey ($pass) { for ($i=0; $i<30; $i++) $mymd[$i]=md5(substr($pass,($i%strlen($pass)),1)); for ($a=0; $a<32; $a++) { for ($i=0; $i<30; $i++) $key.=substr($mymd[$i],$a,1); if ($a%2==1 && $a<31) $key.="\n"; } return ($key); } function genpub ($key) { $key=str_replace("1", "h", str_replace("0", "g", $key)); $key=str_replace("3", "j", str_replace("2", "i", $key)); $key=str_replace("5", "l", str_replace("4", "k", $key)); $key=str_replace("7", "n", str_replace("6", "m", $key)); $key=str_replace("9", "6", str_replace("8", "7", $key)); $key=str_replace("b", "4", str_replace("a", "5", $key)); $key=str_replace("d", "2", str_replace("c", "3", $key)); $key=str_replace("f", "0", str_replace("e", "1", $key)); $key=str_replace("h", "e", str_replace("g", "f", $key)); $key=str_replace("j", "c", str_replace("i", "d", $key)); $key=str_replace("l", "a", str_replace("k", "b", $key)); $key=str_replace("n", "8", str_replace("m", "9", $key)); return ($key); } function encrypt($text, $key) { $key=str_replace("\n", "", $key); for ($i=0; $i<strlen($key); $i=$i+2) $d[$i/2]=hexdec(substr($key,$i,2)); for ($i=0, $ntext=""; substr($text, $i, 1) !=""; $i++) $ntext.=chr((ord(substr($text, $i, 1))+$d[($i%strlen($key))])%255); $ntext=base64_encode($ntext); return ($ntext); } function decrypt($text, $key) { $key=str_replace("\n", "", $key); $text=base64_decode($text); for ($i=0; $i<strlen($key); $i=$i+2) $d[$i/2]=hexdec(substr($key,$i,2)); for ($i=0, $ntext=""; substr($text, $i, 1) !=""; $i++) $ntext.=chr((ord(substr($text, $i, 1))+$d[($i%strlen($key))])%255); return ($ntext); } } If you need help, you can mail. If there is a better method, please mail me. TCK

« previous php.notes (#36654) next »