コード例 #1
0
ファイル: wep.py プロジェクト: neopack1/plugin.video.nrl-live
 def __init__(self, key=None, keyId=None):
     """ key -> octet string for key """
     self.name        = 'WEP'
     self.strength    = None # depends on keySize
     self.arc4 = ARC4()       # base algorithm
     self.__key = [None,None,None,None]  # four possible keys, initialize to invalid keys
     self.encryptHeaderSize = 4
     self.setCurrentKeyId(keyId)
     if key != None:
         self.setKey(key)
コード例 #2
0
 def __init__(self, key=None, transmitterAddress=None, keyID=None):
     """ Initialize TKIP_encr, key -> octet string for key """
     assert(keyID == 0 or keyID == None), 'keyID should be zero in TKIP'
     self.keyId = 0
     self.name = 'TKIP_encr'
     self.strength = 128
     self.encryptHeaderSize = 8        # used to skip octets on decrypt
     self.arc4 = ARC4()                # base algorithm
     self.keyMixer = TKIP_Mixer(key, transmitterAddress)
     if key != None:                   # normally in base init, uses adjusted keySize
         self.setKey(key)
     if transmitterAddress != None:
         self.setTA(transmitterAddress)
コード例 #3
0
        def ARC4testVector(testCase, plainText, key, cipherText):
            """ Process ARC4 test vectors from RFCxxxx"""
            print '%s %s %s' % ('=' *
                                ((54 - len(testCase)) / 2), testCase, '=' *
                                ((54 - len(testCase)) / 2))
            # Convert from octet lists to string
            pt = ''.join([chr(i) for i in plainText])
            key = ''.join([chr(i) for i in key])
            kct = ''.join([chr(i) for i in cipherText])

            alg = ARC4(key)

            print 'key:    %s' % b2a_p(key)[9:]
            print 'pt:     %s' % b2a_p(pt)[9:]
            ct = alg.encrypt(pt)
            print 'ct:     %s' % b2a_p(ct)[9:]
            print 'kct:    %s' % b2a_p(kct)[9:]
            print '========================================================'
            self.assertEqual(ct, kct)
            alg.setKey(key)
            dct = alg.decrypt(ct)
            self.assertEqual(dct, pt)