<gh_stars>1-10
#!/usr/bin/env python3

import binascii

decrypt_key = '<KEY>'

failure_packet = b's \xb4;\xc6\x90\x0f\xd4\xf4k\xe1s\xc8\x81\xa53\xe8\xbei-\xed\xa2IZCd\x00\x00\x00\x12\x00P\xcb\x84\x9b\x11,(\xf4:\xa9>\x0f\xbc\xff'

state = [None] * 256
p = q = None

''' RC4 Key Scheduling Algorithm (KSA) '''
def setKey(key):
	global p, q, state
	state = [n for n in range(256)]
	p = q = j = 0
	for i in range(256):
		j = (j + state[i] + key[i % len(key)]) % 256
		state[i], state[j] = state[j], state[i]

''' RC4 Pseudo-Random Generation Algorithm (PRGA) '''
def byteGenerator():
	global p, q, state
	p = (p + 1) % 256
	q = (q + state[p]) % 256
	state[p], state[q] = state[q], state[p]
	return state[(state[p] + state[q]) % 256]

''' Encrypt input string returning a byte list '''
def encrypt(key, plaintext):
	pt = string_to_list(plaintext)
	ct = rc4(key, pt)
	return list_to_string(ct)

''' Decrypt input byte list returning a string '''
def decrypt(key, ciphertext):
	ct = string_to_list(ciphertext)
	pt = rc4(key, ct)
	return list_to_string(pt)

''' Convert a string into an int list '''
def string_to_list(input_srt):
	res = [ch for ch in binascii.unhexlify(input_srt)]
	return res

''' Convert an int list into a string '''
def list_to_string(lst):
	res = ''.join(["%0.2X" % el for el in lst])
	return res

''' Xor list of ints with output generated by RC4. Output list of ints '''
def rc4(key, ints):
	setKey(string_to_list(key))
	return [x ^ byteGenerator() for x in ints]

def main():
	print(failure_packet) #we receive raw hex from server
	yaz = bytes.hex(failure_packet) #we change the raw bytes to something comprehensible
	print(yaz)
	maz = decrypt(decrypt_key, yaz).encode('utf-8') #remove the encryption
	print(maz)
	taz = binascii.unhexlify(maz) #convert the data to something readable
	print(taz)
	gaz = encrypt(decrypt_key, maz) #re encrypt
	print(gaz)
	waz = bytes.fromhex(gaz) #convert it back to binary puke that the server understands
	print(waz)

if __name__ == '__main__':
	main()

#!/usr/bin/env python3

import binascii

decrypt_key = '<KEY>'

failure_packet = b's \xb4;\xc6\x90\x0f\xd4\xf4k\xe1s\xc8\x81\xa53\xe8\xbei-\xed\xa2IZCd\x00\x00\x00\x12\x00P\xcb\x84\x9b\x11,(\xf4:\xa9>\x0f\xbc\xff'

state = [None] * 256
p = q = None

''' RC4 Key Scheduling Algorithm (KSA) '''
def setKey(key):
	global p, q, state
	state = [n for n in range(256)]
	p = q = j = 0
	for i in range(256):
		j = (j + state[i] + key[i % len(key)]) % 256
		state[i], state[j] = state[j], state[i]

''' RC4 Pseudo-Random Generation Algorithm (PRGA) '''
def byteGenerator():
	global p, q, state
	p = (p + 1) % 256
	q = (q + state[p]) % 256
	state[p], state[q] = state[q], state[p]
	return state[(state[p] + state[q]) % 256]

''' Encrypt input string returning a byte list '''
def encrypt(key, plaintext):
	pt = string_to_list(plaintext)
	ct = rc4(key, pt)
	return list_to_string(ct)

''' Decrypt input byte list returning a string '''
def decrypt(key, ciphertext):
	ct = string_to_list(ciphertext)
	pt = rc4(key, ct)
	return list_to_string(pt)

''' Convert a string into an int list '''
def string_to_list(input_srt):
	res = [ch for ch in binascii.unhexlify(input_srt)]
	return res

''' Convert an int list into a string '''
def list_to_string(lst):
	res = ''.join(["%0.2X" % el for el in lst])
	return res

''' Xor list of ints with output generated by RC4. Output list of ints '''
def rc4(key, ints):
	setKey(string_to_list(key))
	return [x ^ byteGenerator() for x in ints]

def main():
	print(failure_packet) #we receive raw hex from server
	yaz = bytes.hex(failure_packet) #we change the raw bytes to something comprehensible
	print(yaz)
	maz = decrypt(decrypt_key, yaz).encode('utf-8') #remove the encryption
	print(maz)
	taz = binascii.unhexlify(maz) #convert the data to something readable
	print(taz)
	gaz = encrypt(decrypt_key, maz) #re encrypt
	print(gaz)
	waz = bytes.fromhex(gaz) #convert it back to binary puke that the server understands
	print(waz)

if __name__ == '__main__':
	main()
#!/usr/bin/env python3 RC4 Key Scheduling Algorithm (KSA) RC4 Pseudo-Random Generation Algorithm (PRGA) Encrypt input string returning a byte list Decrypt input byte list returning a string Convert a string into an int list Convert an int list into a string Xor list of ints with output generated by RC4. Output list of ints #we receive raw hex from server #we change the raw bytes to something comprehensible #remove the encryption #convert the data to something readable #re encrypt #convert it back to binary puke that the server understands