Пример #1
0
def click_binario():  # Makes sure the input is a 12 bit binary number
    try:
        user_input = entry.get()
        number = int(user_input)
        is_binary = True
        for i in range(len(user_input)):
            if user_input[i] != str(1) and user_input[i] != str(0):
                is_binary = False
                break
        if len(user_input) == 12 and isinstance(number, int) and is_binary:
            # entry.delete(0, 'end')
            deci = int(user_input, 2)
            hexa = hex(deci)[2:].upper()
            octa = oct(deci)[2:].upper()

            table.delete(*table.get_children())
            table.insert("", 0, values=(user_input, deci, hexa, octa))
            table.pack()

            draw_nrzi = NRZI(user_input, nrzi_canvas)
            draw_nrzi.draw()

            Hamming(root, user_input, radio_group.get(), digit_group.get())

        else:
            messagebox.showerror("Error",
                                 "El número debe ser binario y de 12 dígitos")
    except ValueError:
        messagebox.showerror("Error", "Ingrese un número válido")
Пример #2
0
def test_hamming():
    print("Testing Hamming")
    h = Hamming(3)
    my_str = "111100001010"
    e = h.encode(my_str)
    print("original string: ", my_str)
    print("original encoded: ", e)
    e = e[:-1] + "1"
    e = "0" + e[1:]
    print("errored encoded:  ", e)
    d = h.decode(e)
    print("decoded string:  ", d)
Пример #3
0
def send(word, parity):
    hamming = Hamming(word, parity)
    if hamming.word_generate():
        print()
        print('=' * 50)
        print('Typed word: ', end='')
        print(word)
        print('generated word: ', end='')
        print(hamming.word_distributed)
        print('=' * 50)
        print()
        return True
    return False
Пример #4
0
def test_hamming_single_block_encode_only():
    #   i             0 1 2 3 4 5 6 7
    #   data = 11     1 0 1 - 1
    #   coverage            a   b c
    #   a             X X X S - - - -
    #   b             X X - - X S - -
    #   c             X - X - X - S -
    #   result        1 0 1 0 1 0 1 0

    ham = Hamming(block_size=8)
    in_block = np.unpackbits(np.array([0b1011], dtype=np.uint8))  #4'b1011
    bits = ham._encode_block(in_block[4:8])
    expected_bits = np.unpackbits(np.array([0b10101010], dtype=np.uint8))
    assert (bits == expected_bits).all()
Пример #5
0
def receive(word, parity):
    hamming = Hamming(word, parity)
    if hamming.check_word():
        print()
        print('=' * 50)
        print(hamming.word_distributed)
        if hamming.error_counter > 0:
            print('incorrect word')
            print('error found in position {}'.format(hamming.error_position))
        else:
            print('correct word')
        print('=' * 50)
        print()
        return True
    return False
Пример #6
0
from hamming import Hamming

if __name__ == "__main__":
    palavra = Hamming()
    palavra.gerador()
    palavra.decomposicao()
    palavra.validacao()
    palavra.colocando_erro()
    palavra.validacao()
Пример #7
0
from hamming import Hamming

data = raw_input('Type the message received: ')
h = Hamming()
result = h.decode(data)
msg = 'Result: ' + result + '\n'
if (int(result, 2) != 0):
    msg += 'There\'s an error on position ' + str(int(result, 2)) + '.\n'
    correct = h.correct(data, int(result, 2))
    msg += 'The correct data should be ' + correct + '.'
else:
    msg += 'The data received is correct.'
print msg
 def setUp(self):
     self.temp = Hamming()
     try:
         self.assertRaisesRegex
     except AttributeError:
         self.assertRaisesRegex = self.assertRaisesRegexp
Пример #9
0
 def __init__(self, sockt):
     self.sock = sockt
     self.addr = socket.gethostname()
     self.hamming = Hamming()
Пример #10
0
def test_hamming_multiple_block_encode_only():
    ham = Hamming(block_size=16)
    in_block = bytearray(b"e")
    bits = ham.encode(in_block)
    assert len(bits) == 2