Created
October 30, 2017 13:21
-
-
Save phpfiddle/bd9bdd18fc707a96f8ac51edec17ad73 to your computer and use it in GitHub Desktop.
[ Posted by Riaz Laskar ] riazxrazor encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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