Created
May 6, 2024 23:04
-
-
Save VIRUXE/80a27dca1604ddc8d205416ace911914 to your computer and use it in GitHub Desktop.
SA-MP's GPCI function implementation in GO and PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/Renegade334/gpci-js/blob/master/src/index.ts | |
package main | |
import ( | |
"crypto/sha1" | |
"encoding/binary" | |
"encoding/hex" | |
"fmt" | |
"os/user" | |
"path/filepath" | |
"strings" | |
) | |
func GPCI(input string) string { | |
GPCI_SBOX := []byte{ | |
0, 4, 8, 12, 4, 5, 9, 13, 8, 9, 10, 14, 12, 13, 14, 15, | |
64, 68, 72, 76, 68, 69, 73, 77, 72, 73, 74, 78, 76, 77, 78, 79, | |
128, 132, 136, 140, 132, 133, 137, 141, 136, 137, 138, 142, 140, 141, 142, 143, | |
192, 196, 200, 204, 196, 197, 201, 205, 200, 201, 202, 206, 204, 205, 206, 207, | |
64, 68, 72, 76, 68, 69, 73, 77, 72, 73, 74, 78, 76, 77, 78, 79, | |
80, 84, 88, 92, 84, 85, 89, 93, 88, 89, 90, 94, 92, 93, 94, 95, | |
144, 148, 152, 156, 148, 149, 153, 157, 152, 153, 154, 158, 156, 157, 158, 159, | |
208, 212, 216, 220, 212, 213, 217, 221, 216, 217, 218, 222, 220, 221, 222, 223, | |
128, 132, 136, 140, 132, 133, 137, 141, 136, 137, 138, 142, 140, 141, 142, 143, | |
144, 148, 152, 156, 148, 149, 153, 157, 152, 153, 154, 158, 156, 157, 158, 159, | |
160, 164, 168, 172, 164, 165, 169, 173, 168, 169, 170, 174, 172, 173, 174, 175, | |
224, 228, 232, 236, 228, 229, 233, 237, 232, 233, 234, 238, 236, 237, 238, 239, | |
192, 196, 200, 204, 196, 197, 201, 205, 200, 201, 202, 206, 204, 205, 206, 207, | |
208, 212, 216, 220, 212, 213, 217, 221, 216, 217, 218, 222, 220, 221, 222, 223, | |
224, 228, 232, 236, 228, 229, 233, 237, 232, 233, 234, 238, 236, 237, 238, 239, | |
240, 244, 248, 252, 244, 245, 249, 253, 248, 249, 250, 254, 252, 253, 254, 255, | |
} | |
hash := sha1.Sum([]byte(input)) | |
swappedHash := make([]byte, 20) | |
for i := 0; i < 5; i++ { | |
binary.BigEndian.PutUint32(swappedHash[i*4:], binary.LittleEndian.Uint32(hash[i*4:])) | |
} | |
byteArray := make([]byte, 20) | |
for i := 0; i < len(swappedHash); i++ { | |
byteArray[i] = GPCI_SBOX[swappedHash[i]] | |
} | |
result := strings.TrimLeft(hex.EncodeToString(byteArray), "0") | |
return strings.ToUpper(result) | |
} | |
func main() { | |
usr, err := user.Current() | |
if err != nil { | |
panic(err) | |
} | |
GTASanAndreasUserFiles := filepath.Join(usr.HomeDir, "Documents", "GTA San Andreas User Files") | |
result := GPCI(GTASanAndreasUserFiles[4:]) | |
// fmt.Println("GTA San Andreas User Files Path:", GTASanAndreasUserFiles) | |
fmt.Println("Your GPCI hash is:", result) | |
fmt.Println("Press Enter to continue...") | |
fmt.Scanln() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://github.com/Renegade334/gpci-js/blob/master/src/index.ts | |
function GPCI($input) { | |
$GPCI_SBOX = [ | |
0, 4, 8, 12, 4, 5, 9, 13, 8, 9, 10, 14, 12, 13, 14, 15, | |
64, 68, 72, 76, 68, 69, 73, 77, 72, 73, 74, 78, 76, 77, 78, 79, | |
128, 132, 136, 140, 132, 133, 137, 141, 136, 137, 138, 142, 140, 141, 142, 143, | |
192, 196, 200, 204, 196, 197, 201, 205, 200, 201, 202, 206, 204, 205, 206, 207, | |
64, 68, 72, 76, 68, 69, 73, 77, 72, 73, 74, 78, 76, 77, 78, 79, | |
80, 84, 88, 92, 84, 85, 89, 93, 88, 89, 90, 94, 92, 93, 94, 95, | |
144, 148, 152, 156, 148, 149, 153, 157, 152, 153, 154, 158, 156, 157, 158, 159, | |
208, 212, 216, 220, 212, 213, 217, 221, 216, 217, 218, 222, 220, 221, 222, 223, | |
128, 132, 136, 140, 132, 133, 137, 141, 136, 137, 138, 142, 140, 141, 142, 143, | |
144, 148, 152, 156, 148, 149, 153, 157, 152, 153, 154, 158, 156, 157, 158, 159, | |
160, 164, 168, 172, 164, 165, 169, 173, 168, 169, 170, 174, 172, 173, 174, 175, | |
224, 228, 232, 236, 228, 229, 233, 237, 232, 233, 234, 238, 236, 237, 238, 239, | |
192, 196, 200, 204, 196, 197, 201, 205, 200, 201, 202, 206, 204, 205, 206, 207, | |
208, 212, 216, 220, 212, 213, 217, 221, 216, 217, 218, 222, 220, 221, 222, 223, | |
224, 228, 232, 236, 228, 229, 233, 237, 232, 233, 234, 238, 236, 237, 238, 239, | |
240, 244, 248, 252, 244, 245, 249, 253, 248, 249, 250, 254, 252, 253, 254, 255 | |
]; | |
$hash = sha1($input, true); | |
$swapped_hash = ''; | |
for ($i = 0; $i < strlen($hash); $i += 4) $swapped_hash .= strrev(substr($hash, $i, 4)); | |
$byte_array = ''; | |
for ($i = 0; $i < strlen($swapped_hash); $i++) $byte_array .= chr($GPCI_SBOX[ord($swapped_hash[$i])]); | |
$result = ltrim(bin2hex($byte_array), '0'); | |
return strtoupper($result); | |
} | |
$input = substr($_GET['input'], 4) ?? null; | |
$result = $input ? GPCI($input) : null; | |
$our_gpci = "94F988DEDE9DEE49EDCDACDFA5840CA45F48CEDC"; | |
echo "Input: $input<br>"; | |
echo "The GPCI hash for the input is: $result<br>"; | |
echo "Our GPCI: $our_gpci<br>"; | |
echo "Same? " . (($result === $our_gpci) ? 'true' : 'false'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment