Created
October 5, 2021 05:28
-
-
Save InvoxiPlayGames/6e6c2275f1494eb6cf2656b1bdc60794 to your computer and use it in GitHub Desktop.
crappy implementation of gamespy's rc4 challenge algorithm in NodeJS
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
/* | |
crappy implementation of gamespy's rc4 challenge algorithm in NodeJS | |
basically just eyed from https://github.com/barronwaffles/dwc_network_server_emulator/blob/master/gamespy/gs_utility.py | |
strkey = String of "secret key" used by client | |
data = Buffer of challenge data sent by server | |
return value = String of base64 encoded challenge response | |
i only tested this once, it could probably be improved, idk if it works 100% | |
*/ | |
function gamespyChallengeRC4(strkey, data) { | |
key = Buffer.from(strkey); | |
var S = Array.from(Array(0x100).keys()); | |
var j = 0; | |
var i = 0; | |
for (i = 0; i < 0x100; i++) { | |
j = (j + S[i] + key[i % key.length]) & 0xff; | |
var si = S[i]; | |
var sj = S[j]; | |
S[i] = sj; | |
S[j] = si; | |
} | |
i = 0; | |
j = 0; | |
for (var h = 0; h < data.length; h++) { | |
val = data[h]; | |
i = (i + 1 + val) & 0xff; | |
j = (j + S[i]) & 0xff; | |
var si = S[i]; | |
var sj = S[j]; | |
S[i] = sj; | |
S[j] = si; | |
data[h] ^= S[(S[i] + S[j]) & 0xff]; | |
} | |
data[data.length - 1] = 0x00; // hacky idk | |
return data.toString("base64"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment