Gistrec

encode/decode string

Aug 23rd, 2018
288
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. function randucode($txt) {
  4.     $x=56780; $out="";
  5.     for($i=0;$i<strlen($txt);$i++) {
  6.         $x=((($x*65539)+0) ^ 0x7FFFFFFF) & 0xFFFFFFFF;
  7.         $r=($x ^ ($x >> 16))& 0x3F;
  8.         $s=ord($txt[$i]);
  9.         if($s>=46 && $s<=127) {
  10.             $s=($s ^ $r);
  11.             if($s<46 or $s>=127) $s=($s ^ $r);
  12.         }
  13.         $out.=chr($s);
  14.     }
  15.     return $out;
  16. }
  17. function encode($txt) {
  18.     return str_replace(array("?","&","/","="),array("(",")","*",","),randucode($txt));
  19. }
  20. function decode($txt) {
  21.     return randucode(str_replace(array("(",")","*",","),array("?","&","/","="),$txt));
  22. }
  23.  
  24. $c=encode('/?id=12&link=http://example.com/?id=123&p=param');
  25.  
  26. var_dump(encode("/?id=12&link=http://example.com/?id=123&p=param"));
  27. var_dump(decode(encode("/?id=12&link=http://example.com/?id=123&p=param")));
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment