|
|
|
This is the sample of encryption and decryption script that I made and I use it to randomly create an encrypted password.
usage:
| <?php
include('code.php');
$str="mypassword";
$enc=encrypt($re);
print "this is encrypted mypassword ".$enc."<br>";
print "this is decrypted mypassword ".decrypt($enc)."<br>";
?> | |
| <?php
$strcode=array('','0','1','2','3','4','5','6','7','8','9','a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n','N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y','z','Z',' ');
//a function that will split a string into an array chunked with $num lenght.
function strsplt($thetext,$num=1)
{
$arr=array();
while ($i<strlen($thetext))
{
$y=substr($thetext,$i,$num);
if (isset($y))
{
$arr[]=$y;
}
$i=$i+$num;
}
return $arr;
}
//a function that will locate a key of an array
function key_locator($code,$strcode)
{
while (list($key, $val) = each($strcode)) {
if ($val==$code)
{
$x=$key;
}
}
return $x;
}
//a function that will array the sum of key and the random number.
function add_random_key($thetext)
{
global $strcode;
$newcode=array();
$rnd=rand(1,intval(count($strcode))-2);
for ($i=0;$i<strlen($thetext);$i++)
{
$x=key_locator(substr($thetext,$i,1),$strcode);
$temp=$x+$rnd;
if($temp>intval(count($strcode)-1))
{
$temp=$temp-intval(count($strcode)-1);
}
$newcode[]=$temp;
$temp="";
}
$newcode[]=$rnd;
return $newcode;
}
//A function that will convert from key to value from an array
function convert_keyto_value($thetext)
{
global $strcode;
$a=add_random_key($thetext);
while (in_array(count($strcode)-1,$a)==true)
{
$a=add_random_key($thetext);
}
for ($i=0;$i<strlen($thetext)+1;$i++)
{
$output.=$strcode[$a[$i]];
}
return $output;
}
//A function that will remove the random value and back to original value
function derandomized($thetext)
{
global $strcode;;
$arr=strsplt($thetext,intval(strlen($thetext)-1));
for ($x=0;$x<strlen($thetext)-1;$x++)
{
$s=key_locator(substr($arr[0],$x,1),$strcode);
$t=key_locator($arr[1],$strcode);
$newcode=$s-$t;
if ($newcode<0)
{
$newcode=$newcode+intval(count($strcode)-1);
}
if ($newcode==0&&$s<>0)
{
$newcode=count($strcode)-1;
}
$output.=$strcode[$newcode];
}
return $output;
}
//A function that will randomly chunk a string then add them as one string.
function encrypt($thetext)
{
global $strcode;;
$nstr=strsplt($thetext,2);
for ($i=0;$i<count($nstr);$i++)
{
$output.=convert_keyto_value($nstr[$i]);
}
return $output;
}
//A function that will remove the random values from chunked string and regrouped
//them as original string.
function decrypt($thetext)
{
global $strcode;;
$nstr=strsplt($thetext,3);
for ($i=0;$i<count($nstr);$i++)
{
$output.=derandomized($nstr[$i]);
}
return $output;
}
?> | | |
|
| A damaged image generator (class) for validating text.
CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart Categories : PHP, PHP Classes, Security, GD image library, Security | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | MD5 secured login Categories : PHP, Java Script, Authentication, Security | | | Secure URL $_GET Categories : PHP, Data Validation, Security | | | Encoding data using PGP via PHP's proc_* functions Categories : Cryptography, Security, Email, PHP, PGP | | | Easily Grant Temporary SSH Access to yourself when in remote location Categories : PHP, Linux, Cron, Security | | | SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge
response login algorithms over an insecure connection. Categories : Algorithms, PHP, Security | | | A simple PHP login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page. Categories : PHP, Sessions, Security, Authentication | | | Human readable PHP password generator Categories : PHP, Security, Beginner Guides, Arrays | | | Form Security - Match A Value For Success Categories : PHP, Authentication, HTML and PHP, Sessions, Security | | | Random Password Generator Categories : PHP, Strings, Security | | | Distribute PHP Software Protected by a License Key. Categories : PHP, Cryptography, Security, Software | | | Antispoof - a class to help prevent people hi-jacking and misusing parts of a website Categories : PHP, PHP Classes, Security | | | Scramble Eggs - php class to scramble/encode Categories : PHP, PHP Classes, Security, Encryption | | | IP Blocking Categories : PHP, Security, HTTP | |
| | | | ROMEL CUZON wrote : 1146
The usage above that should be:
$enc=encrypt($str);
instead of
$enc=encrypt($re);
| | | | Sarah King wrote : 1153
I`ve been using that code for 6+ years and it`s been pretty good to date, have written it in a few languages.
The cool thing about it is that you can extend the character set, or restrict it as necessary, move them around and it still works. I hope it makes it much harder to decrypt.
| | | | ROMEL CUZON wrote : 1155
I made this code only first week of July 2004. Maybe you use another coding. It is hard to decrypt unless somebody knows the value and series of your code array, also if someone knows the number of strings chunked before it was randomized for encryption.
You can also set in the
function encrypt
$nstr=strsplt($thetext,1); and in
function decrypt
$nstr=strsplt($thetext,2);
or in the
function encrypt
$nstr=strsplt($thetext,4);
and in the
function decrypt
$nstr=strsplt($thetext,5);
whatever you want. You have only to remember that chunked lenght of function decrypt should be greater by 1 than the chunked lenght of function encrypt.
The lesser the chunked lenght, the longer the encrypted strings. The greater the chunked lenght, the shorter the encrypted strings. I hope this will help them make the code harder to decrypt.
| | | | ROMEL CUZON wrote :1358
In PHP5
Use function str_split()
instead of function strsplt() given above.
| |
|
|
|