1# Author: Trevor Perrin 2# See the LICENSE file for legal information regarding use of this file. 3 4"""PyCrypto RC4 implementation.""" 5 6from .cryptomath import * 7from .rc4 import * 8 9if pycryptoLoaded: 10 import Crypto.Cipher.ARC4 11 12 def new(key): 13 return PyCrypto_RC4(key) 14 15 class PyCrypto_RC4(RC4): 16 17 def __init__(self, key): 18 RC4.__init__(self, key, "pycrypto") 19 key = bytes(key) 20 self.context = Crypto.Cipher.ARC4.new(key) 21 22 def encrypt(self, plaintext): 23 plaintext = bytes(plaintext) 24 return bytearray(self.context.encrypt(plaintext)) 25 26 def decrypt(self, ciphertext): 27 ciphertext = bytes(ciphertext) 28 return bytearray(self.context.decrypt(ciphertext))