Error Correction Codes
How do I ensure my message get's delivered correctly given that someone might tamper with it?
Erasure Errors (Someone erases parts of our message)
Imagine someone erases parts of our message. How do we prevent that?
Step 0 - Setup
Your packets will come in pairs (index,message) where the message is in modspace of a prime.
A simple example is (1,7) in mod31.
You may notice that these messages oddly look a lot like (x,y) coordinates on a Cartesian plane.
It may be helpful (in order to get a first initial grasp of things) to think of them as (x,y) points on a xy plane that is finitely large.
Notice a pattern:
- Two points defines a 1st degree polynomial (a1x+a0)
- Three points defines a 2nd degree polynomial (a2x2+a1x+a0)
- Four points defines a 3rd degree polynomial (a3x3+a2x2+a1x+a0)
More formally, d points uniquely identify a d−1 degree polynomial. If we have the polynomial, we have the packets.
As long as you receive more than or equal to d points, then you can recreate the d−1 degree polynomial.
Hence to combat k erasure errors, we can just send at least d+k points to recover our polynomial. Step 1 - Lagrange Interpolation
The point of Lagrange interpolation create a d−1 polynomial from the d points.
In order to send d+k points, we need k extra points.
To find k extra points we need the unique polynomial, which we use lagrange interpolation for.
Say our message is 736.
Our packets are: (1,7),(2,3),(3,6). Since the values are small, we'll choose modspace 11.
We can define a new variable and fit it into the following form:
Δ1Δ2Δ3≡(1−2)(1−3)(x−2)(x−3)≡2(x−2)(x−3)≡6(x−2)(x−3)mod11≡(2−1)(2−3)(x−1)(x−3)≡−1(x−1)(x−3)≡10(x−1)(x−3)mod11≡(3−1)(3−2)(x−1)(x−2)≡2(x−1)(x−2)≡6(x−1)(x−2)mod11 Notice that for all indexes other than its own, it reduces to zero.
Notice that for its own index, it reduces to one.
This important relationship allows us to write our polynomial in the following form:
f(x)=m1Δ1+m2Δ2+m3Δ3modp Hence our ultimate polynomial is:
f(x)=7Δ1+3Δ2+6Δ3mod11=9(x−2)(x−3)+8(x−1)(x−3)+3(x−1)(x−2)mod11Using modulus arithmetic We have our polynomial! If we plugin 1, 2, or 3, we'll receive our original message of 7, 3, and 6!
Step 2 - Create extra points
Now that we have the polynomial f(x) that goes through all our points, we can create k extra points by plugging in more indices to our function.
So if there are at most two erasure errors, we can add (4,f(4)), (5,f(5)) to our original message.
message: (1,7),(2,3),(3,6),(4,f(4)),(5,f(5)) Step 3 - Send message over noisy channel
Here, someone might erase parts of our message.
message: (1,7),(4,f(4)),(5,f(5)) Step 4 - Recover using Lagrange Interpolation
We reuse Lagrange Interpolation to recreate the polynomial and find the message values for indices 2 and 3.
...Lagrangian Interpolationf(x)=...message: (1,7),(2,f(2)),(3,f(3))message: (1,7),(2,3),(3,6) We've recreated our message. Information was preserved.