Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //GG to PAR converter by Rydian, based on GG documentation I've since lost. :(
- //Just an example. Do what you need to set $code as the GG code in that format.
- $code = "DF47-E76D";
- echo $code,"<br>";
- //Make it into an array so we can work on the individual digits easily.
- $code = str_split($code);
- //GG hex values.
- $ggc1 = array("D","F","4","7","0","9","1","5","6","B","C","8","A","2","3","E");
- //Temporary place holders.
- $ggc2 = array("!","@","#","$","%","^","&","*","(",")",";","=","_","+","[","]");
- //Actual hex values.
- $hex = array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
- //Uses temporary holders to get past a common coding issue with string replacement via arrays.
- $code = str_replace($ggc1,$ggc2,$code);
- $code = str_replace($ggc2,$hex,$code);
- //Implode the array back to a normal string.
- $code = implode("",$code);
- echo $code,"<br>";
- //Remove the hyphen.
- $code = str_replace("-","",$code);
- echo $code,"<br>";
- //Separate the value from the address.
- $addr = substr($code,2,6);
- $value = substr($code,0,2);
- echo $addr," ($value)<br>";
- //Convert the address into a binary string.
- $addr = base_convert($addr, 16, 2);
- echo $addr," ($value)<br>";
- //Pad the address to 24 characters.
- $addr = str_pad($addr, 24, "0", STR_PAD_LEFT);
- echo $addr," ($value)<br>";
- //Convert the string back into an array.
- $addr = str_split($addr);
- //Set each bit an assigned place.
- $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");
- foreach ($addr as $key => $bit) {
- $transb = $trans[$key];
- $new[$transb] = $bit;
- }
- print_r($new);
- echo " ($value)<br>";
- //Rearrange the bits to put them in the proper order.
- ksort($new);
- print_r($new);
- echo " ($value)<br>";
- //Implode the array back to a normal string.
- $new = implode("",$new);
- echo $new," ($value)<br>";
- //Convert the binary back to hex, make sure it's uppercase for readability/compatibility.
- $new = strtoupper(base_convert($new, 2, 16));
- echo $new," ($value)<br>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement