note 80702 deleted from function.mt-rand by felipe
| From: | felipe@php.net | Date: | Wed, 30 Jan 2008 23:55:22 +0000 |
| Subject: | note 80702 deleted from function.mt-rand by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-135634@lists.php.net to get a copy of this message | ||
Note Submitter: dmoree at coker dot edu
----
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";
?>