Skip to content

Instantly share code, notes, and snippets.

@herrcore
Forked from OALabs/rc4.py
Created April 19, 2021 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herrcore/b53bb6485c7d765cc00595455c80b999 to your computer and use it in GitHub Desktop.
Save herrcore/b53bb6485c7d765cc00595455c80b999 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment