2
I own the functions below:
function enCript($string, $key)
{
$result = '';
$test = "";
for($i=0; $i<strlen($string); $i++)
{
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$test[$char]= ord($char)+ord($keychar);
$result.=$char;
}
return urlencode(base64_encode($result));
}
function deCript($string, $key)
{
$result = '';
$string = base64_decode(urldecode($string));
for($i=0; $i<strlen($string); $i++)
{
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
example of use:
echo enCript('201910037', '7636846602');
returns:
Warning: Illegal string offset 'd' in $test[$char]= ord($char)+ord($keychar); Warning: Illegal string offset 'g' in $test[$char]= ord($char)+ord($keychar); Warning: Illegal string offset 'g' in $test[$char]= ord($char)+ord($keychar); Warning: Illegal string offset 'l' in $test[$char]= ord($char)+ord($keychar); Warning: Illegal string offset 'g' in $test[$char]= ord($char)+ord($keychar); Warning: Illegal string offset 'h' in $test[$char]= ord($char)+ord($keychar); Warning: Illegal string offset 'd' in $test[$char]= ord($char)+ord($keychar); Warning: Illegal string offset 'i' in $test[$char]= ord($char)+ord($keychar); Warning: Illegal string offset 'm' in $test[$char]= ord($char)+ord($keychar); ZGdnbGdoZGlt
and what is your doubt?
– user148170
explain to me why I use this crypt to formulate it for you
– user148170
Not directly related to your error, but anyway: if this is just an exercise, it’s okay to create your cryptographic algorithm. But if you’re going to use it in a real system to encrypt sensitive information, nay invent your own algorithm (read more about this here and here).
– hkotsubo