Pycrypto: l'Incrémentation de la CTR Mode

Ne peut toujours pas obtenir que cela fonctionne. Ma question est comment faire le décryptage de la ligne de travail. Voici ce que j'ai écrit:

class IVCounter(object):
    @staticmethod
    def incrIV(self):
        temp = hex(int(self, 16)+1)[2:34]
        return array.array('B', temp.decode("hex")).tostring()


def decryptCTR(key, ciphertext):

    iv = ciphertext[:32] #extracts the first 32 characters of the ciphertext

    #convert the key into a 16 byte string
    key = array.array('B', key.decode("hex")).tostring()

    print AES.new(key, AES.MODE_CTR, counter=IVCounter.incrIV(iv)).decrypt(ciphertext)
    return

Mon message d'erreur est:

ValueError: "compteur" paramètre doit être un objet appelable

Je ne peux pas comprendre comment le pycrypto veut de moi pour organiser cette troisième argument à nouveau.

Peut aider quelqu'un? Merci!

MODIFIER
Nouveau code après la mise en œuvre des suggestions ci-dessous. Toujours bloqué!

class IVCounter(object):
    def __init__(self, start=1L):
        print start #outputs the number 1 (not my IV as hoped)
        self.value = long(start)

   def __call__(self):
        print self.value  #outputs 1 - need this to be my iv in long int form
        print self.value + 1L  #outputs 2
        self.value += 1L
        return somehow_convert_this_to_a_bitstring(self.value) #to be written

def decryptCTR(key, ciphertext):

    iv = ciphertext[:32] #extracts the first 32 characters of the ciphertext
    iv = int(iv, 16)

    #convert the key into a 16 byte string
    key = array.array('B', key.decode("hex")).tostring()

    ctr = IVCounter()
    Crypto.Util.Counter.new(128, initial_value = iv)

    print AES.new(key, AES.MODE_CTR, counter=ctr).decrypt(ciphertext)
    return

MODIFIER ne peut TOUJOURS pas obtenir que cela fonctionne. très frustré et complètement à court d'idées. Voici le dernier code: (veuillez noter que mes chaînes d'entrée de 32 bits hex de chaînes de caractères qui doit être interprété de deux paires de chiffres pour convertir des entiers longs.)

class IVCounter(object):
    def __init__(self, start=1L):
        self.value = long(start)

    def __call__(self):
        self.value += 1L
        return hex(self.value)[2:34]

def decryptCTR(key, ciphertext):
    iv = ciphertext[:32] #extracts the first 32 characters of the ciphertext
    iv = array.array('B', iv.decode("hex")).tostring()

    ciphertext = ciphertext[32:]

    #convert the key into a 16 byte string
    key = array.array('B', key.decode("hex")).tostring()

    #ctr = IVCounter(long(iv))
    ctr = Crypto.Util.Counter.new(16, iv)

    print AES.new(key, AES.MODE_CTR, counter=ctr).decrypt(ciphertext)
    return

TypeError: CTR fonction de compteur de chaîne retournée pas de longueur de 16

OriginalL'auteur Alex | 2012-07-25