Coverage for /root/GitHubProjects/impacket/impacket/Dot11Crypto.py: 100%

# Coverage for /root/GitHubProjects/impacket/impacket/Dot11Crypto.py : 100%

## 19 statements

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# Impacket - Collection of Python classes for working with network protocols.

2#

3# SECUREAUTH LABS. Copyright (C) 2018 SecureAuth Corporation. All rights reserved.

4#

5# This software is provided under a slightly modified version

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

7# for more information.

8#

9# Description:

10# IEEE 802.11 Network packet codecs.

11#

12# Author:

13# Gustavo Moreira

14#

15

16 class RC4():

17 def __init__(self, key):

18 bkey = bytearray(key)

19 j = 0

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

21 for i in range(256):

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

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

24

25 def encrypt(self, data):

26 i = j = 0

27 out=bytearray()

28 for char in bytearray(data):

29 i = (i+1) & 0xff

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

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

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

33

34 return bytes(out)

35

36 def decrypt(self, data):

37 # It's symmetric

38 return self.encrypt(data)