Skip to content

Instantly share code, notes, and snippets.

@pwlin
Created September 28, 2011 15:36
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • 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=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;
}
?>
@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