Guest User

Untitled

a guest
Dec 11th, 2013
830
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //GG to PAR converter by Rydian, based on GG documentation I've since lost. :(
  3.  
  4. //Just an example.  Do what you need to set $code as the GG code in that format.
  5. $code = "DF47-E76D";
  6. echo $code,"<br>";
  7. //Make it into an array so we can work on the individual digits easily.
  8. $code = str_split($code);
  9.  
  10. //GG hex values.
  11. $ggc1 = array("D","F","4","7","0","9","1","5","6","B","C","8","A","2","3","E");
  12. //Temporary place holders.
  13. $ggc2 = array("!","@","#","$","%","^","&","*","(",")",";","=","_","+","[","]");
  14. //Actual hex values.
  15. $hex = array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
  16. //Uses temporary holders to get past a common coding issue with string replacement via arrays.
  17. $code = str_replace($ggc1,$ggc2,$code);
  18. $code = str_replace($ggc2,$hex,$code);
  19. //Implode the array back to a normal string.
  20. $code = implode("",$code);
  21. echo $code,"<br>";
  22.  
  23. //Remove the hyphen.
  24. $code = str_replace("-","",$code);
  25. echo $code,"<br>";
  26.  
  27. //Separate the value from the address.
  28. $addr = substr($code,2,6);
  29. $value = substr($code,0,2);
  30. echo $addr," ($value)<br>";
  31.  
  32. //Convert the address into a binary string.
  33. $addr = base_convert($addr, 16, 2);
  34. echo $addr," ($value)<br>";
  35.  
  36. //Pad the address to 24 characters.
  37. $addr = str_pad($addr, 24, "0", STR_PAD_LEFT);
  38. echo $addr," ($value)<br>";
  39.  
  40. //Convert the string back into an array.
  41. $addr = str_split($addr);
  42. //Set each bit an assigned place.
  43. $trans = array("i","j","k","l","q","r","s","t","o","p","a","b","c","d","u","v","w","x","e","f","g","h","m","n");
  44. foreach ($addr as $key => $bit) {
  45.     $transb = $trans[$key];
  46.     $new[$transb] = $bit;
  47. }
  48. print_r($new);
  49. echo " ($value)<br>";
  50. //Rearrange the bits to put them in the proper order.
  51. ksort($new);
  52. print_r($new);
  53. echo " ($value)<br>";
  54.  
  55. //Implode the array back to a normal string.
  56. $new = implode("",$new);
  57. echo $new," ($value)<br>";
  58.  
  59. //Convert the binary back to hex, make sure it's uppercase for readability/compatibility.
  60. $new = strtoupper(base_convert($new, 2, 16));
  61. echo $new," ($value)<br>";
  62.  
  63. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×