# CRC-Based Reliable WiFi Backscatter Communication for Supply Chain Management
## 3 CRCScatter Decoder Design
### CRC Reverse Decoder  
#### 3.2.1 The Algorithms of CRC in the CRC Reverse Decoder  
To detect unpredictable bit errors in received packets, the CRC sequence is transmitted with the data. In particular, FCS uses CRC32 to protect the MAC header and frame body. The CRC32 value can be computed by performing bit shifts and XOR operations on a 32-bit CRC register. The bit-oriented calculation algorithm of the CRC value is given by IEEE 802.11b protocol, as shown in Algorithm 1. The CRC algorithm contains three constants, namely, CRCPOLY, INITXOR, and FINALXOR. For CRC32, the value of these constants is given by CRCPOLY = 0x04C11 DB7, INITXOR = FINALXOR = 0 xFFFFFFFF. In addition, when focusing on the calculation of the CRC register, we can replace INITXOR and FINALXOR with the initial and final states of the CRC register. In each loop of Algorithm 1, bit shift and XOR operations are carried out on the CRC register based on the comparison of the input data bit and the shifted-out bit. The number of bits calculated for a single shift and XOR operation depends on the register length, while the number of cycles corresponds to the length of the input data. When the input data length and CRC type are given, the average run time of Algorithm 1 is stable.  
```
data bits \(a\) CRC register value \(crcreg\)\(\leftarrow\) INITXOR \(i\gets 0\) while\(i\ <\ a.length\)do  LEFTSHIFT(\(crcreg\)) if\(bit\_just\_shifted\_out\
eq a_{i}\)then \(crcreg\gets crcreg\oplus\) CRCPOLY  endif \(i\gets i+1\) endwhile \(crcreg\gets crcreg\oplus\)FINALXOR
```  
**Algorithm 1** Calculation of the CRC  
Figure 4: CRCscatter decoder overview. The decoding procedure can be divided into two steps. The first step is to reverse the original data marked in blue, and the second step is to calculate the tag data marked in red.  
Assuming that the initial CRC register value \(r^{\prime}\) and the data bits \(a\) are known, the CRC algorithm can calculate the final value \(r\). Conversely, if the final CRC register value \(r\) and the calculated data \(a\) are given, we can reverse the procedure of the CRC algorithm to obtain the initial value \(r^{\prime}\). The CRC reverse algorithm [41] is presented in Algorithm 2 because Algorithm 2 is the inverse process of Algorithm 1. Similarly, we can also conclude that the average run time is stable when the input bit length is fixed.  
```
0: final CRC register value \(r\), reversed data bits \(a\)
0: initial CRC register value \(r^{\prime}\) \(i\gets a.length-1\) \(crcreg\gets r\) while\(i\geq 0\)do if\(crcreg_{31}=1\)then \(crcreg\gets crcreg\oplus\) CRCPOLY \(\text{RIGHTSHIFT}(crcreg)\) \(crcreg_{0}=a_{i}\oplus 1\) else \(\text{RIGHTSHIFT}(crcreg)\) \(crcreg_{0}=a_{i}\) endif \(i\gets i-1\) endwhile \(r^{\prime}\gets crcreg\)
```  
**Algorithm 2** CRC32 reverse algorithm  
Both the CRC algorithm and the CRC reverse algorithm can be represented as functions, where \(r^{\prime}\) and \(r\) represent the initial and final value of the CRC register, respectively, while \(a\) represents the calculated data bits. When a set of CRC register values and data bits are given, the two algorithms are opposite computational processes, and the two functions hold simultaneously.  
\[r=crc(r^{\prime},a),\quad r^{\prime}=crc_{-}reverse(r,a). \tag{3}\]