Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement