Skip to content

Instantly share code, notes, and snippets.

@yushine
Forked from pwlin/gist:1248250
Created January 23, 2017 07:15
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 yushine/f15d421833275607de5dbcf0025c1ead to your computer and use it in GitHub Desktop.
Save yushine/f15d421833275607de5dbcf0025c1ead 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