note 25187 added to ref.mcrypt

From: Date: Fri, 13 Sep 2002 14:41:39 +0000
Subject: note 25187 added to ref.mcrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-36633@lists.php.net to get a copy of this message
RELASE OF MY CODE Sorry, I normaly test all my codes but when I write for php.net, somtimes I change my code to make it easier to read. so don't worry if it doesn't work. there is just a little error. You must ignore the preview message and use the following one : <? $sc=new scrypt; $pass="my pass"; $text="woow, what a text"; $sc->gen_key($pass); # send the pass to generate the key $enc=$sc->enc($text); # crypted text you can share in your mysql db or other echo "Encrypted: ".$enc<br>Decrypted: "; echo $sc->enc($enc,0); # decrypt your text in the var called $enc 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); } } ?> Now it's ok. everything works. I think lot of people are searching here just for cool codes witch can be used in their sites, but if there is an interesting code witch don't work, they stop. SO DON'T BE A PHP TOURIST, try alone, as long as you need. For example, to search my first mysql request, i hacked my phpMyAdmin to find finally 10 lines of code and took about 6 hours. so you can correct a script and prevent the author but don't mail if there is just a ";" wrong. TCK -- http://www.php.net/manual/en/ref.mcrypt.php http://master.php.net/manage/user-notes.php?action=edit+25187 http://master.php.net/manage/user-notes.php?action=delete+25187 http://master.php.net/manage/user-notes.php?action=reject+25187

« previous php.notes (#36633) next »