Created
June 2, 2019 22:55
-
-
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)
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
#! /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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for python 3: box = list(range(256))