Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created October 30, 2017 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/bd9bdd18fc707a96f8ac51edec17ad73 to your computer and use it in GitHub Desktop.
Save phpfiddle/bd9bdd18fc707a96f8ac51edec17ad73 to your computer and use it in GitHub Desktop.
[ Posted by Riaz Laskar ] riazxrazor encryption
<?php
$key = 2;//(int)rand(1,3);
function encode($str,$k)
{
$newstring = '';
foreach(range(0,strlen($str)-1) as $i)
{
$newstring .= chr(ord($str[$i])+$k);
}
return $newstring;
}
function decode($str,$key)
{
$newstring = '';
foreach(range(0,strlen($str)-1) as $i)
{
$newstring .= chr((int)ord($str[$i])-$key);
}
return $newstring;
}
$t = encode("winter",$key);
echo $t.'<br>';
echo $key.'<br>';
echo "decode : ". decode($t,$key);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment