2016-09-13 17:23:14 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# This work is licensed under the Creative Attribution-NonCommercial-ShareAlike
|
|
|
|
# 3.0 Unported License.To view a copy of this license, visit
|
|
|
|
# http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
|
|
|
|
# Creative Commons, 444 Castro Street, Suite 900, Mountain View,
|
|
|
|
# California, 94041, USA.
|
|
|
|
|
2016-09-12 21:04:47 -04:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
from bitstring import BitArray
|
|
|
|
|
2016-09-13 17:30:01 -04:00
|
|
|
# Does anybody read this stuff? There's a PEP somewhere that says I should do this.
|
|
|
|
__author__ = 'Cortney T. Buffington, N0MJS'
|
|
|
|
__copyright__ = 'Copyright (c) 2016 Cortney T. Buffington, N0MJS and the K0USY Group'
|
2016-09-15 08:52:16 -04:00
|
|
|
__credits__ = 'Jonathan Naylor, G4KLX; Ian Wraith'
|
2016-09-13 17:30:01 -04:00
|
|
|
__license__ = 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported'
|
|
|
|
__maintainer__ = 'Cort Buffington, N0MJS'
|
|
|
|
__email__ = 'n0mjs@me.com'
|
|
|
|
|
|
|
|
|
2016-09-13 17:21:57 -04:00
|
|
|
def binary_196(_data):
|
|
|
|
_data = bytearray(_data)
|
|
|
|
_data = BitArray(_data)
|
|
|
|
return _data[:98] + _data[-98:]
|
|
|
|
|
|
|
|
def deint_196(_data):
|
|
|
|
deint = BitArray(196)
|
|
|
|
for index in range(196):
|
|
|
|
deint[index] = _data[(index * 181) % 196]
|
|
|
|
return deint
|
|
|
|
|
|
|
|
def extract_196(_data):
|
|
|
|
databits = BitArray()
|
|
|
|
databits.append(_data[4:12])
|
2016-09-15 08:52:16 -04:00
|
|
|
databits.append(_data[16:27])
|
|
|
|
databits.append(_data[31:42])
|
|
|
|
databits.append(_data[46:57])
|
|
|
|
databits.append(_data[61:72])
|
|
|
|
databits.append(_data[76:87])
|
|
|
|
databits.append(_data[91:102])
|
|
|
|
databits.append(_data[106:117])
|
|
|
|
databits.append(_data[121:132])
|
2016-09-13 17:21:57 -04:00
|
|
|
return databits.tobytes()
|
2016-09-15 08:52:16 -04:00
|
|
|
|
2016-09-12 21:04:47 -04:00
|
|
|
|
2016-09-13 17:21:57 -04:00
|
|
|
if __name__ == '__main__':
|
2016-09-12 21:04:47 -04:00
|
|
|
|
2016-09-15 08:52:16 -04:00
|
|
|
from binascii import b2a_hex as h
|
|
|
|
|
2016-09-13 17:21:57 -04:00
|
|
|
# Validation Example
|
|
|
|
data = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20'
|
|
|
|
|
|
|
|
bin_data = binary_196(data)
|
|
|
|
deint_data = deint_196(bin_data)
|
|
|
|
ext_data = extract_196(deint_data)
|
|
|
|
|
2016-09-15 08:52:16 -04:00
|
|
|
print('original 33 byte data block:')
|
2016-09-13 17:21:57 -04:00
|
|
|
print(h(data))
|
|
|
|
print(len(data))
|
|
|
|
print()
|
|
|
|
|
2016-09-15 08:52:16 -04:00
|
|
|
print('binary data (discarding sync)')
|
2016-09-13 17:21:57 -04:00
|
|
|
print(bin_data.len)
|
2016-09-15 08:52:16 -04:00
|
|
|
print(bin_data)
|
2016-09-13 17:21:57 -04:00
|
|
|
print()
|
|
|
|
|
2016-09-15 08:52:16 -04:00
|
|
|
print('deinterleaved binary data')
|
2016-09-13 17:21:57 -04:00
|
|
|
print(deint_data.len)
|
2016-09-15 08:52:16 -04:00
|
|
|
print(deint_data)
|
2016-09-13 17:21:57 -04:00
|
|
|
print()
|
2016-09-12 21:04:47 -04:00
|
|
|
|
2016-09-15 08:52:16 -04:00
|
|
|
print('decoded hex data')
|
|
|
|
print(len(ext_data)*8)
|
2016-09-13 17:21:57 -04:00
|
|
|
print(h(ext_data))
|