[python] QR code application of Reed-solomon codes (2)

        (Note: This part of the blog mainly combines the PPT of Mr. Zhou and the information found, trying to explain the mathematical principles and information theory principles of Reed-Solomon Codes, and discuss the application of Reed-Solomon Codes in QR codes.)

        Today we will discuss the Galois Field GF(2^m), which can actually be regarded as mod(2^m). We have been exposed to the principles of microcomputers, and we all know that a binary number with a length of m bits can represent 2^m number, and the general data code erasure code is 8bit as a unit, so they all belong to the symbols in GF (2^8). Then we can use 2^8, why use mod (remainder)? This is a feature of Galois Field. The remainder of any number divided by 2^m will be less than 2^m, so the value of mod(2^m) must also belong to Galois Field GF(2^m).

        So what is the convenience of Galois Field? The picture I found first:

              

        First explain, the second column and the third column are corresponding, when a=2, the second column is the process of converting the binary in the third column into decimal, such as 0000 0100 = 2^7*0+2 ^6*0+2^5*0+2^4*0+2^3*0+2^2*1+2^1*0+2^0*0. Column 1 and (column 2, column 3) is the given table, which is calculated by binary log-based multiplication (more on this later). The last column is the binary converted decimal of the third column. (It should be noted here that the space size of a^k and k in the first column is 254, and the value of the last column is taken in [0,255). )

       Speaking of finite fields, the concept of fields must be explained. The field has the concept of identity element and inverse element, which makes it possible to add or multiply, both of which can be obtained through matrix operations. *" means (but not the addition and multiplication operations that we usually know). For addition and multiplication, they all have their own identity matrix e (addition and multiplication are not equal, the identity matrix for addition is 0, and the identity matrix for multiplication is 1), but what is the use of the identity matrix? For example, we know the reciprocal, a=1/b. When we want to divide a number, we multiply by the reciprocal of the number. Similarly, in the known domain, c*d=e (that is, the multiplication of c and d equals the unit) matrix), if we want to divide by c, then we can multiply by the inverse d of c.

        Galois Field as well.

        If we want to add, subtract, multiply and divide polynomials in the Galois Field, we must know how the Galois Field polynomial (the second column) performs four operations.

        1. For addition and subtraction, we use a^11= x^6+x^2+1, and a^2= x^2 to give a chestnut:

              1) When merging similar items, we will 1*x^2+1*x^2 = (1+1)*x^2=0*x^2=0, it can be seen that the addition is represented by XOR , that is, 1+1=0, 1+0=1, 0+0=0.

               2) When performing subtraction, subtraction is addition, which is also XOR.

        2. For multiplication, we use 0001001 x 00101010 as an example: (^ is XOR, * is multiplication)

        10001001
 *      00101010
   -------------
       10001001
 ^   10001001
 ^ 10001001
   -------------
   1010001111010
               Described in Python is:
def poly_mult(x,y):
 z = 0
 i = 0
 while (y>>i) > 0:       #指针从y的最右侧开始右移i位,只要除数内还有1,就继续执行
   if y & (1<<i):         #判断y右移了i位后的右边第一位是否为1,如果为1则将x与z异或
     z ^= x<<i            #将x错位,统一阶位
   i += 1
 return z
         (Explain, the >> right shift sign bit here is relative to binary, >> i means that the binary number is shifted to the right by i bits, for binary, the right shift of i bits represents the number divided by 2^i, For specific functions, see the comments of the function poly_mult().)

  

           Of course, there are more efficient methods, such as the Russian Peasant algorithm of the Russian farmer method (is the fighting race even the farmer so strong...):

def gf_mult_RU(x, y):     
    r = 0    
    while y:           #判断y>0
        if y & 1: #Check if y is odd
            r = r ^ x #Mainly store the last x and XOR
            y = y >> 1 # Divide y by 2, because it is an odd y based on binary right shift, right shift means dividing by 2 after subtracting the last 1, which is very 666, calling for the farmer     
            x = x << 1 # multiply x by 2   
    return r

       This way by looping over and over:

               x*y = (x*2) * (y/2)

              x*y = (x*2) * (y-1)/2 + x

       When y<0, r is the product of the two. After understanding polynomial multiplication, of course there is division, mainly the very elegant Gaussian elimination method, more tomorrow.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325621282&siteId=291194637