0xtv

rc4crypt

Apr 24th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. def rc4crypt(data, key):
  2.     x = 0
  3.     box = range(256)
  4.     for i in range(256):
  5.         x = (x + box[i] + ord(key[i % len(key)])) % 256
  6.         box[i], box[x] = box[x], box[i]
  7.     x = 0
  8.     y = 0
  9.     out = []
  10.     for char in data:
  11.         x = (x + 1) % 256
  12.         y = (y + box[x]) % 256
  13.         box[x], box[y] = box[y], box[x]
  14.         out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))
  15.    
  16.     return ''.join(out)
Add Comment
Please, Sign In to add comment