'Initialize AES with the given key and IV.
If counter_wraparound is set to True, the AES-CTR counter will
wraparound to 0 when it overflows.'

def __init__(self, key, iv, counter_wraparound=False):

    assert (len(key) == 16)
    assert (len(iv) == 16)
    self.ctr = Counter.new(128, initial_value=long(iv.encode('hex'), 16), allow_wraparound=counter_wraparound)
    self.cipher = AES.new(key, AES.MODE_CTR, counter=self.ctr)
