SSamTure.net

워드프레스

PHP Encrypt Decrypt using Base64

Here are two methods to encrypt and decrypt using Base64. I forgot where I got this from but these 2 methods are pretty handy. Make sure you remember your key as your string will be encrypted and decrypted according to what you specify as key. Key is a string here.

Usage is as follows:
$encrypted = encrypt(”to encrypt string”, “chitgoks”);
$decrypted = decrypt($encrypted, “chitgoks”);

$decrypted will return to encrypt string.

function encrypt($string, $key) {
$result = ”;
for($i=0; $i<strlen($string); $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) {
$result = ”;
$string = base64_decode($string);

for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}

return $result;
}

아~왜 안되지…

암호화 복호화 다 출력했을 때는 잘 나오는데~

복호화한 값을 xmlrpc로 넘기면 자꾸 에러 난다ㅠㅠㅠㅠㅠㅠㅠ

이것만 해결하면 완성 되는데…

1 Comment

  1. twitter.com
    2015/12/06 at 05:43 · Reply

    The bounty on each rat is directly linked to
    how difficult they are to kill, which in turn is connected to the Security Status of
    the system they are located in. If you are looking for
    a game thats not all hack and slash, and more like an rpg player, then this is the game for
    you online. File sharing programs can sometimes download porn to your computer
    without your knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *