Obfuscation.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. declare(strict_types=1);
  3. namespace netico\Bones;
  4. /**
  5. * String obfuscation.
  6. *
  7. * ROT-13 + Zlib compression + base64 encoding.
  8. * See: https://stackoverflow.com/questions/2996049/how-to-compress-decompress-a-long-query-string-in-php.
  9. *
  10. * @package bones
  11. * @link https://git.lattuga.net/netico/code-library/src/master/Framework
  12. * @copyright Copyright (c) 2016, 2022 netico <netico@riseup.net>
  13. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License
  14. * @author netico <netico@riseup.net>
  15. *
  16. */
  17. class Obfuscation
  18. {
  19. /**
  20. * This is the method to obfuscate a string.
  21. *
  22. * @param string $str
  23. * @return string
  24. */
  25. public function obfuscate($str)
  26. {
  27. return rtrim(strtr(base64_encode(gzdeflate(str_rot13($str), 9)), '+/', '-_'), '=');
  28. }
  29. /**
  30. * This is the method to deobfuscate a string.
  31. *
  32. * @param string $str
  33. * @return string
  34. */
  35. public function deobfuscate($str)
  36. {
  37. return str_rot13(gzinflate(base64_decode(strtr($str, '-_', '+/'))));
  38. }
  39. }