def _flash_encryption_tweak_key(key, offset, tweak_range):
 key = [ord(k) for k in key]
 offset_bits = [((offset & (1 << x)) != 0) for x in range(24)]
 for bit in tweak_range:
  if offset_bits[_FLASH_ENCRYPTION_TWEAK_PATTERN[bit]]:
   key[(bit / 8)] ^= (1 << (7 - (bit % 8)))
 return ''.join((chr(k) for k in key))

def _flash_encryption_tweak_key ( key , offset , tweak_range ) : key = [ ord ( k ) for k in key ] offset_bits = [ ( ( offset & ( 1 << x ) ) != 0 ) for x in range ( 24 ) ] for bit in tweak_range : if offset_bits [ _FLASH_ENCRYPTION_TWEAK_PATTERN [ bit ] ] : key [ ( bit / 8 ) ] ^= ( 1 << ( 7 - ( bit % 8 ) ) ) return '' . join ( ( chr ( k ) for k in key ) )
apply xor "tweak" values to the key .