Last active
May 4, 2018 07:46
-
-
Save AmirSbss/8369048f58f23a5f4e5275384822436d to your computer and use it in GitHub Desktop.
PHP encryption method
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 | |
/** | |
* @property string | |
*/ | |
function encr($raw) { | |
$encoded = ""; | |
$seprated = str_split(base64_encode($raw)); | |
$empty = []; | |
while (count($seprated) > 0) { | |
$encoded .= $seprated[0]; | |
unset($seprated[0]); | |
foreach($seprated as $i) { | |
$empty[] = $i; | |
} | |
$seprated = $empty; | |
$empty = []; | |
if (count($seprated) > 0) { | |
$encoded .= $seprated[count($seprated) - 1]; | |
unset($seprated[count($seprated) - 1]); | |
foreach($seprated as $i) { | |
$empty[] = $i; | |
} | |
$seprated = $empty; | |
$empty = []; | |
} | |
} | |
return $encoded; | |
} | |
function decr($encr) { | |
$seprated = str_split($encr); | |
$empty = []; | |
$index = 0; | |
$reverse = count($seprated) - 1; | |
foreach($seprated as $i=>$v) { | |
if ($i%2 == 0) { | |
$empty[$index] = $v; | |
$index++; | |
} else { | |
$empty[$reverse] = $v; | |
$reverse--; | |
} | |
} | |
ksort($empty); | |
$decoded = implode("", $empty); | |
return base64_decode($decoded); | |
} | |
$hello = encr("Hello!"); | |
echo $hello; | |
echo decr($hello); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment