def TX(self):
     try:
         if self.rand:
             self.random_data_generator()
         else:
             self.bin_file_data_extractor()
         
         SAMPLES=int(self.samples_textctrl.GetValue())
         self.progress_bar.SetRange(SAMPLES)
         
         #Check Sample Rate mode and calculate Sleep in seconds
         sample_rate=self.sample_rate_textctrl.GetValue()
         if sample_rate in ['0','']:
             sample_rate=1
             self.sample_rate_textctrl.SetValue('1')
         else:
             sample_rate=float(sample_rate)
         choice=self.sample_rate_rb.GetStringSelection()
         if choice=='[Hz]':
             SLEEP=1.0/float(sample_rate)
         else:
             SLEEP=float(sample_rate)
         
         choice=self.addressing_type_rb.GetStringSelection()
         if choice.startswith('XBee'):
             #PAN Change
             #self.ser.Open()
             PAN = self.pan_id_textctrl.GetValue()
             frame_data="0801"+hexlify("ID")+PAN
             length = self.length_calc(frame_data)
             check_sum = self.check_sum_calc(frame_data)
             command="7E" + length + frame_data + check_sum
             self.ser.write(unhexlify(command))
             #response=hexlify(self.ser.readall())
             
             #Encryption Disable (if not set)
             if self.encryption_enabled:
                 AT_cmd=hexlify('KY')
                 AT_par=self.encryption_key
                 if len(AT_par) % 2:
                     AT_par='0'+AT_par
                 frame_data="0801"+AT_cmd+AT_par #AT command send
                 length = self.length_calc(frame_data)   
                 check_sum = self.check_sum_calc(frame_data)
                 command="7E" + length + frame_data + check_sum
                 self.ser.write(unhexlify(command))
                 #response=(hexlify(self.ser.readall()))
                 
                 AT_cmd=hexlify('EE')
                 AT_par='01'
                 frame_data="0801"+AT_cmd+AT_par #AT command send
                 length = self.length_calc(frame_data)   
                 check_sum = self.check_sum_calc(frame_data)
                 command="7E" + length + frame_data + check_sum
                 self.ser.write(unhexlify(command))
                 #response=(hexlify(self.ser.readall()))
             else:
                 AT_cmd=hexlify('EE')
                 AT_par='00'
                 frame_data="0801"+AT_cmd+AT_par #AT command send
                 length = self.length_calc(frame_data)   
                 check_sum = self.check_sum_calc(frame_data)
                 command="7E" + length + frame_data + check_sum
                 self.ser.write(unhexlify(command))
                 #response=(hexlify(self.ser.readall()))
         else:
             if self.encryption_enabled: #UDP AES Encryption calrulation here!
                 key = '%016x' % int(self.encryption_key, 16)
                 kSize = len(key)
                 
                 alg = AES(key, keySize=kSize, padding=padWithPadLen())
                 
                 for i in range(0, SAMPLES):
                     self.data_arr[i]=alg.encrypt(self.data_arr[i])
                 
         '''
         XBee S2     - we will use Radios Series2 (ZigBee) Module with explicit addressing (64bit & 16bit) data Transmission
         XBee short  - we will use Radios Series1 (XBee) Module with short addressing (16bit) data Transmission
         XBee long   - we will use Radios Series1 (XBee) Module with long addressing (64bit) data Transmission
         UDP         - we will use standard UDP data Transmission (no Digi Modules involved here)
         '''
         if choice=="XBee S2":
             #self.ser.Open()
             self.S2_TX(SLEEP, SAMPLES)
             #self.ser.Close()
         elif choice=="XBee short":
             #self.ser.Open()
             self.S1_TX_short(SLEEP, SAMPLES)
             #self.ser.Close()
         elif choice=="XBee long":
             #self.ser.Open()
             self.S1_TX_long(SLEEP, SAMPLES)
             #self.ser.Close()
         elif choice=="UDP":
             #self.udp.Open()
             self.UDP_TX(SLEEP, SAMPLES)
             #self.udp.Close()
             
     except KeyboardInterrupt:
         return
from crypto.cipher.aes  import AES
from crypto.cipher.base import padWithPadLen
from binascii           import a2b_hex, b2a_hex, hexlify, unhexlify

key = '%016x' % 0x1234
kSize = len(key)

data = 'Data goes here! Is that a surprize?'

alg = AES(key, keySize=kSize, padding=padWithPadLen())

enc_data=alg.encrypt(data)
dec_data=alg.decrypt(enc_data)