Skip to content

Instantly share code, notes, and snippets.

@AmirSbss
Last active May 4, 2018 07:46
Show Gist options
  • Save AmirSbss/8369048f58f23a5f4e5275384822436d to your computer and use it in GitHub Desktop.
Save AmirSbss/8369048f58f23a5f4e5275384822436d to your computer and use it in GitHub Desktop.
PHP encryption method
<?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