Beispiel #1
0
            print('R_%s = %s' % (i, R[i].bin))
    # R_fin = np.array(R[16])
    # L_fin = np.array(L[16])
    output_pre_permutation = np.concatenate(
        (split_bitarray(R[16], 4), split_bitarray(L[16], 4)), axis=0)
    output = do_permutation(
        BitArray(flatten_list(output_pre_permutation.tolist())), vals.ip_inv)
    if debug:
        print('Ciphertext before inverse permutation: ')
        for element in output_pre_permutation:
            print(BitArray(element).bin)
    return BitArray(flatten_list(output))


# The below can be used to validate the functionality of DES_encrypt() as described in
# http://page.math.tu-berlin.de/~kant/teaching/hess/krypto-ws2006/des.htm
# x   = BitArray('0b 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111')
# K   = BitArray('0b 00010011 00110100 01010111 01111001 10011011 10111100 11011111 11110001')
# y = DES_encrypt(x, K, debug=True)
# print('\nCiphertext:' + str(y.hex))

# Initialize given values
x = BitArray(
    '0b 00100101 01100111 11001101 10110011 11111101 11001110 01111110 00101010'
)
K = BitArray(
    '0b 11100101 01100111 11001101 10110011 11111101 11001110 01111111 00101010'
)
y = DES_encrypt(x, K)
print('Ciphertext: %s' % y.hex)
Beispiel #2
0
def displayPrecision(num):
    binum = BitArray(float=num, length=64)
    sign = int(binum[0])
    exponent = binum[1:12].bin
    mantissa = binum[12:].bin
    return sign, exponent, mantissa
Beispiel #3
0
 def convert_to_bitstring(self, new_data):
     if isinstance(new_data, BitArray):
         return new_data
     else:
         return BitArray(bytes=new_data, length=len(new_data) * 8)
class TinyCompressor:
    """This class holds data and methods for 
    a data compressor using LEC Algorithm"""

    table = {}
    decode_table = {}
    eof = 0
    __first_data = []
    __previous_data = []
    __data = []
    __data_ns = []
    __decimal_places = []
    __strings_table = {}
    __compressed_data = BitArray()
    __compressed_data_string = ""
    __data_length = 0
    data_frequencies = {}

    __d_values = []
    codec = 0

    def __init__(self, decimal_places):
        self.__decimal_places = decimal_places[:]

    def set_strings_table(self, new_strings_table):
        self.__strings_table = new_strings_table

    def get_n(self, d_value):
        if d_value == 0:
            return 0
        return int(floor(log(abs(d_value),2))) + 1

    def get_a(self,d_value,n_value):
        if d_value == 0:
            return ""
        if d_value < 0:
            return BitArray(int=d_value-1, length=20).bin[(-1)*n_value:]
        if d_value > 0:
            return BitArray(int=d_value, length=20).bin[(-1)*n_value:]

    def generate_data_list(self,inputfilename):
        first = True
        self.__first_data = []
        self.__previous_data = []
        self.__data_ns = []
        self.__data = []
        self.data_frequencies = {}
        with open(inputfilename) as inputfile:
            for line in inputfile:
                linedata = line.split(",")
                self.__data_length = len(linedata)
                if (len(linedata) != len(self.__decimal_places)):
                    print "Length of decimal places different than length of data"
                    return #Should return an exception
                if first:
                    for i in range(len(linedata)):
                        self.__first_data.append(float(linedata[i]))
                    self.__previous_data = self.__first_data[:]
                    first = False
                else:
                    for i in range(len(linedata)):
                        value = (int(float(linedata[i]) * 10**self.__decimal_places[i]) - 
                                int(float(self.__previous_data[i]) * 10**self.__decimal_places[i]))
                        """if (i == 2):
                            print "Value =", value"""
                        self.__data.append(value)
                        self.__data_ns.append(self.get_n(value))
                    self.__previous_data = linedata[:]

        print "Data len =", len(self.__data)
        print "adding range MAX_DATA_N"
        self.__data_ns += range(MAX_DATA_N)



    def generate_table(self,inputfilename):
        self.generate_data_list(inputfilename)
        self.codec = HuffmanCodec.from_data(self.__data_ns)
        self.table = self.codec.get_code_table()

        self.__strings_table = {}
        for symbol in self.table.keys():
            if not type(symbol) is int:
                self.eof = symbol
            bitsize, value = self.table[symbol]
            self.__strings_table[symbol] = bin(value)[2:].rjust(bitsize, '0')

    def encode_data(self, inputfilename, outputfilename):
        self.generate_data_list(inputfilename)
        self.__compressed_data_string = ""

        try:
            for i in range(len(self.__data)):
                self.__compressed_data_string += \
                    self.__strings_table[self.__data_ns[i]] + \
                    self.get_a(self.__data[i], self.__data_ns[i]) 
        except KeyError:
            print "Not possible to encode data[{}] = {}".format(i, self.__data[i])
            return

        #Add EOF
        self.__compressed_data_string += self.__strings_table[self.eof]

        self.__compressed_data = BitArray(bin=self.__compressed_data_string)
        #print "Compressed data to file:", self.__compressed_data.bin

    def to_file(self):
        with open(outputfilename, 'wb') as outputfile:
            self.__compressed_data.tofile(outputfile)

    def build_values(self,inputfilename):
        print "Building values from", inputfilename

        compressed_bitarray = 0
        with open(inputfilename, 'rb') as compressedfile:
            compressed_bitarray = BitArray(compressedfile)

        #print "Compressed data from file:", compressed_bitarray.bin

        for k in self.__strings_table.keys():
            if (type(k) is int):
                self.decode_table[self.__strings_table[k]] = k
        possible_codes = set(self.decode_table.keys())

        #print "Decode table =", self.decode_table
        self.__d_values = []
        time_to_stop = False
        iteration = 0
        start_s = 0
        end_s = 1
        start_a = end_s
        end_a = 3
        n = 0
        s = 0
        a = 0

        while( not time_to_stop):
            if compressed_bitarray[start_s:end_s].bin in possible_codes:
                s = compressed_bitarray[start_s:end_s]
                n = self.decode_table[s.bin]
                start_a = end_s
                end_a = start_a + n # +1 ?


                if n == 0: #a = 0
                    self.__d_values.append(0)
                else:
                    a = compressed_bitarray[start_a:end_a]
                    if a[0]:
                        self.__d_values.append((OFFSET_ZERO+ a).int)
                    else:
                        self.__d_values.append((OFFSET_ONE+ a).int +1)
                start_s = end_a
            else:
                end_s += 1
            if end_s >= len(compressed_bitarray.bin):
                time_to_stop = True


    def decode_data(self,first_values, inputfilename, outputfilename):
        self.build_values(inputfilename)
        self.__values = []
        accumulator = first_values[:]
        print "len __d_values =", len(self.__d_values)
        """print "Data encoded =", self.__data
        print "Data decoded =", self.__d_values
        print "First values =", first_values"""
        """for i in range(len(self.__d_values)/len(accumulator)):
            self.__values.append(accumulator[:])
            for j in range(i, i*len(accumulator)+ len(accumulator)):
                print "(i,j) =",j-i*len(accumulator),j
                accumulator[j-i*len(accumulator)] += self.__d_values[j]"""
        self.__values.append(accumulator[:])
        for i in range(len(self.__d_values)):
            """if (i == 2):
                print "Value =", self.__d_values[i]"""
            """if((i%len(accumulator) == 1)):
                print self.__d_values[i]"""
            if self.__decimal_places[i%len(accumulator)] == 0:
                accumulator[i%len(accumulator)] += self.__d_values[i]
            else:
                accumulator[i%len(accumulator)] += float(self.__d_values[i]) \
                    / 10**self.__decimal_places[i%len(accumulator)]
            if ((i%len(accumulator)) == (len(accumulator)-1)):
                self.__values.append(accumulator[:])

        with open(outputfilename, 'wb') as outputfile:
            for value in self.__values:
                line = ",".join(
                    [("{:."+str(self.__decimal_places[i]) +"f}").format(float(value[i])) for i in range(len(value))])
                outputfile.write(line + '\n')
Beispiel #5
0
 def to_bytes(self):
     bytes_name = name_to_bytes(self.qname)[0]
     bits_packet = BitArray(length=32)
     bits_packet[0:16] = pack('uint: 16', self.qtype)
     bits_packet[16:32] = pack('uint: 16', self.qclass)
     return bytes_name + bits_packet.tobytes()
Beispiel #6
0
 def prepareUInt16as2Bytes(self, i):
     word = BitArray(uint=i, length=16)
     lb = word[0:8].hex.encode('utf-8') + b' '
     ub = word[8:16].hex.encode('utf-8') + b' '
     return ub + lb
 def set_vlan(self, vlan):
     if vlan < MIN_VLAN_ID or vlan > MAX_VLAN_ID:
         return
     if not self.vlan_bit_map:
         self.vlan_bit_map = BitArray(MAX_VLAN_ID + 1)
     self.vlan_bit_map[vlan] = 1
Beispiel #8
0
     [30, 22, 84, 3], [36, 92, 113, 46], [37, 50, 98, 81], [33, 125, 13, 122],
     [10, 5, 62, 6], [61, 21, 82, 38], [102, 43, 42, 45], [95, 114, 110, 4],
     [89, 9, 94, 117], [87, 105, 79, 27], [88, 85, 72, 18], [51, 48, 108, 119],
     [16, 23, 1, 73], [75, 101, 26, 71], [126, 93, 7, 118], [31, 97, 104, 74],
     [96, 103, 99, 91], [29, 100, 69, 83], [6, 88, 75, 19], [101, 68, 20, 98],
     [107, 45, 28, 121], [87, 26, 59, 34], [44, 35, 12, 127], [42, 40, 56, 9],
     [47, 80, 16, 89], [78, 21, 14, 100], [1, 110, 65, 115], [90, 113, 8, 15],
     [85, 70, 66, 83], [32, 67, 108, 73], [53, 76, 41, 111], [109, 13, 17, 91],
     [95, 31, 122, 82], [119, 99, 120, 7], [123, 71, 86, 69], [77, 50, 97, 22],
     [5, 126, 43, 125], [118, 52, 38, 102], [48, 55, 29,
                                             116], [27, 24, 103, 94],
     [23, 106, 18, 61], [33, 92, 93, 81], [0, 79, 25, 4], [96, 63, 3, 72],
     [49, 84, 74, 114], [57, 51, 60, 39], [37, 112, 36, 62], [11, 64, 54, 104],
     [58, 46, 10, 124], [117, 30, 105, 2]]
w = BitArray(
    '0b01101111110010111001011111001001111111111100101011111000001011111111000110000101010000011011110110100001011101000011001110001010'
)
x = encode(K, P, w)
assert x == BitArray(
    '0b011011111100101110010111110010011111111111001010111110000010111111110001100001010100000110111101101000010111010000110011100010101111101110010011110111011101000000000000010100111111000100111101110110001111010100101010011111111100000110011000001111100001001110100110010001100001010010001010100010011100001001100110011010010100001110000111011101110111011011001010111010011101101011011110'
)
y = BitArray(
    '0b000011011100101100000011100000011101101010001000110010000010010111000000000000000000000100001100000000010000000000100001000000100111100110000011010111011001000000000000000000110001000000111101000010001001010000000010000101111000000010011000001110100000000000100100010000000000000000000000000010011100000001000110010000010000000010000011000001000101000011000010000010001001101001001010'
)
q = BitArray(
    '0b111100100011000011011100010011000010010101110110001100000001101000111111101111011110010011110011101110100111111101010010110110001000011001111000101000000100011100001001111110001110000100000010110100100110001110101001111010000111111100000100100001000111011110011011101111110001111010011010110100000011011100101001001010001101111100101100011110110010011000101001111101010110000010010100'
)
hat_y = decode(K, P, y, q)
assert hat_y is not None
hat_w = hat_y[:K]
assert hat_w == w
def hamming_distance(s1, s2):
    ba1 = BitArray(hex=s1.encode('hex'))
    ba2 = BitArray(hex=s2.encode('hex'))
    return (ba1 ^ ba2).count(1)
    def __init__(self):
        # TODO Support for command line argument
        self.main_program_instr_cnt = 100  # count of main_prog
        self.sub_program_instr_cnt = []  # count of sub_prog
        self.debug_program_instr_cnt = 0  # count of debug_rom
        self.debug_sub_program_instr_cnt = []  # count of debug sub_progrms
        self.max_directed_instr_stream_seq = 20
        # Commenting out for now
        # self.data_page_pattern = list(
        # map(lambda dta_pg: dta_pg.name, data_pattern_t))
        # dicts for exception_cause_t & interrupt_cause_t Enum classes

        self.m_mode_exception_delegation = {}
        self.s_mode_exception_delegation = {}
        self.m_mode_interrupt_delegation = {}
        self.s_mode_interrupt_delegation = {}

        # init_privileged_mode default to MACHINE_MODE
        self.init_privileged_mode = privileged_mode_t.MACHINE_MODE

        self.mstatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.mie = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.sstatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.sie = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.ustatus = BitArray(bin(0b0), length=rcs.XLEN - 1)
        self.uie = BitArray(bin(0b0), length=rcs.XLEN - 1)

        self.mstatus_mprv = 0
        self.mstatus_mxr = 0
        self.mstatus_sum = 0
        self.mstatus_tvm = 0
        self.mstatus_fs = BitArray(bin(0b0), length=2)
        self.mstatus_vs = BitArray(bin(0b0), length=2)
        self.mtvec_mode = vsc.rand_enum_t(mtvec_mode_t)

        self.argv = self.parse_args()
        self.args_dict = vars(self.argv)

        self.tvec_alignment = self.argv.tvec_alignment

        self.fcsr_rm = list(map(lambda csr_rm: csr_rm.name, f_rounding_mode_t))
        self.enable_sfence = 0
        self.gpr = []

        # Helper fields for gpr
        self.gpr0 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr1 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr2 = vsc.rand_enum_t(riscv_reg_t)
        self.gpr3 = vsc.rand_enum_t(riscv_reg_t)

        self.scratch_reg = vsc.rand_enum_t(riscv_reg_t)
        self.pmp_reg = vsc.rand_enum_t(riscv_reg_t)
        self.sp = vsc.rand_enum_t(riscv_reg_t)
        self.tp = vsc.rand_enum_t(riscv_reg_t)
        self.ra = vsc.rand_enum_t(riscv_reg_t)
        self.check_misa_init_val = 0
        self.check_xstatus = 1
        self.virtual_addr_translation_on = 0

        # Commenting out for now
        # vector_cfg = riscv_vector_cfg # TODO
        # pmp_cfg = riscv_pmp_cfg  # TODO
        # self.mem_region = [] # TODO
        # Self.amo_region = [] # TODO

        self.stack_len = 5000

        # Self.s_mem_region = [] # TODO

        self.kernel_stack_len = 4000
        self.kernel_program_instr_cnt = 400
        # list of main implemented CSRs
        self.invalid_priv_mode_csrs = []
        self.num_of_sub_program = self.argv.num_of_sub_program
        self.instr_cnt = self.argv.instr_cnt
        self.num_of_tests = self.argv.num_of_tests
        self.no_data_page = self.argv.no_data_page
        self.no_branch_jump = self.argv.no_branch_jump
        self.no_load_store = self.argv.no_load_store
        self.no_csr_instr = self.argv.no_csr_instr
        self.no_ebreak = self.argv.no_ebreak
        self.no_dret = self.argv.no_dret
        self.no_fence = self.argv.no_fence
        self.no_wfi = self.argv.no_wfi
        self.enable_unaligned_load_store = self.argv.enable_unaligned_load_store
        self.illegal_instr_ratio = self.argv.illegal_instr_ratio
        self.hint_instr_ratio = self.argv.hint_instr_ratio
        self.num_of_harts = self.argv.num_of_harts
        self.fix_sp = self.argv.fix_sp
        self.use_push_data_section = self.argv.use_push_data_section
        self.boot_mode_opts = self.argv.boot_mode

        if self.boot_mode_opts:
            logging.info("Got boot mode option - %0s", self.boot_mode_opts)
            if self.boot_mode_opts == "m":
                self.init_privileged_mode = privileged_mode_t.MACHINE_MODE
            elif self.boot_mode_opts == "s":
                self.init_privileged_mode = privileged_mode_t.SUPERVISOR_MODE
            elif self.boot_mode_opts == "u":
                self.init_privileged_mode = privileged_mode_t.USER_MODE
            else:
                logging.error("Illegal boot mode option - %0s",
                              self.boot_mode_opts)

        self.enable_page_table_exception = self.argv.enable_page_table_exception
        self.no_directed_instr = self.argv.no_directed_instr
        self.asm_test_suffix = self.argv.asm_test_suffix
        self.enable_interrupt = self.argv.enable_interrupt
        self.enable_nested_interrupt = self.argv.enable_nested_interrupt
        self.enable_timer_irq = self.argv.enable_timer_irq
        self.bare_program_mode = self.argv.bare_program_mode
        self.enable_illegal_csr_instruction = self.argv.enable_illegal_csr_instruction
        self.enable_access_invalid_csr_level = self.argv.enable_access_invalid_csr_level
        self.enable_misaligned_instr = self.argv.enable_misaligned_instr
        self.enable_dummy_csr_write = self.argv.enable_dummy_csr_write
        self.randomize_csr = self.argv.randomize_csr
        self.allow_sfence_exception = self.argv.allow_sfence_exception
        self.no_delegation = self.argv.no_delegation
        self.force_m_delegation = self.argv.force_m_delegation
        self.force_s_delegation = self.argv.force_s_delegation
        self.support_supervisor_mode = 0
        self.disable_compressed_instr = self.argv.disable_compressed_instr
        self.require_signature_addr = self.argv.require_signature_addr

        if (self.require_signature_addr):
            self.signature_addr = int(self.argv.signature_addr, 16)
        else:
            self.signature_addr = 0xdeadbeef

        self.gen_debug_section = self.argv.gen_debug_section
        self.enable_ebreak_in_debug_rom = self.argv.enable_ebreak_in_debug_rom
        self.set_dcsr_ebreak = self.argv.set_dcsr_ebreak
        self.num_debug_sub_program = self.argv.num_debug_sub_program
        self.enable_debug_single_step = self.argv.enable_debug_single_step
        self.single_step_iterations = 0
        self.set_mstatus_tw = self.argv.set_mstatus_tw
        self.set_mstatus_mprv = self.argv.set_mstatus_mprv
        self.min_stack_len_per_program = 10 * (rcs.XLEN / 8)
        self.max_stack_len_per_program = 16 * (rcs.XLEN / 8)
        self.max_branch_step = 20
        self.reserved_regs = vsc.list_t(vsc.enum_t(riscv_reg_t))
        self.enable_floating_point = self.argv.enable_floating_point
        self.enable_vector_extension = self.argv.enable_vector_extension
        self.enable_b_extension = self.argv.enable_b_extension
        self.enable_bitmanip_groups = self.argv.enable_bitmanip_groups
        self.dist_control_mode = 0
        self.category_dist = {}
        self.march_isa = self.argv.march_isa

        if (len(self.march_isa) != 0):
            rcs.supported_isa = self.march_isa

        if (rcs.supported_isa != 'RV32C'):
            self.disable_compressed_instr = 1
####
PROB_THRESHOLD = .7
COUNT_THRESH = 3

#pre-amble and access code data
# PREA_AND_ADDR = [PREA_AND_ADDR_STR[st:st+2] for st in range(len(PREA_AND_ADDR_STR)) if st%2==0]
# PREA_AND_ADDR_LEN = len(PREA_AND_ADDR);

# packet of interest
PACKET_BODY_STR = "d373803183ab10953e489039dd3b36236a29f0b0c6f8ba00b9"
PACKET_BODY = [
    PACKET_BODY_STR[st:st + 2] for st in range(len(PACKET_BODY_STR))
    if st % 2 == 0
]
PACKET_BUFFER = BitArray(hex=PACKET_BODY_STR).bin
#PARKED_PACKET
PACKET_BODY_LEN = len(PACKET_BODY)

##hamming distance map
characters = [
    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e",
    "f"
]
#CHAR_DISTS = {(i,j):bin(int(i,16)^int(j,16)).count('1') for i in characters for j in characters}

#####################
#####################
'''
debug and control functions
'''
 def encrypt(self, input_bits):
     assert(len(input_bits) == BS_BITS)
     return BitArray(aes.encrypt256(input_bits.bytes))
Beispiel #13
0
 def rx_bitfield(self):
     if self._receiver:
         bits = BitArray(bytes=self._current_buf[1:self._bytes_received])
         self._receiver.rx_bitfield(bits)
Beispiel #14
0
def main():
    # logging.basicConfig(format='%(asctime)s %(filename)s %(funcName)s %(levelname)s %(message)s',
    #                     datefmt='%m/%d/%Y %I:%M:%S %p',filename=r'logs/app.log',level=logging.INFO, filemode='w')

    logging.basicConfig(
        format=
        '%(asctime)s %(filename)s %(funcName)s %(levelname)s %(message)s',
        datefmt='%m/%d/%Y %I:%M:%S %p',
        level=logging.INFO)
    logging.info('App started.')
    parser = argparse.ArgumentParser(
        description='DNA secret sharing app client')
    parser.add_argument('-f',
                        help='the full path of the DNA file',
                        required=True,
                        dest='file_name')
    parser.add_argument('-s',
                        help='server 2 IP  - #.#.#.#',
                        required=True,
                        dest='server_ips',
                        nargs=2)
    parser.add_argument('-d',
                        help='max distance off of the client DNA',
                        dest='dist',
                        required=False,
                        type=int)
    args = vars(parser.parse_args())
    dna = load_file(args['file_name'])
    try:
        Client = DNA_App_Client(dna)
        if args['dist'] is not None:
            logging.info("Building distance tree")
            secret_share_tree, seed0, seed1 = Client.build_d_distance_trees(
                args['dist'])
        else:
            logging.info("Building the tree")
            secret_share_tree, seed0, seed1 = Client.build_secret_share_trees()
        logging.info("Done building tree")

    except InvalidDNAException:
        logging.error(
            "The input DNA string is invalid, please check DNA string in file")

    # send server 1 list of tree object, seed, t bit and sec param - thread
    # send server 2 list of tree object, seed, t bit and sec param - thread

    # listen to response - should be serialized list of results - both threads
    # add corresponding items in each thread

    # try:
    logging.info("Sending data to servers")
    comm_client_1 = Comm_client(args['server_ips'][0],
                                tree_root=secret_share_tree,
                                seed=seed0,
                                tbit='0',
                                sec_param=constant.SEC_PARAM)
    comm_client_2 = Comm_client(args['server_ips'][1],
                                tree_root=secret_share_tree,
                                seed=seed1,
                                tbit='1',
                                sec_param=constant.SEC_PARAM)
    comm_client_1.start()

    # comm_client_1.run()
    # comm_client_2.run()
    comm_client_2.start()

    comm_client_1.join()
    comm_client_2.join()

    server1_analysis = comm_client_1.analysis
    server2_analysis = comm_client_2.analysis

    logging.info("Analyzing results")

    analysis = (BitArray(bin=server1_analysis)
                ^ BitArray(bin=server2_analysis)).int
    if analysis == 0:
        print "No disease found."
    else:
        analysis = log(analysis, 2)
        print 'The client DNA matches disease # : %d' % (analysis)

    # for key, index in zip(server1_analysis,range(0,len(server1_analysis))):
    #     analysis1 = BitArray(bin=server1_analysis[key])
    #     analysis2 = BitArray(bin=server2_analysis[key])
    #
    #     print "The risk of being ill of illness # %d is: %d percent. " %(index + 1,(analysis1 ^ analysis2).int)
    # print analysis1.int
    # except Exception as e:
    #     logging.error("Something went wrong while communicating with servers")
    #     print sys.exc_info()[0]

    logging.info('App done.')
Beispiel #15
0
 def prepareInt8as4bits(self, i):
     word = BitArray(uint=i, length=4)
     b = word[0:4].hex.encode('utf-8') + b''
     return b
Beispiel #16
0
from bitstring import BitArray

char_string = "71 -119 -99 84 71 -115 -99 84 71 9 -99 84 71 -115 -99 92 71 -119 -99 84 71 -115 -99 84 71 11 -99 84 71 -115 -99 92 71 -120 -99 84 71 -115 -99 84 71 9 -115 84 71 -99 -99 92 71 -119 -99 84 71 -115 -99 84 71 11 -99 -44 71 -115 -99 92 71 -119 -99 84 71 -115 -99 -44 71 9 -99 84 68 -115 -99 92 71 -119 -99 84 79 -115 -100 84 71 10 -99 84 71 -115 -99 88 71 -120 -99 84 71 -115 -99 84 71 9 -115 84 71 -99 -99 94 71 -119 21 84 71 -115 -99 84 71 11 -99 -44 71 -115 -99 88 71 -119 -103 84 71 -115 -99 84 71 9 -99 84 71 -115 -107 92 71 -119 -115 84 71 -115 -99 84 71 11 -99 84 71 -115 -99 92 71 -120 -115 84 71 -115 -99 84 71 9 -115 84 71 -99 -99 92 71 -119 -99 84 -57 13 -97 84 71 11 -99 -44 71 -115 -99 92 71 -103 -99 84 71 -115 -99 84 69 -119 -99 84 68 -115 -99 92 71 -119 -115 84 79 -115 -100 84 71 -118 -99 84 71 13 -99 88 71 -120 -99 84 71 -115 -99 84 71 9 -115 84 71 -99 -99 94 71 -119 21 85 71 -123 -67 84 71 11 -99 -42 71 -115 -99 90 71 -103 -97 84 71 -115 -99 92 71 9 -99 92 71 -115 -99 92 71 -55 -99 84 71 -115 -99 84 71 11 -35 84 71 -115 -103 94 79 -120 -99 84 71 -115 -99 84 71 9 -115 84 79 -99 -99 94 71 -119 -99 84 69 -115 -99 84 71 11 -99 -44 71 -115 -99 92 71 -119 -99 84 7 -115 -99 -44 71 9 -100 84 68 -115 -99 92 71 -119 -99 84 79 -115 -100 84 71 10 -99 84 71 -115 -99 89 71 -120 -99 84 71 -115 -103 84 71 9 -115 84 71 -99 -103 94 71 -119 -75 84 71 13 -99 92 71 11 -99 -44 7 -115 -99 88 71 -119 -103 84 71 -115 -99 92 71 9 -99 84 71 -115 -107 92 71 -119 -115 116 71 -83 -35 84 71 11 -99 84 71 -115 -35 92 71 -120 -115 84 71 -115 -99 84 69 9 -115 84 71 -99 -99 92 71 -119 -107 84 -57 9 -65 84 71 11 -99 -44 87 -115 -35 92 71 -103 -99 84 103 -115 -99 84 69 -119 -99 84 68 -115 -67 92 79 -119 -115 84 79 -115 -100 84 71 -118 -99 84 71 13 -99 88 71 -120 -99 84 71 -116 -99 84 71 9 -113 84 71 -99 -99 94 71 -119 21 85 71 -91 -3 84 71 -117 -99 -42 71 -115 -99 122 71 -119 -99 84 71 -115 -99 84 71 9 -97 84 71 -115 -99 92 71 -119 -99 84 71 -115 -99 84 71 11 -107 84 71 -115 -99 92 71 -120 -99 84 71 -115 -99 80 71 9 -115 84 71 -99 -99 92 7 -119 -99 84 71 -115 -99 84 71 11 -99 -44 71 -115 -99 92 71 -119 -97 84 -57 -115 -99 -44 67 9 -99 84 68 -115 -99 88 71 9 -99 84 79 -115 -100 84 71 10 -99 84 71 -115 -99 88 71 -120 -99 84 68 -115 -99 86 71 9 -113 84 71 -35 -99 95 71 -119 21 84 71 -115 -67 84 71 11 -99 -44 71 -115 29 88 71 -119 -103 84 71 -115 -99 84 71 9 -99 20 71 -115 -107 92 71 -119 -123 84 71 -115 -99 84 71 11 -99 84 71 -115 -99 92 71 -120 -115 84 71 -115 -99 28 71 9 -115 84 71 -99 -99 92 71 -119 -99 84 -57 13 -97 84 71 11 -99 -44 71 -115 -99 92 69 -103 -99 -44 71 -115 -99 84 69 -119 -99 84 68 -115 -99 92 71 -71 -115 92 79 -115 -100 84 71 -118 -99 84 71 13 -67 88 71 -120 -99 84 71 -115 -99 84 71 1 -115 84 71 -99 -99 94 70 -119 29 85 71 -123 -67 84 71 15 -97 -42 71 -115 -99 90 71 -104 -97 84 71 -115 29 92 71 9 29 92 71 -115 -35 92 71 -55 -99 84 71 -115 -99 84 71 11 -35 84 71 -115 -103 94 79 -116 -99 -44 71 -115 -99 84 71 9 -115 84 79 -99 -99 94 71 -119 -99 84 69 -115 -99 84 71 11 -99 -44 71 -115 -99 92 71 -119 -99 84 7 -83 -99 -44 15 9 -100 84 68 -115 -99 92 71 -119 -99 21 79 9 -100 84 71 10 -99 84 71 -115 -99 89 71 -120 -99 84 71 -115 -101 84 71 9 -115 84 71 -99 -103 92 71 -119 -75 84 103 13 -99 92 71 9 -99 -44 3 -115 -99 88 71 -119 -103 84 71 -115 -99 92 71 9 -99 84 71 -115 -108 92 71 -119 -115 116 71 -81 -35 84 71 11 -99 84 71 -115 -99 92 71 -120 -115 84 71 -99 -99 84 69 9 -115 85 71 -99 -99 92 79 -119 -107 84 -57 9 -65 84 71 11 -99 -44 87 -115 -35 92 67 -103 -103 84 103 -115 -99 84 69 -119 -97 84 68 -115 -67 92 79 -119 -103 84 79 -115 -100 84 71 -118 -115 84 7 13 -99 88 71 -120 -99 84 71 -116 -99 68 71 9 -113 84 103 -99 -99 94 71 -119 21 81 71 37 -3 84 71 -117 -99 -42 67 -115 -99 122 79 -116 -99 84 71 -115 -99 84 71 9 -99 84 71 -119 29 92 79 -119 -99 84 71 -115 -99 68 69 11 -99 84 71 -115 -99 92 71 13 -99 84 71 -115 -99 84 71 9 -115 84 71 -99 -99 92 71 -115 -35 84 67 12 -99 84 71 11 -99 -44 71 -115 -99 92 71 -119 -35 84 71 -115 -99 -44 -57 9 -99 84 68 -99 -99 92 67 -119 -100 80 79 -115 -100 84 71 10 -99 84 71 -115 -99 88 71 -120 -99 84 71 -115 -99 84 71 9 -115 92 71 -99 -99 95 71 -119 21 92 87 -115 -99 84 71 41 -99 -44 71 -115 -99 88 71 -119 -103 85 71 -115 -99 84 71 9 -99 84 79 -115 -107 92 71 -127 -115 84 71 -113 -99 92 71 11 -99 84 71 -115 -99 92 71 -120 13 84 71 -115 -99 84 71 9 -123 84 71 -99 -123 92 71 -119 -99 84 -49 77 -97 84 71 11 -115 -44 7 -115 -99 92 71 -103 -99 84 -57 -115 -99 84 69 -119 -99 84 68 -115 -99 88 71 -119 -119 84 79 -115 -100 84 7 -118 -99 84 71 13 -99 88 71 -120 -99 84 71 -115 -99 84 71 1 -115 84 71 -99 29 94 71 -119 21 85 71 -123 -67 84 71 11 -99 -42 71 -115 -99 90 71 -103 -97 84 71 -115 -99 92 71 9 -99 92 71 -115 -99 92 71 -55 -99 84 7 -115 -99 84 71 11 -35 84 71 -115 -103 94 79 -120 29 80 71 -113 -99 70 71 9 -115 84 79 -99 -97 94 71 -119 -100 84 69 -115 -99 84 71 11 -99 -44 71 -115 -99 92 71 -119 -99 84 6 -115 -99 -44 71 9 -100 84 68 -115 -99 92 71 -117 -99 84 -49 -115 -100 84 77 10 -99 84 71 -115 -99 89 71 -116 -115 85 71 -115 -103 84 71 9 -115 84 71 -99 -103 94 71 -119 -75 84 71 13 -99 93 71 11 -107 -44 7 -115 -99 88 71 -119 -103 84 71 -55 -99 92 71 9 -99 84 71 -115 -107 92 71 -119 -115 116 71 -83 -39 84 103 11 -99 84 71 -115 -35 92 71 -120 -115 84 71 -115 -99 84 69 9 -115 80 71 -99 -99 92 71 -119 -111 84 -57 9 -65 84 71 11 -99 -44 87 -115 -35 92 71 -103 -99 84 103 -115 -99 84 101 -119 -99 80 68 -51 -67 -36 15 -119 -115 84 79 -115 -100 84 71 -118 -99 84 71 45 -99 88 71 -120 -99 84 71 -116 -99 84 69 9 -49 84 71 -107 -99 94 103 -119 21 85 71 -91 -3 84 71 -101 -99 -42 71 -115 -99 58 67 -119 -99 84 71 -115 -99 86 87 9 -97 84 71 -115 -99 92 71 -119 -99 84 71 -115 -99 84 71 13 -107 84 71 -115 -99 92 70 -120 -99 84 71 -115 -99 80 71 9 -115 84 71 29 -99 92 7 -119 -99 116 119 -115 -97 84 -57 11 -99 -43 79 -115 -67 28 71 -119 -97 80 -57 -115 -99 -44 67 9 -99 68 68 -115 -99 24 103 9 -99 84 79 -115 -100 84 71 10 -99 84 71 -115 -99 90 -57 -120 -99 84 68 -115 -99 86 71 9 -113 84 71 -35 -99 95 71 9 21 84 71 -115 -67 84 71 -118 -99 -44 71 -115 -99 88 71 -119 -103 84 71 -115 -99 84 71 9 -99 20 71 -115 -107 92 71 25 -123 84 70 -115 -99 84 71 11 -99 84 71 -115 -99 -36 71 -120 -124 84 71 -115 -99 28 71 9 -115 84 71 -99 -115 92 87 -119 -99 -44 -57 13 -97 84 71 11 -99 -44 71 -115 -99 92 69 -103 -99 -44 71 -115 -99 84 69 -119 -99 84 68 -115 -99 92 71 -69 -115 92 79 -115 -100 84 71 -118 -99 84 71 13 -67 80 71 -120 -67 84 71 -115 -99 84 71 1 -115 92 71 -99 -99 94 70 -119 29 85 79 -123 -67 68 71 15 -98 -42 71 -115 -99 90 71 -104 -97 84 71 -115 29 92 71 9 29 92 71 -115 -35 92 71 -55 -99 84 71 -115 -99 84 71 11 -35 84 71 -115 -103 94 75 -116 -99 -44 67 -115 -99 84 7 9 -115 84 79 -99 -67 94 71 -119 -99 84 69 -51 -99 84 71 11 -99 -44 71 -55 -99 92 79 -119 -35 84 7 -83 -99 -44 14 9 -100 84 68 -115 -99 28 71 -55 -99 21 78 10 -100 84 71 42 -99 68 71 -115 -99 89 71 -120 -99 84 71 -115 -101 84 71 9 -123 84 71 -99 -103 92 71 -119 53 84 103 13 -99 92 71 9 -107 -44 3 -115 -99 88 71 -115 -103 84 71 -115 -99 124 71 9 -99 20 71 13 -108 93 71 -119 -115 116 71 -81 -35 84 71 91 -99 84 71 -116 -107 92 71 -120 -115 84 71 -99 -115 84 69 9 -115 85 71 -107 -99 92 79 -119 -107 84 -57 9 -97 84 71 11 -99 -44 87 -115 93 92 67 -103 -103 84 103 -115 -99 84 69 -119 -97 116 68 -115 -75 92 79 -119 57 84 79 -119 -100 84 71 -118 -115 84 7 13 -107 88 71 -120 -67 84 71 -116 -99 68 79 9 -113 84 103 -99 -99 94 71 -119 21 83 71 37 -3 84 71 -117 61 -42 65 -100 -99 122 71 -119 -35 84 71 -115 -99 84 71 9 -35 84 7 -115 -99 92 71 -119 -99 84 71 -99 -99 52 71 11 -99 84 71 -115 -99 92 71 -119 -99 84 71 -115 -99 84 71 9 -115 84 71 -99 -99 92 87 -119 -99 84 71 -115 -115 85 71 11 -99 -44 71 -83 -99 92 71 -119 -99 84 71 -113 -99 -44 71 25 -99 84 68 -115 -99 84 71 -119 -99 84 79 -115 -100 84 103 10 -99 84 71 -119 -99 88 71 -120 -99 84 71 -115 -99 84 71 9 -115 84 71 -99 29 94 71 -119 21 116 71 -115 -107 84 71 11 -99 -44 71 -115 -99 88 71 -119 -103 84 71 -115 -99 84 -57 13 -99 84 71 -115 -107 93 71 -119 -115 84 71 -123 -99 84 87 11 25 84 71 -115 -97 92 71 -120 -115 84 71 -115 -67 -44 71 9 -115 84 79 -99 -99 92 71 -119 -107 84 -61 13 -97 84 71 11 -100 -44 -57 -115 -99 92 71 -103 -99 86 71 -115 -99 68 69 -119 -99 84 68 -115 -99 92 71 -119 -115 84 79 -115 -100 84 71 -118 -107 84 71 13 -99 -40 71 -120 -99 84 71 -115 -99 84 71 9 -115 84 71 -99 -99 94 71 -119 21 85 71 -123 -67 84 69 11 -99 -42 71 -115 -107 90 71 -111 -97 84 71 13 -99 92 71 9 -107 84 71 -115 -99 92 71 -55 -99 80 71 -115 -99 84 7 11 -35 84 87 -115 -103 94 79 -120 29 84 71 -115 -115 84 103 9 -115 84 79 -103 -99 -34 71 -119 -99 84 69 -115 -99 84 79 11 -115 -44 67 -115 -99 28 71 -119 -103 20 7 -51 -99 -44 71 25 -100 64 68 -115 -99 92 71 -119 -99 84 79 -115 -100 84 103 10 -99 84 71 -115 -99 89 71 -120 -99 84 71 -115 -103 84 71 9 -115 84 71 -99 -71 94 71 -119 -75 20 71 13 -99 92 71 27 -99 -44 7 -115 -99 88 71 -119 -103 84 71 -115 -99 92 71 9 -99 84 71 -115 -107 92 71 -119 -115 116 71 -83 -35 80 71 11 -99 84 71 -115 -35 92 71 -120 13 84 71 -115 -99 84 69 9 -119 84 71 -99 -107 93 71 -119 -107 84 -57 9 63 84 71 11 -99 -12 87 -115 -35 92 71 -103 -99 84 103 -51 29 84 69 -117 -99 84 69 -115 -67 92 79 -127 -115 68 95 -115 -116 84 71 -118 -97 84 71 13 -99 88 71 -120 -99 84 71 -116 -99 84 71 9 -117 84 71 -99 -99 94 71 -119 21 85 71 -91 -11 84 71 -101 -99 -42 71 -115 -99 122 71 -87 -99 84 71 -115 -99 84 71 9 -97 84 71 -115 -99 92 71 -119 -99 84 71 -115 -99 84 71 9 -107 84 71 -115 -105 88 71 -56 -99 68 71 -115 -99 112 71 9 -115 84 103 -99 -99 92 7 -119 -99 84 67 -115 -99 84 71 11 -99 -44 69 -115 -99 92 71 -119 -97 84 71 -115 -99 -44 71 9 29 84 68 -115 -99 88 71 11 -99 84 79 -115 -100 -44 71 10 -99 84 71 -115 -99 88 71 -120 -99 84 68 -115 -99 70 69 9 -113 84 71 -35 -99 91 71 -119 85 84 103 -99 -68 84 71 11 -99 -44 71 -115 29 88 71 9 -103 84 71 -115 -99 84 71 9 -35 20 71 -83 -99 92 71 -119 -123 84 71 -115 -99 84 71 11 -99 84 71 -115 -99 93 67 -120 -51 84 71 -115 -99 28 71 9 -115 84 71 -67 -99 92 71 -119 -99 85 -57 13 -97 84 71 11 -99 -44 71 -115 -99 92 77 -119 -99 -44 71 -115 -99 84 5 -119 -99 84 68 -115 -115 92 71 -67 -119 92 79 13 -100 84 71 -114 -98 68 71 13 -83 72 71 -120 -99 84 71 -115 -99 84 71 1 -115 84 103 -99 -99 94 6 -119 29 85 71 -123 -67 84 71 15 -97 -42 71 -99 -99 26 71 -104 -98 84 71 -115 29 92 71 9 29 92 71 -115 -35 92 71 -55 -99 84 70 -115 -99 -44 71 11 -35 84 71 -119 -103 94 79 -116 -103 -60 71 -115 -99 84 79 9 -115 84 71 -67 -99 94 71 -119 -99 81 69 -115 -99 84 -57 11 -99 -44 71 -115 -99 92 71 -119 -99 84 23 -83 -99 -44 15 9 -100 84 68 -115 -99 92 71 -87 -99 21 95 9 -100 84 71 10 -99 84 71 -115 -99 89 71 -120 -99 84 77 -115 -101 84 71 25 -115 84 71 -107 -119 92 71 -119 -75 84 103 13 -100 92 71 9 -99 -44 3 -115 -99 -40 -57 -119 -103 84 71 -115 -99 92 71 9 -99 84 71 -115 -108 92 71 -119 -115 116 -57 -81 -35 84 71 11 -99 84 71 -116 -99 92 71 8 -115 84 71 -99 -99 84 69 9 -115 85 79 -99 -99 124 79 -119 -107 86 -57 9 -65 84 71 11 -99 -44 87 -83 -35 92 67 -43 -103 84 103 -115 -99 84 5 -119 -97 84 68 -115 -67 92 79 -119 -103 84 79 -116 -100 84 71 -82 -115 84 7 13 -99 88 87 -120 -99 81 71 -116 -99 68 71 41 -113 84 103 -99 -99 90 71 -115 -107 81 71 33 -3 84 71 -117 -99 -42 67 -99 -97 122 79 -84 -99 84 71 -114 -99 84 71 9 -99 84 71 -119 29 92 79 -119 -99 84 71 -115 -99 68 69 11 -99 80 71 -115 -99 92 71 13 -99 84 71 -115 -99 116 71 9 -115 84 71 -99 -99 28 71 -115 -35 84 67 12 -99 84 71 11 -99 -44 71 -115 -67 92 71 -119 -35 84 71 -115 -115 -44 -57 9 -99 92 68 -99 -99 92 67 -119 -100 80 79 -115 -98 84 71 10 -99 84 71 -115 -99 88 71 -120 -99 92 71 -115 -99 84 71 9 -115 92 71 -99 -103 95 71 -119 -107 28 87 -115 -99 84 71 41 -99 -60 71 -115 -99 89 71 -119 -103 85 71 -115 -99 84 71 9 -99 84 79 -115 -107 92 71 -127 -115 84 71 -117 -99 88 71 11 -99 84 71 -83 -115 92 71 -120 13 84 71 -115 -99 84 71 9 -123 84 71 -99 -123 92 66 -119 -100 84 -49 109 -97 84 71 11 -115 -44 7 -115 -99 92 71 -103 -99 84 -57 -115 -99 20 69 -56 -99 84 68 -115 -99 88 71 -119 -119 20 79 -115 -108 84 7 -118 -99 84 71 13 -99 88 71 -120 -97 84 71 -115 -99 84 71 1 -115 84 79 -99 29 94 71 -119 21 85 71 -123 -67 84 71 11 -99 -42 71 -115 -99 74 71 -39 -97 84 71 -115 -35 92 71 9 -99 80 71 -115 -99 28 71 -55 -99 84 7 -115 -99 84 71 11 -35 84 70 -115 -104 94 79 -120 29 80 103 -113 -99 70 71 9 -115 84 79 -99 -97 90 87 -119 -100 84 69 -115 -99 84 69 11 -99 -44 71 -115 -99 92 71 -119 -99 84 6 -115 -99 -44 6 9 -100 84 68 -115 -99 92 71 -117 -99 112 -49 -115 -100 84 77 10 -99 68 71 -115 -99 89 71 -116 -115 85 71 -115 -103 84 71 9 -115 84 71 -99 -79 94 71 -119 -75 84 71 13 -99 93 71 11 -105 -44 7 -115 -99 88 71 -119 -103 84 71 -55 -99 93 71 9 -99 84 71 -115 -107 94 -57 -119 -115 116 71 -83 89 84 103 11 -99 92 71 -115 -35 92 71 -120 -115 84 69 -115 -99 84 85 9 -115 -48 79 -99 -99 94 71 -119 -107 84 -57 9 -65 84 -57 11 -99 -44 87 -115 -35 92 87 -103 -99 84 103 -115 -99 84 101 -119 -99 88 68 -51 -67 -36 15 -119 -115 84 71 -115 -99 84 71 -114 -99 80 71 45 -99 88 71 -120 -99 84 71 -116 -67 84 69 9 -49 84 71 -107 -99 94 103 -119 21 85 79 -91 -3 84 71 -101 -99 -42 71 -115 -99 58 67 -119 -99 84 -57 -115 -115 86 87 9 -97 84 71 -115 -99 92 -57 -87 -97 84 71 -115 -99 84 67 13 -107 84 71 -115 -99 92 102 -120 -99 84 71 -115 -99 88 71 9 -116 84 71 29 -35 92 7 -119 -99 116 119 -115 -97 84 -57 11 -99 -43 79 -115 -67 28 71 -119 -97 80 -57 13 -99 -48 67 9 -99 68 68 -115 -99 24 102 9 -99 86 79 -115 -100 84 71 10 -99 20 71 -115 -99 90 -57 -120 -99 84 68 -115 -99 86 71 9 -113 -44 71 -35 -103 95 71 9 5 84 -57 -115 -67 84 87 -118 -99 -44 71 -115 -99 88 71 -120 -103 84 71 -115 -99 84 71 9 -99 20 71 -83 -107 92 71 25 -123 20 70 -115 -99 84 71 11 -115 20 71 -115 -99 -36 71 -120 -124 84 71 -115 -99 28 71 9 -115 84 71 -99 -83 92 71 -119 -99 -44 -57 13 -97 84 71 11 -99 -108 103 -115 -99 92 69 -103 -35 -44 71 -115 -99 84 69 -103 -99 80 68 -115 -99 92 71 -69 -115 92 79 -115 -104 84 71 -118 -99 84 78 13 -67 80 71 -116 -67 84 71 -116 -99 84 71 1 -115 92 71 -99 -99 94 70 -119 73 85 71 -59 -67 68 7 15 -98 -42 71 -115 -99 90 71 -104 -97 84 71 -115 29 92 69 9 29 92 71 -115 -35 92 71 -55 -99 84 71 13 -99 84 71 11 -35 84 71 -99 -103 90 75 -116 -99 -44 67 -115 -99 84 7 9 -115 84 79 -99 -67 94 70 -119 93 84 69 -51 -99 84 71 43 -99 -44 7 -55 -99 92 79 -119 -36 84 7 -83 -103 -44 14 9 29 84 68 -115 -99 28 71 -23 -99 21 106 10 -98 84 71 42 -108 68 71 -115 -115 89 71 -120 -107 84 71 -115 -101 84 71 9 -123 92 -57 -99 -103 92 71 -119 53 84 99 13 -99 93 103 9 -105 -48 11 -115 -99 88 71 -115 -103 84 71 -115 -103 124 71 9 -99 20 7 13 -107 93 71 -119 -115 116 71 47 -35 92 71 91 -99 92 71 -116 -107 92 71 -120 -115 84 71 -99 -115 84 65 9 -115 85 71 -123 -99 92 71 -119 -107 84 -57 9 -33 84 71 11 -99 -44 87 -115 93 92 75 -103 -103 116 103 -115 -99 84 85 -119 -97 116 68 -115 -75 92 79 -119 57 84 79 -119 -100 84 71 -118 -115 84 7 13 -107 88 71 -120 -67 84 71 -116 -99 68 79 9 -113 84 103 -99 -99 94 71 -119 21 83 6 37 -19 84 87 -117 61 -41 67 -100 -103 122"

char_array = char_string.split(' ')
genome = []
genome_str = ""
print len(char_array)
for char in char_array:
    bitrep = BitArray('int:8=' + char).bin
    print "char:", char, bitrep
    genome_str += (str(bitrep))

for ch in genome_str:
    genome.append(int(ch))

#   positive = int(char) + 256
#    bin_str = str(bin(positive)[2:])
#    over = len(bin_str) -8
#    for ch in bin_str:
#        genome.append(int(ch))

print "length", len(genome)
op_file = open("miguel_parsed.txt", "w")
op_file.write(str(genome))
op_file.close()
Beispiel #17
0
 def prepareInt8as1Bytes(self, i):
     """Converts i to a hex encoded('utf-8') byte string with
        a b' ' appended to the end."""
     word = BitArray(int=i, length=8)
     b = word[0:8].hex.encode('utf-8') + b' '
     return b
Beispiel #18
0
class MainWindow(tk.Tk):
    def __init__(self, mcu):
        tk.Tk.__init__(self)
        self.frame = tk.Frame(self)
        self.mcu = mcu

        self.reg_frame = tk.Frame(self.frame)

        self.regs = self.get_regs(self.reg_frame)
        self.consol = self.Consol(self.mcu, self.frame, self)
        self.buttons = self.Connector(self.mcu, self.frame)
        self.fileholder = self.FileHolder(self.mcu, self.frame)

        self.queue = queue.Queue()

        self.reg_frame.pack()
        self.frame.pack()
        self.task_running = False

    def get_regs(self, frame):
        regs = []
        for reg in range(0x17):
            regs.append(self.Register(reg, frame))
        return regs

    def read_regs(self):
        self._new_task(self._read_regs)

    def read_files(self):
        self._new_task(self.fileholder.read_files)

    def _task_done(self):
        if not self.queue.empty():
            self.queue.get().start()
        else:
            self.task_running = False

    def _new_task(self, function):
        task = threading.Thread(target=function, args=(self._task_done, ))
        if self.queue.empty() and not self.task_running:
            self.task_running = True
            task.start()
        else:
            self.queue.put(task)

    def _read_regs(self, cb):
        for reg in self.regs:
            value = self.mcu.write('nrf._read_reg(%s)' % reg.reg)
            reg.set_val(int(value))
        cb()

    from bitstring import BitArray
    BitArray(length=8)

    class Connector:
        def __init__(self, mcu, frame):
            self.frame = tk.Frame(frame)
            self.connect = tk.Button(self.frame,
                                     text="Connect",
                                     command=self._connect)
            self.disconnect = tk.Button(self.frame,
                                        text="Disconnect",
                                        command=self._disconnect)
            self.reset = tk.Button(self.frame,
                                   text="Reset",
                                   command=self._reset)
            self.ping = tk.Button(self.frame, text="Ping", command=self._ping)

            self.connect.grid(row=0, column=0)
            self.disconnect.grid(row=0, column=1)
            self.reset.grid(row=0, column=2)
            self.ping.grid(row=0, column=3)
            self.frame.pack()

        def _connect(self):
            pass

        def _disconnect(self):
            pass

        def _reset(self):
            pass

        def _ping(self):
            pass

    class FileHolder:
        def __init__(self, mcu, frame):
            self.mcu = mcu
            self.frame = tk.Frame(frame)
            self.title = tk.Label(self.frame, text='Files')
            self.title.pack()
            self.frame.pack(side='left')

        def read_files(self, cb):
            self.files = []
            self.mcu.write('import os')
            dirs = self.mcu.write('os.listdir()')
            dirs = dirs[1:-1].split(',')
            for file_ in dirs:
                label = tk.Label(self.frame, text=file_.replace("'", ''))
                label.pack()
                self.files.append(label)
            cb()

    class Consol:
        def __init__(self, mcu, frame, root):
            self.mcu = mcu
            self.frame = tk.Frame(frame)
            self.c = tk.Entry(self.frame, width=60)
            self.btn = tk.Button(self.frame, text="Send", command=self._send)

            self.output = tk.Text(self.frame, width=80, height=10)

            self.c.grid(row=0, column=0)
            self.btn.grid(row=0, column=1)
            self.output.grid(row=1, columnspan=2)
            self.frame.pack()

            self.c.bind('<Control-KeyRelease-a>', self._mark)
            self.c.bind('<Return>', self._send)
            self.c.focus_set()

        def _mark(self, event):
            # select text
            event.widget.select_range(0, 'end')
            # move cursor to the end
            event.widget.icursor('end')

        def _send(self, *e):
            command = self._parse_cmd(self.c.get())
            if command == 'clear':
                self.output.delete('1.0', 'end')
            else:
                res = self.mcu.write(command)
                self.output.insert('end', '\n' + res)
            self.c.delete(0, 'end')

        def _parse_cmd(self, data):
            return data

    class Register():
        def __init__(self, reg, frame):
            self.reg = reg
            self.frame = tk.Frame(frame)
            self.label = tk.Label(self.frame,
                                  text='Reg %s' % hex(reg),
                                  width=10)
            self.int = tk.Label(self.frame, width=10)
            self.entry = tk.Entry(self.frame, width=20)

            self.label.grid(column=0, row=0)
            self.int.grid(column=1, row=0)
            self.entry.grid(column=2, row=0)
            self.frame.pack()

        def set_val(self, value):
            self.entry.delete(0, 'end')
            formated = str(bin(value))[2:].zfill(8)
            self.entry.insert('end', formated)
            self.int.config(text=str(value))
def getgps(old_dt):
    #    k = sub.find('0x851200',bytealigned = True)
    #    if len(k) == 0:
    #        gps = 'N/A'
    #        return gps

    try:
        sub.find('0x85000004', bytealigned=True)

        sub.pos += 32
        #read 0x850000 - GPS Ver
        gpsver = sub.read(4 * 8)

        sub.pos += 32
        #read 0x8501 - Latitude Ref (N or S)
        latref = BitArray(sub.read(8))
        latref = latref.tobytes().decode('utf-8')
        sub.pos += 32
        # read 0x8502 - latiture (6 chunks)
        l1 = sub.read(4 * 8).uint
        l2 = sub.read(4 * 8).uint
        l3 = sub.read(4 * 8).uint
        l4 = sub.read(4 * 8).uint
        l5 = sub.read(4 * 8).uint
        l6 = sub.read(4 * 8).uint

        if (l2 == 0 or l4 == 0 or l6 == 0):
            gps = 'N/A'
            return gps

        #write latitute string for text output
        lat = str(l1 / l2) + '°' + str(l3 / l4) + "'" + str(
            float(l5) / float(l6)) + '"'
        latdd = round((float(l1) / float(l2) + (float(l3) / float(l4)) / 60 +
                       (float(l5) / float(l6) /
                        (60 * 60)) * (-1 if latref in ['W', 'S'] else 1)), 7)

        sub.pos += 32
        #read 0x8503 - longtitude ref (E or W)
        lonref = BitArray(sub.read(8))
        lonref = lonref.tobytes().decode('utf-8')
        # read 0x8504 - lontgiture (6 chunks)
        sub.pos += 32
        l1 = sub.read(4 * 8).uint
        l2 = sub.read(4 * 8).uint
        l3 = sub.read(4 * 8).uint
        l4 = sub.read(4 * 8).uint
        l5 = sub.read(4 * 8).uint
        l6 = sub.read(4 * 8).uint

        if (l2 == 0 or l4 == 0 or l6 == 0):
            gps = 'N/A'
            return gps

        #write latitute string for text output
        lon = str(float(l1) / float(l2)) + '°' + str(
            float(l3) / float(l4)) + "'" + str(float(l5) / float(l6)) + '"'
        londd = round((float(l1) / float(l2) + float(l3) / float(l4) / 60 +
                       (float(l5) / float(l6) /
                        (60 * 60)) * (-1 if lonref in ['W', 'S'] else 1)), 7)
        k = sub.find('0x85050001', bytealigned=True)
        if len(k) != 0:
            sub.pos += 32
            #read 0x8505 - 1 bytes = AltitudeRef (0 = above sea level, 1 = below sea level)
            x8505 = sub.read(8).uint

            sub.pos += 32
            #read 0x8506 - 8 bytes ([4]/[4]) - Altitude
            x8506_1 = sub.read(4 * 8).uint
            x8506_2 = sub.read(4 * 8).uint

            x8506 = str(float(x8506_1) / float(x8506_2))
        else:
            x8505 = None

        sub.pos += 32
        # read 0x8507 - timestamp (6 chunks)
        l1 = sub.read(4 * 8).uint
        l2 = sub.read(4 * 8).uint
        l3 = sub.read(4 * 8).uint
        l4 = sub.read(4 * 8).uint
        l5 = sub.read(4 * 8).uint
        l6 = sub.read(4 * 8).uint
        if (l2 == 0 or l4 == 0 or l6 == 0):
            gps = 'N/A'
            return gps
        #write timestamp for text output (hh:mm:ss.xxx)
        gpsts = str(int(float(l1) / float(l2))).zfill(2) + ':' + str(
            int(float(l3) / float(l4))).zfill(2) + ":" + str(
                int(float(l5) / float(l6))).zfill(2)
        #print (gpsts)

        sub.pos += 32
        #read 0x8509 - GPS fix STATUS (not used yet)
        gpsfix = BitArray(sub.read(8))
        gpsfix = gpsfix.tobytes().decode('utf-8')

        sub.pos += 32
        # read 0x850a - GPS Measure mode (2 = 2D, 3 = 3D) - not used yet
        gpsmeasure = BitArray(sub.read(8))
        gpsmeasure = gpsmeasure.tobytes().decode('utf-8')

        sub.pos += 32
        #read 0x850b -  8 bytes ([4]/[4]) -- DOP -not used yet
        x850b_1 = sub.read(4 * 8).uint
        x850b_2 = sub.read(4 * 8).uint

        x850b = str(float(x850b_1) / float(x850b_2))

        if sub.read(4 * 8) == '0x850c0001':
            #read 0x850c -  1 byte - SpeedRef (K = km/h, M = mph, N = knots)
            x850c = BitArray(sub.read(8))
            x850c = x850c.tobytes().decode('utf-8')

            sub.pos += 32
            #read 0x850d - 8 bytes ([4]/[4]???) - SPEED
            x850d_1 = sub.read(4 * 8).uint
            x850d_2 = sub.read(4 * 8).uint

            x850d = round(float(x850d_1) / float(x850d_2), 2)
        else:
            x850d = 'N/A'

        if sub.read(4 * 8) == '0x850e0001':
            #read 0x850e - 1 byte - TrackRef (Direction Reference, T = True direction, M = Magnetic direction)
            x850e = BitArray(sub.read(8))
            x850e = x850e.tobytes().decode('utf-8')

            sub.pos += 32
            #read 0x850f - Course 8 bytes ([4]/[4]) (degrees from 0.0 to 359.99)
            x850f_1 = sub.read(4 * 8).uint
            x850f_2 = sub.read(4 * 8).uint

            x850f = round(float(x850f_1) / float(x850f_2), 2)
        else:
            x850f = 'N/A'

        #write full lat + lon + timestamp for text output

        if latref == None or lonref == None: gps = 'N/A'
        else:
            gps = lat + str(latref) + ' ' + lon + str(lonref) + ' ' + gpsts
        # debug
        #gps = gps + '\n' +str(x8505) + ' ' + str(x8506) + ' ' + str(gpsfix) + ' ' + str(gpsmeasure) + ' ' + str(x850b) + ' ' + str(x850c) + ' ' + str(x850d) + ' ' + str(x850e) + ' ' + str(x850f)
        if x850d != 'N/A' or x850f != 'N/A':
            gps = gps + '\n' 'Speed: ' + str(x850d) + 'km/h   Course: ' + str(
                x850f)

        k = sub.find('0x851d000a', bytealigned=True)
        sub.pos += 32
        gpxdate = BitArray(sub.read(8 * 10))
        gpxdate = gpxdate.tobytes().decode('utf-8')
        gpxdate = gpxdate.replace(':', '-')
        gpxdate = gpxdate + 'T' + gpsts + 'Z'
        dt = datetime.strptime(gpxdate, '%Y-%m-%dT%H:%M:%SZ')

        #print (lat,lon, x850d, x850f)

        #write GPX.

        if (args.gpx
                and 'ExifGPS'.encode() in exifchk) and old_dt < dt.timestamp():
            if x8505 != None:
                gpx_point = gpxpy.gpx.GPXTrackPoint(
                    latdd,
                    londd,
                    position_dilution=x850b,
                    type_of_gpx_fix=(gpsmeasure + 'd'),
                    elevation=(float(x8506) * (-1 if x8505 == 1 else 1)),
                    time=datetime(dt.year, dt.month, dt.day, dt.hour,
                                  dt.minute, dt.second))
            else:
                gpx_point = gpxpy.gpx.GPXTrackPoint(
                    latdd,
                    londd,
                    position_dilution=x850b,
                    type_of_gpx_fix=(gpsmeasure + 'd'),
                    time=datetime(dt.year, dt.month, dt.day, dt.hour,
                                  dt.minute, dt.second))
            gpx_segment.points.append(gpx_point)

            #GPX EXT TEST AREA

            namespace = '{gpxtx}'
            nsmap = {'gpxtpx': namespace[1:-1]}  #
            root = mod_etree.Element(namespace + 'TrackPointExtension')

            subnode1 = mod_etree.SubElement(root, namespace + 'speed')
            subnode2 = mod_etree.SubElement(root, namespace + 'course')
            if x850d != 'N/A' and x850c == 'K':
                subnode1.text = str(round(x850d_1 / x850d_2 / 3.6, 2))
            elif x850d != 'N/A' and x850c == 'M':
                subnode1.text = str(round(x850d_1 / x850d_2 / 2.23694, 2))
            elif x850d != 'N/A' and x850c == 'N':
                subnode1.text = str(round(x850d_1 / x850d_2 / 1.94384, 2))

            if x850f != 'N/A':
                subnode2.text = str(x850f)
            gpx.nsmap = nsmap
            if x850d != 'N/A' or x850f != 'N/A':
                gpx_point.extensions.append(root)
            old_dt = dt.timestamp()

    except (bitstring.ReadError, UnicodeDecodeError):
        return 'N/A'

    return gps, old_dt
Beispiel #20
0
rects = axes.bar(index,dataset,bar_width)
plt.xticks(index + bar_width/2.0, ("A", "B", "A'", "B'", "C4", "C5", "C6", "C7"))


s = serial.Serial("COM1",19200,bytesize=serial.SEVENBITS,stopbits=serial.STOPBITS_ONE)
buffer = []
count = 0
alldata = np.zeros([8,10])
while True:
    index = count%10
    count += 1
    print "index = ", index
    try:
        data = s.read()
        if data == "\x7f":
            bits = BitArray(bytes=buffer)
	    # test length:
	    if bits.length == 8*40:
		time.sleep(0.1)
            	a, b, c, d, c4, c5, c6, c7 = bits.unpack('uintle:40,uintle:40,uintle:40,uintle:40,uintle:40,uintle:40,uintle:40,uintle:40')
		#print a, b, c, d, c4, c5, c6, c7
                newdata = np.array((a, b, c, d, c4, c5, c6, c7))
		alldata[:,index] = newdata
		if index == 0:
		    print alldata
		    # update plot every 10 shots
		    for rect, h in zip(rects, alldata.mean(axis=1)):
                        rect.set_height(h)

                    axes.relim()
                    axes.autoscale_view(True,True,True)
from dahuffman import HuffmanCodec
from bitstring import BitArray
from math import ceil, floor, log
import cPickle as pickle


OFFSET_ZERO = BitArray(bin='0')
OFFSET_ONE = BitArray(bin='1')

MAX_DATA_N = 15

def get_decimal_places(d):
    r = d.split(".")
    if len(r) > 1:
        return len(r[1])
    return 0


class TinyCompressor:
    """This class holds data and methods for 
    a data compressor using LEC Algorithm"""

    table = {}
    decode_table = {}
    eof = 0
    __first_data = []
    __previous_data = []
    __data = []
    __data_ns = []
    __decimal_places = []
    __strings_table = {}
Beispiel #22
0
import numpy as np
import struct
import pandas as pd
import beacontools
from beacontools import parse_packet
from converters import BinToFloat, BinToInt
from numpy import dtype
from bitstring import BitArray

test = b"5\x01\'\x02\xfd\x02/\x02e\x01%\xfd8\xc8Xn<\xc3"

print(BitArray(test).bin[:1])


def chunker(seq, size):
    return (seq[pos:pos + size] for pos in range(0, len(seq), size))


def test_bin_float_converstion():
    val = 100
    test = struct.pack(">f", val)
    binary = float_to_bin(val)
    print(binary)
    print(BinToFloat().process(test))
    print(struct.unpack(">f", test))
    print(BinToFloat().process(test, True))
    print(struct.unpack("f", test))


def test_bin_int_converstion():
    print()
Beispiel #23
0
def parse_domain_link(data, position):
    length = int(BitArray(position).bin[2:], 2)
    domain, count = parse_domain(data, length)
    return 1, domain
def is_full(board):
    t_board = board[0:area]
    o_board = board[area:2 * area]
    return t_board | o_board == BitArray('0b1') * area
Beispiel #25
0
import tensorflow as tf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from bitstring import BitArray

with tf.Graph().as_default():
    with tf.Session() as sess:
        map_string = "484_561_459_322_64_158_41_315_384_437_192_510_504_534_308_334_487_128_207"
        region_ids = [int(x) for x in map_string.split("_")]
        print(region_ids)

        fn = 'binary_arrays/' + str(region_ids[0]) + '.txt'
        with open(fn, 'r') as bits:
            bits_string = bits.read()
            map_bin = BitArray(bin=bits_string)

        all_or = map_bin

        for i in region_ids:
            fn = 'binary_arrays/' + str(i) + '.txt'

            with open(fn, 'r') as bits:
                bits_string = bits.read()
                bit_array = BitArray(bin=bits_string)

            all_or = all_or | bit_array

        print(all_or.count("1"))

        bit_array = [int(x) for x in list(str(all_or.bin))]
def bytes_to_board(data):
    a = BitArray()
    a.bytes = data.encode('ISO-8859-1')
    return a
Beispiel #27
0
    def parse(cls, address, data):
        '''Used to parse data received from RuuviTag.
        Currently supports versions 3 and 5 of the protocol.

        Arguments:
            address (str): MAC address of RuuviTag.
            data (bytes): received data in bytes.
        '''
        b = BitArray(bytes=data)

        # Try to find protocol version 3
        # https://github.com/ruuvi/ruuvi-sensor-protocols#data-format-3-protocol-specification
        if b.find('0xFF990403'):
            # If it's found, parse data
            b = list(b.split('0xFF990403', count=2))[-1]
            _, humidity, temperature, temperature_fraction, pressure, \
                accel_x, accel_y, accel_z, battery_voltage = b.unpack(
                    # Ignore the packet type and manufacturer specs,
                    # as they've been handled before
                    'uint:32,' +
                    # Parse the actual payload
                    'uint:8, int:8, uint:8, uint:16,' +
                    'int:16, int:16, int:16, uint:16')

            # ... and return an instance of the calling class
            return cls(address,
                       3,
                       temperature=float(temperature) +
                       temperature_fraction / 100.0,
                       humidity=humidity / 2.0,
                       pressure=(pressure + 50000) / 100.0,
                       acceleration_x=accel_x / 1000.0,
                       acceleration_y=accel_y / 1000.0,
                       acceleration_z=accel_z / 1000.0,
                       battery_voltage=battery_voltage / 1000.0)

        # Try to find protocol version 5
        # https://github.com/ruuvi/ruuvi-sensor-protocols#data-format-5-protocol-specification
        if b.find('0xFF990405'):
            # If it's found, parse data
            b = list(b.split('0xFF990405', count=2))[-1]
            _, temperature, humidity, pressure, \
                accel_x, accel_y, accel_z, \
                battery_voltage, tx_power, \
                movement_counter, measurement_sequence, mac = b.unpack(
                    # Ignore the packet type and manufacturer specs,
                    # as they've been handled before
                    'uint:32,' +
                    # Parse the actual payload
                    'int:16, uint:16, uint:16,' +
                    'int:16, int:16, int:16,' +
                    'uint:11, uint:5,' +
                    'uint:8, uint:16, uint:48')

            # Not sure what to do with MAC at the moment?
            # Maybe compare it to the one received by btle and
            # raise an exception if doesn't match?
            mac = '%x' % mac
            mac = ':'.join(mac[i:i + 2] for i in range(0, 12, 2))

            # ... and return an instance of the calling class
            return cls(address,
                       5,
                       temperature=float(temperature) * 0.005,
                       humidity=humidity * 0.0025,
                       pressure=(pressure + 50000) / 100.0,
                       acceleration_x=accel_x / 1000.0,
                       acceleration_y=accel_y / 1000.0,
                       acceleration_z=accel_z / 1000.0,
                       battery_voltage=(battery_voltage + 1600) / 1000.0,
                       tx_power=-40 + tx_power,
                       movement_counter=movement_counter,
                       measurement_sequence=measurement_sequence)
Beispiel #28
0
    def direct_mapping(self,
                       address,
                       write=0,
                       value=-1,
                       bytes_=4,
                       unsigned_=0):

        address = BitArray(int=address, length=32).bin

        index = address[self.tag_bits:self.tag_bits + self.block_bits]

        if (write == 1):
            # if index in self.cache_list.keys() and (self.cache_list[index][0] == address[0:self.tag_bits]):
            self.cache_list[index][
                1 +
                int(address[self.tag_bits +
                            self.block_bits:30])] = self.to_be_written(value)

            self.memory_object.writeWord(int(address, 2), value)
            return

        if index in self.cache_list.keys():
            if (self.cache_list[index][0] == address[0:self.tag_bits]
                ):  #tag field
                print('cache hit')
                return self.cache_list[index][1 +
                                              int(address[self.tag_bits +
                                                          self.block_bits:30])]
            else:
                print('cache miss')
                self.cache_list[index][0] = address[0:self.tag_bits]
                zero = ''
                for i in range(self.word_bits + 2):
                    zero += '0'
                temp_address = int(address[:self.tag_bits + self.block_bits] +
                                   zero)
                for i in range(self.block_size):
                    value = self.memory_object.readWord(temp_address)
                    self.cache_list[index][1 + i] = self.to_be_written(value)
                    temp_address += 4
                return self.return_value(
                    self.cache_list[index][1 +
                                           int(address[self.tag_bits +
                                                       self.block_bits:30])],
                    bytes_, unsigned_)

        else:
            self.cache_list[index] = []
            self.cache_list[index].append(address[0:self.tag_bits])
            zero = ''
            for i in range(self.word_bits + 2):
                zero += '0'
            temp_address = int(
                address[:self.tag_bits + self.block_bits] + zero, 2)
            for i in range(self.block_size):
                value = self.memory_object.readWord(temp_address)
                self.cache_list[index].append(self.to_be_written(value))
                temp_address += 4
            return self.return_value(
                self.cache_list[index][1 + int(address[self.tag_bits +
                                                       self.block_bits:30])],
                bytes_, unsigned_)
    def alu(self,operation):
        print("\n|--------- (ALU Part)Execution of the instruction----------|\n")
        print("OP:",operation)
        if operation == "add":
            if self.muxB == 0:
                self.RZ = self.RA + self.RB   #add
            if self.muxB == 1:
                self.RZ = self.RA + self.imm  #addi
        elif operation == "mul":
            self.RZ = self.RA * self.RB
        elif operation == "sub":
            self.RZ = self.RA - self.RB
        elif operation == "or":
            if self.muxB == 0:
                self.RZ = self.RA | self.RB   #or
            elif self.muxB == 1:
                self.RZ = self.RA | self.imm  #ori
        elif operation == "rem":
            self.RZ = self.RA % self.RB
        elif operation == "xor":
            self.RZ = self.RA ^ self.RB
        elif operation == "div":
            self.RZ = self.RA // self.RB
        elif operation == "srl":
            self.RZ = BitArray(int=self.RA, length=32) >> self.RB
            self.RZ = self.RZ.int
        elif operation == "sra":
            self.RZ = self.RA >> self.RB
        elif operation == "and":
            if self.muxB == 0:
                self.RZ = self.RA & self.RB  #and
            elif self.muxB == 1:
                self.RZ = self.RA & self.imm #andi
        elif operation == "sll":
            self.RZ = BitArray(int=self.RA, length=32) << self.RB
            self.RZ = self.RZ.int
        elif operation == "slt":
            if self.RA < self.RB :
                self.RZ = 1
            else :
                self.RZ = 0
        elif operation == "jalr":
            self.PC_temp = self.PC
            self.PC = self.RA + self.imm
        elif operation == "beq":
            if self.RA == self.RB:
                self.PC = self.PC - 4 + self.imm
        elif operation == "bge":
            if self.RA >= self.RB:
                self.PC = self.PC - 4 + self.imm
        elif operation == "blt":
            if self.RA < self.RB:
                self.PC = self.PC - 4 + self.imm
        elif operation == "bne":
            if self.RA != self.RB:
                self.PC = self.PC - 4 + self.imm
        elif operation == "auipc":
            self.RZ = self.PC - 4 + self.imm
        elif operation == "jal":
            self.PC_temp = self.PC
            self.PC = self.PC - 4 + self.imm
        else :
            print("no operation found in the AlU part")

        self.memoryAccess()
Beispiel #30
0
 def __init__(self, x, y, height, weight, rocky):
     self.x = BitArray('0b' + bin(x).lstrip('0b').zfill(8))
     self.y = BitArray('0b' + bin(y).lstrip('0b').zfill(8))
     self.height = BitArray('0b' + bin(height).lstrip('0b').zfill(4))
     self.weight = BitArray('0b' + bin(weight).lstrip('0b').zfill(4))
     self.rocky = BitArray('0b' + bin(rocky).lstrip('0b').zfill(4))