Skip to content

Instantly share code, notes, and snippets.

@phpcodertop
Forked from pwlin/gist:1248250
Created February 4, 2018 00:56
Show Gist options
  • Save phpcodertop/9519f0b722b5fba5074a86d32b17e5e2 to your computer and use it in GitHub Desktop.
Save phpcodertop/9519f0b722b5fba5074a86d32b17e5e2 to your computer and use it in GitHub Desktop.
php custom encrypt/decrypt
<?php
function encrypt($string, $key=5) {
$result = '';
for($i=0, $k= strlen($string); $i<$k; $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result .= $char;
}
return base64_encode($result);
}
function decrypt($string, $key=5) {
$result = '';
$string = base64_decode($string);
for($i=0,$k=strlen($string); $i< $k ; $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment