示例#1
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)
示例#2
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