note 80702 added to function.mt-rand

From: Date: Tue, 29 Jan 2008 15:48:14 +0000
Subject: note 80702 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-135554@lists.php.net to get a copy of this message
Here is a simple encryption algorithm I made a few months ago. I was tired of MD5 because they have rainbow tables out that will crack most any MD5 pass. Along with SHA. So encryption algorithms are getting weaker all the time. So here is new one for people to try and crack. So far no one has told me they cracked it. I also use it to generate very random passwords or character segments. Below the function is the random string generator. I tested this algorithm with mt_rand over 10 million iterations without one duplicate string. So use it in good health! <?php // Hexi-decimal encryption function // Returns: 64 character encrypted string function HexCrypt($string = "", $salt = ""){ if(strlen(trim($string)) == 0){ $string = " "; } if(strlen(trim($salt)) == 0){ $salt = " "; } $string = $salt.$string.$salt; $lastchar = ""; $output = ""; $saltlength = "0x".dechex(strlen($salt)); while(strlen($output) < 64){ $firstchar = "0x".dechex(ord(substr($string, strlen($salt), 1))); for($i = 0; $i < strlen($string); $i++){ $strlength = "0x".dechex($output+$i+3); if(strlen($output) >= 64){ break(2); }elseif($lastchar == ""){ $lastchar = "0x".dechex(ord(substr($string, $i, 1))); }else{ $current = "0x".dechex(ord(substr($string, $i, 1))); $total = ($lastchar * $current) * ($firstchar * $saltlength); $output .= dechex($total); $lastchar = ""; } } if((strlen($string)%2) == 1){ $total = ($lastchar * $firstchar) * ($firstchar * $saltlength); $output .= dechex($total); } $string = $output; $output = ""; } if(strlen($output) != 0){ $output = substr($output, 0, 64); }else{ $output = substr($string, 0, 64); } return($output); } // Generates an 8 character random string $length = 8; $string = ""; for($i = 0; $i < 32; $i++){ $string .= mt_rand(0,9); } $start = mt_rand(0, (64-$length)); $salt = substr($string, mt_rand(0,20), 12); echo "Random String: ".substr(HexCrypt($string, $salt), $start, $length)."\n"; ?> ---- Server IP: 64.71.164.2 Probable Submitter: 199.222.128.249 ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- https://master.php.net/note/edit/80702 Del: integrated -- https://master.php.net/note/delete/80702/integrated Del: useless -- https://master.php.net/note/delete/80702/useless Del: bad code -- https://master.php.net/note/delete/80702/bad+code Del: spam -- https://master.php.net/note/delete/80702/spam Del: non-english -- https://master.php.net/note/delete/80702/non-english Del: in docs -- https://master.php.net/note/delete/80702/in+docs Del: other reasons-- https://master.php.net/note/delete/80702 Reject -- https://master.php.net/note/reject/80702 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135554) next »