Skip to content

Instantly share code, notes, and snippets.

@OALabs
Created June 2, 2019 22:55
Show Gist options
  • Save OALabs/1b07f7ef90e19e77745cad4101af78e9 to your computer and use it in GitHub Desktop.
Save OALabs/1b07f7ef90e19e77745cad4101af78e9 to your computer and use it in GitHub Desktop.
RC4 Crypto Python Module (probably stolen from stack overflow but it's been so long I can't remember)
#! /usr/bin/env python
##########################################################################################
##
## RC4 Crypto
##
##########################################################################################
def rc4crypt(key, data):
x = 0
box = range(256)
for i in range(256):
x = (x + box[i] + ord(key[i % len(key)])) % 256
box[i], box[x] = box[x], box[i]
x = 0
y = 0
out = []
for char in data:
x = (x + 1) % 256
y = (y + box[x]) % 256
box[x], box[y] = box[y], box[x]
out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))
return ''.join(out)
@atanazy333
Copy link

for python 3: box = list(range(256))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment