Posted by Henk oegema on 04/22/07 09:51
Vince Morgan wrote:
> "Jeff North" <jnorthau@yahoo.com.au> wrote in message
> news:74nl23ttu07hshcis4b80ovkmasrbs7ijm@4ax.com...
>
>>
>> Not really :-)
>> I was trying to keep the code in a similar format to the OP :-)
>
> Yes, and that was much more considerate. Not to mention that it actualy
> worked too ;)
> Vince
I have put the three versions together with their output:
<?php
function encryptString($string)
{
for ($i=0;$i<strlen($string);$i++)
{
$chr = $string[$i];
if ($chr == "0")
{
$chr = "5";
$string{$i} = $chr;
}
elseif ($chr == "1")
{
$chr = "6";
$string[$i] = $chr;
}
elseif ($chr == "2")
{
$chr = "7";
$string[$i] = $chr;
}
elseif ($chr == "3")
{
$chr = "8";
$string[$i] = $chr;
}
elseif ($chr == "4")
{
$chr = "9";
$string[$i] = $chr;
}
elseif ($chr == "5")
{
$chr = "0";
$string[$i]= $chr;
}
elseif ($chr == "6")
{
$chr = "1";
$string[$i] = $chr;
}
elseif ($chr == "7")
{
$chr = "2";
$string[$i] = $chr;
}
elseif ($chr == "8")
{
$chr = "3";
$string[$i] = $chr;
}
elseif ($chr == "9")
{
$chr = "4";
$string[$i] = $chr;
}
}
return str_rot13($string);
}
// Set username and password
$username1 = encryptString('henkoegema');
$password1 = encryptString('php4script') ;
print($username1); //output="uraxbrtrzn"
print($password1); //output="cuc9fpevcg"
//==================================================
function encryptString2($string)
{
for($i=0; $i < strlen($string); $i++)
{
if(is_numeric($string[$i]<"5"))
{
$string[$i]= $string[$i]+ 5;
}else
{
$string[$i]= $string[$i]- 5;
}
}
return str_rot13($string);
}
// Set username and password
$username2 = encryptString2('henkoegema');
$password2 = encryptString2('php4script');
print($username2); //output="----------"
print($password2); //output="----------"
//===============================================
function encryptString3($string)
{
for($i=0; $i < strlen($string); $i++)
{
$chr=$string[$i];
switch($chr)
{
case "0":$string[$i]="5";break;
case "1":$string[$i]="6";break;
case "2":$string[$i]="7";break;
case "3":$string[$i]="8";break;
case "4":$string[$i]="9";break;
case "5":$string[$i]="0";break;
case "6":$string[$i]="1";break;
case "7":$string[$i]="2";break;
case "8":$string[$i]="3";break;
case "9":$string[$i]="4";break;
}
}
return str_rot13($string);
}
// Set username and password
$username3 = encryptString3('henkoegema');
$password3 = encryptString3('php4script');
print($username3); //output="uraxbrtrzn"
print($password3); //output="cuc9fpevcg"
print("End test");
//================================================
Rgds
Henk
Navigation:
[Reply to this message]
|