-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
26 lines (21 loc) · 799 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from RS.RSCoder import RSCoder
prim = 0x11d
n = 20
k = 11
message = "hello world"
rs = RSCoder(prim)
mesecc = rs.encode([ord(x) for x in message], n - k)
print("Original: %s" % mesecc)
# Tampering 6 characters of the message (over 9 ecc symbols, so we are above the Singleton Bound)
mesecc[0] = 0
mesecc[1] = 2
mesecc[2] = 2
mesecc[3] = 2
mesecc[4] = 2
mesecc[5] = 2
print("Corrupted: %s" % mesecc)
# Decoding/repairing the corrupted message, by providing the locations of a few erasures, we get below the Singleton Bound
# Remember that the Singleton Bound is: 2*e+v <= (n-k)
corrected_message, corrected_ecc = rs.decode(mesecc, n - k, erase_pos=[0, 1, 2])
print("Repaired: %s" % (corrected_message+corrected_ecc))
print(''.join([chr(x) for x in corrected_message]))