Last active
May 24, 2022 06:15
-
-
Save Cvar1984/704a5719f41e69415bb7896e0e848b3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* XorEncrypt.php | |
* Copyright (c) 2021 Cvar1984 <[email protected]> | |
* | |
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
* Version 2, December 2004 | |
* | |
* Everyone is permitted to copy and distribute verbatim or modified | |
* copies of this license document, and changing it is allowed as long | |
* as the name is changed. | |
* | |
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
* | |
* 0. You just DO WHAT THE FUCK YOU WANT TO. | |
*/ | |
namespace Cvar1984\Utils; | |
class XorEncrypt | |
{ | |
public static function encrypt( | |
string $text, | |
string $key | |
) : string | |
{ | |
$textLen = strlen($text); | |
for($x = 0; $x < $textLen; $x++) { | |
$text[$x] = ($text[$x] ^ $key); | |
} | |
return $text; | |
} | |
public static function decrypt( | |
string $text, | |
string $key | |
) : string | |
{ | |
return self::encrypt($text, $key); | |
} | |
} | |
$enc = XorEncrypt::encrypt('hello world', true); | |
$dec = XorEncrypt::decrypt($enc, true); | |
echo 'enc: ', $enc, PHP_EOL, 'dec: ', $dec, PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment