Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def crypt(data, key):
- """RC4 algorithm"""
- key = [ord(c) for c in key] # or `key = key.encode()` for python3
- x = 0
- box = list(range(256))
- for i in range(256):
- x = (x + int(box[i]) + int(key[i % len(key)])) % 256
- box[i], box[x] = box[x], box[i]
- x = 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)
- key = 'mysecret'
- a = crypt("hello world!", key)
- print(a)
- b = crypt(a, key)
- print(b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement