Skip to content

Instantly share code, notes, and snippets.

@trietptm
Forked from OALabs/rc4.py
Created September 18, 2020 07:46
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 trietptm/f570bbc63e5da9126b2b0673c2fad886 to your computer and use it in GitHub Desktop.
Save trietptm/f570bbc63e5da9126b2b0673c2fad886 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