SHARE
TWEET

Untitled

a guest Jun 16th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def crypt(data, key):
  2.     """RC4 algorithm"""
  3.  
  4.     key = [ord(c) for c in key]  # or `key = key.encode()` for python3
  5.  
  6.     x = 0
  7.     box = list(range(256))
  8.     for i in range(256):
  9.         x = (x + int(box[i]) + int(key[i % len(key)])) % 256
  10.         box[i], box[x] = box[x], box[i]
  11.     x = y = 0
  12.     out = []
  13.     for char in data:
  14.         x = (x + 1) % 256
  15.         y = (y + box[x]) % 256
  16.         box[x], box[y] = box[y], box[x]
  17.         out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))
  18.  
  19.     return ''.join(out)
  20.  
  21.  
  22. key = 'mysecret'
  23. a = crypt("hello world!", key)
  24. print(a)
  25. b = crypt(a, key)
  26. print(b)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top