Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved. 

2# 

3# This software is provided under under a slightly modified version 

4# of the Apache Software License. See the accompanying LICENSE file 

5# for more information. 

6# 

7# Description: 

8# IEEE 802.11 Network packet codecs. 

9# 

10# Author: 

11# Gustavo Moreira 

12 

13class RC4(): 

14 def __init__(self, key): 

15 bkey = bytearray(key) 

16 j = 0 

17 self.state = bytearray(range(256)) 

18 for i in range(256): 

19 j = (j + self.state[i] + bkey[i % len(key)]) & 0xff 

20 self.state[i],self.state[j] = self.state[j],self.state[i] # SSWAP(i,j) 

21 

22 def encrypt(self, data): 

23 i = j = 0 

24 out=bytearray() 

25 for char in bytearray(data): 

26 i = (i+1) & 0xff 

27 j = (j+self.state[i]) & 0xff 

28 self.state[i],self.state[j] = self.state[j],self.state[i] # SSWAP(i,j) 

29 out.append(char ^ self.state[(self.state[i] + self.state[j]) & 0xff]) 

30 

31 return bytes(out) 

32 

33 def decrypt(self, data): 

34 # It's symmetric 

35 return self.encrypt(data)