Skip to content

Instantly share code, notes, and snippets.

@pwlin
Last active June 21, 2024 17:40
Show Gist options
  • Save pwlin/1248250 to your computer and use it in GitHub Desktop.
Save pwlin/1248250 to your computer and use it in GitHub Desktop.
php custom encrypt/decrypt
<?php
function encrypt($string, $key='YOUR_SALT') {
$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='YOUR_SALT') {
$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;
}
?>
@giriannamalai
Copy link

Working Nice.
But If comment lines added and would be helpful...!

@nileshp9495
Copy link

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment