Gistrec

encode/decode string

Aug 24th, 2018
344
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. function strcode($str, $passw = "", $encode = true) {
  2.     if (!$encode) {
  3.         $str = base64_decode($str);
  4.     }
  5.     $salt = "Dn8*#2n!9j";
  6.     $len = strlen($str);
  7.     $gamma = '';
  8.     $n = $len>100 ? 8 : 2;
  9.     while (strlen($gamma) < $len) {
  10.         $gamma .= substr(pack('H*', sha1($passw.$gamma.$salt)), 0, $n);
  11.     }
  12.     $str = $str ^ $gamma;
  13.  
  14.     if ($encode) {
  15.         $str = base64_encode($str);
  16.     }
  17.     return $str;
  18. }
  19.  
  20. $txt = "test_string";
  21. $txt = strcode($txt, 'mypassword', true);
  22. echo $txt . PHP_EOL;
  23.  
  24. $txt = strcode($txt, 'mypassword', false);
  25. echo $txt;
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment