Created
December 16, 2013 16:54
-
-
Save mckabi/7990284 to your computer and use it in GitHub Desktop.
Rc4 python implement
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
def RC4crypt(data, key): | |
''' | |
http://en.wikipedia.org/wiki/RC4 | |
''' | |
box_range = 256 | |
box = range(box_range) | |
i = 0 | |
for j in range(box_range): | |
i = (i + box[j] + ord(key[j % len(key)])) % box_range | |
box[j], box[i] = box[i], box[j] | |
i = j = 0 | |
out = [] | |
for c in data: | |
i = (i + 1) % box_range | |
j = (j + box[i]) % box_range | |
box[i], box[j] = box[j], box[i] | |
out.append(chr(ord(c) ^ box[(box[i] + box[j]) % 256])) | |
return ''.join(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment