Rewritable and Sustainable 2D Barcode for Traceability Application in Smart IoT Based Fault-Tolerant Mechanism

: With the development of the Internet of Things (IoT) technology, two-dimensional (2D) barcodes are widely used in smart IoT applications as a perception portal. In industries with many circulations and testing links like traceability, since the existing 2D barcode cannot be changed once it is printed, it can only be replaced with more expensive radio frequency identiﬁcation (RFID) labels or new 2D barcodes, causing a waste of human resources and costs. For better circulation e ﬃ ciency and resource utilization, we propose a new design of the rewritable and sustainable 2D barcode based on the fault-tolerance mechanism. The ability to add new information in the 2D barcode can be achieved through data encryption and the insertion of a rewritable layer. It means the message of 2D barcodes could be changed, and increases the ﬂexibility and liquidity of the 2D barcode application. Besides, the encoding and decoding method of the proposed 2D barcode is presented. Experimental results have illustrated the superiority of rewritable and sustainable 2D barcodes in the traceability of herbal medicine compared with the conventional 2D barcodes, and demonstrated the feasibility of the design. The ﬁndings show the potential for signiﬁcant application in the ﬁeld of traceability in smart IoT, as well as in the manufacturing industry and logistics.


Introduction
With the development of Internet of Things (IoT), there will be a large number of devices connected to the Internet.Due to the increasing popularity and wide application of the Internet of Things (IoT), it will affect all fields and shape new lifestyles [1][2][3].The two-dimensional (2D) barcode as a brand-new technology of information storage, transmission, and identification, has penetrated domains such as medicine [4,5], shopping [6], catering, financial payment, and other industry applications [7][8][9][10].In all kinds of application scenarios, higher requirements are being focused on today for improving the related technology of the 2D barcode.
On the basis of existing barcode technology, 2D barcode positioning technology [11], 2D barcode image distortion correction [12], color barcode [13], and other new technology [14] have been widely studied.With the popularity of mobile devices, 2D barcode becomes an integral part of the field.
Current research on rewritable identifications is mainly focused on rewritable tags such as radio frequency identification (RFID) tags and identification (ID) cards.Compared with 2D barcode identifications, RFID tags and ID cards are more expensive, and the rewritable process is complicated.
Only dedicated equipment can erase and rewrite data.For example, the RFID tag implements multiple rewriting of tag information through wired contact or writes data information to the RFID tag in a non-contact manner through a dedicated device [15][16][17].The rewritable ID card is generally a polyvinyl chloride (PVC) format card.This material is sensitive to temperature.When different temperatures are applied, the label can be rewritten and colored, but it needs to be used in conjunction with a printer [18,19].One of the widely concerning problems of the current 2D barcode technology is that the information stored in the 2D barcode is static.Once the information is formed, it cannot be changed.
Regarding the research on rewritable image identification, dynamic two-dimensional codes, as the latest 2D barcode technology, have been widely used in recent years [20][21][22].Unlike the traditional black and white static quick response (QR) code, the dynamic QR code contains a variety of information, and the information embedded in the QR code can be changed at any time without reprinting or generating.As long as the change is made and saved, the QR code can be updated automatically.The new content will be obtained when scanning again.It is widely used in the fields of payment, product packaging, and promotion.However, the dynamic QR code needs to be connected to the Internet to view it.Moreover, a worse issue is that the original information cannot be viewed after changing the content.
For the industry of Information circulation, circulating information is different in various stages.As a traditional 2D barcode, the corresponding 2D barcode needs to be generated in different stages.For instance, in the production and sales process of herbal medicine, the traceability process involves farmland, planting, processing, product storage, transportation, and sales stages, among which all circulation links need to record relevant information.Based on the Internet of Things technology, using QR code as an information perception portal can realize traceability management of the circulation process of herbal medicine [23,24].By recording and monitoring all aspects of herbal medicine production and sale, enterprises can find the source accurately and quickly when problems arise, and then form a chain of quality and safety traceability of herbal medicine, thus greatly improving the competitiveness of pharmaceutical enterprises.The traceability and circulation process is shown in Figure 1.Consequently, for better circulation efficiency and resource utilization, research and design of the rewritable and sustainable 2D barcode are necessary.Current research on rewritable identifications is mainly focused on rewritable tags such as radio frequency identification (RFID) tags and identification (ID) cards.Compared with 2D barcode identifications, RFID tags and ID cards are more expensive, and the rewritable process is complicated.Only dedicated equipment can erase and rewrite data.For example, the RFID tag implements multiple rewriting of tag information through wired contact or writes data information to the RFID tag in a non-contact manner through a dedicated device [15][16][17].The rewritable ID card is generally a polyvinyl chloride (PVC) format card.This material is sensitive to temperature.When different temperatures are applied, the label can be rewritten and colored, but it needs to be used in conjunction with a printer [18,19].One of the widely concerning problems of the current 2D barcode technology is that the information stored in the 2D barcode is static.Once the information is formed, it cannot be changed.
Regarding the research on rewritable image identification, dynamic two-dimensional codes, as the latest 2D barcode technology, have been widely used in recent years [20][21][22].Unlike the traditional black and white static quick response (QR) code, the dynamic QR code contains a variety of information, and the information embedded in the QR code can be changed at any time without reprinting or generating.As long as the change is made and saved, the QR code can be updated automatically.The new content will be obtained when scanning again.It is widely used in the fields of payment, product packaging, and promotion.However, the dynamic QR code needs to be connected to the Internet to view it.Moreover, a worse issue is that the original information cannot be viewed after changing the content.
For the industry of Information circulation, circulating information is different in various stages.As a traditional 2D barcode, the corresponding 2D barcode needs to be generated in different stages.For instance, in the production and sales process of herbal medicine, the traceability process involves farmland, planting, processing, product storage, transportation, and sales stages, among which all circulation links need to record relevant information.Based on the Internet of Things technology, using QR code as an information perception portal can realize traceability management of the circulation process of herbal medicine [23,24].By recording and monitoring all aspects of herbal medicine production and sale, enterprises can find the source accurately and quickly when problems arise, and then form a chain of quality and safety traceability of herbal medicine, thus greatly improving the competitiveness of pharmaceutical enterprises.The traceability and circulation process is shown in Figure 1.Consequently, for better circulation efficiency and resource utilization, research and design of the rewritable and sustainable 2D barcode are necessary.This paper presents a design of rewritable and sustainable 2D barcodes based on the fault-tolerant mechanism and data encryption algorithm.For data writing and information encryption, this new rewritable and sustainable 2D barcode only needs to add the rewritable and sustainable layer to 2D barcode and encrypt information by the encryption algorithm.It makes the circulation efficiency and resource utilization greatly improved.At the same time this design overcomes the problem that the 2D barcode can only express the static information, which increases the flexibility and broadens the application fields of the 2D barcode.

Internet
The organization of this paper is as follows.In Section 2, we mainly discuss the fault-tolerant mechanism of 2D barcodes.In Section 3, the design principle of rewritable and sustainable 2D barcode by the fault-tolerant mechanism is determined.In Section 4, the rewritable and sustainable 2D barcode is tested.Section 5 concludes the proposed rewritable and sustainable 2D barcode.

2D Barcode Fault-Tolerant Mechanism
This section first introduces the basic knowledge of quick response (QR) codes, and then explains the fault-tolerant mechanism of QR codes.The objective is mainly to describe the Reed-Solomon (RS) encoding process of QR codes in detail, paving the way for the design of the writable area in Section 3.

The Structure of QR Code
QR code is a two-dimensional (2D) code invented by Japanese Denso Wave Company in 1994.In the international standard ISO/IEC-18004:2015, the QR code is defined accordingly.As shown in Figure 2, the QR code is generated by the black and white modules according to certain coding rules.It is mainly composed of functional patterns and an encoding region.This paper presents a design of rewritable and sustainable 2D barcodes based on the faulttolerant mechanism and data encryption algorithm.For data writing and information encryption, this new rewritable and sustainable 2D barcode only needs to add the rewritable and sustainable layer to 2D barcode and encrypt information by the encryption algorithm.It makes the circulation efficiency and resource utilization greatly improved.At the same time this design overcomes the problem that the 2D barcode can only express the static information, which increases the flexibility and broadens the application fields of the 2D barcode.
The organization of this paper is as follows.In Section II, we mainly discuss the fault-tolerant mechanism of 2D barcodes.In Section III, the design principle of rewritable and sustainable 2D barcode by the fault-tolerant mechanism is determined.In section IV, the rewritable and sustainable 2D barcode is tested.Section V concludes the proposed rewritable and sustainable 2D barcode.

2D Barcode Fault-Tolerant Mechanism
This section first introduces the basic knowledge of quick response (QR) codes, and then explains the fault-tolerant mechanism of QR codes.The objective is mainly to describe the Reed-Solomon (RS) encoding process of QR codes in detail, paving the way for the design of the writable area in Section 3.

The Structure of QR Code
QR code is a two-dimensional (2D) code invented by Japanese Denso Wave Company in 1994.In the international standard ISO/IEC-18004:2015, the QR code is defined accordingly.As shown in Figure 2, the QR code is generated by the black and white modules according to certain coding rules.It is mainly composed of functional patterns and an encoding region.The functional patterns also include five parts: quiet zone, position detection patterns, and their separators, timing patterns, and alignment patterns.The encoding region format includes three parts: format information, version information, data and error correcting codewords.A QR code has three position detection patterns, its black and white module ratio is 1:1:3:1:1 in any direction.In other locations, there is no such feature, so that it can be quickly identified.
For the encoding region, it contains data and error correcting codewords, format information, and version information.The data and error correction codewords are used to store the original QR code information and correct the error codewords caused by image damage.Format information is composed of error correction level and mask image information, while the version information is used to determine the number of modules that form the QR code.The relationship between its version and module size is shown in Equation ( 1): The functional patterns also include five parts: quiet zone, position detection patterns, and their separators, timing patterns, and alignment patterns.The encoding region format includes three parts: format information, version information, data and error correcting codewords.A QR code has three position detection patterns, its black and white module ratio is 1:1:3:1:1 in any direction.In other locations, there is no such feature, so that it can be quickly identified.
For the encoding region, it contains data and error correcting codewords, format information, and version information.The data and error correction codewords are used to store the original QR code information and correct the error codewords caused by image damage.Format information is composed of error correction level and mask image information, while the version information is used to determine the number of modules that form the QR code.The relationship between its version and module size is shown in Equation ( 1): As for the research on 2D barcode modification information proposed by other researchers, most of them focused on beautifying codes [25] and 2D barcode anti-counterfeiting technology [26].

QR Code Fault-Tolerant Mechanism
The 2D barcode image will inevitably be stained and damaged in practical applications, which affects the correct recognition of the 2D barcode negatively.Some image processing methods can partly reduce the effects.However, only by methods of error detection and error correction, can the 2D barcode with missing codewords or other pollution be decoded correctly.
For the convenience of research, a QR code, a kind of 2D barcode, is taken as an example to illustrate the related technology with details in this paper.QR codes may be based on RS code [27][28][29] to implement the error correction coding.RS code is a kind of Bose-Chaudhuri-Hocquenghem (BCH) code [30], which is also a kind of maximum distance code with a robust error-correction ability that can correct the burst error and random error.The encoding and decoding of QR codes play a crucial role in the generation and recognition of QR codes.The algorithm of RS code is the core of the 2D barcode decoding system technology.
The element symbols of RS code are in a finite field-GF(q), and roots of its generation polynomial are primitive elements in GF(q), which means that symbols and roots of RS code are in the same field.So the RS code generation polynomial can be written as: where m(x) is information polynomial, and r(x) is calibration polynomial.So a polynomial of RS code could be expressed as: As a RS codeword, it should be multiple of the generation polynomial, The RS code coding steps are shown as follows: 1.
Calculate the coefficients of RS code generation polynomial according to the primitive polynomial to get the expression of g(x).

2.
Multiply the information polynomial m(x) by x n−k .

3.
Divide m(x)x n−k by g(x) for remainder r(x).

4.
RS code polynomials can be written as: For the 2D barcode, a code that is unable to be scanned or decoded is called non-read error.The code that is decoded falsely is called replaced error [31].Among them, the total number of replaced errors and non-read errors can be corrected as follows: where e is the number of non-read error, t is the number of replaced error, d is the number of error-correcting codewords, p is the number of error detection codewords.
For the QR code, a series of error correction codewords can be generated by the error correction algorithm, which protects the codeword from losing data when the image is destroyed.There are four error correction levels of QR codes, corresponding to four error correction capacities, as shown in Table 1.Take the example of QR code version 3. Its error correction characteristic can be shown in Table 2.

Design Principle of Rewritable and Sustainable 2D Barcode
This section illustrates the design principle of the rewritable and sustainable two-dimensional (2D) barcode, which is described from three aspects.The design principle of the rewriteable area and the encryption algorithm is explained in detail, and then the encoding process of the rewriteable and sustainable 2D barcode is presented.

Design and Principle of Rewritable Area
According to the fault-tolerant mechanism, as long as the soiled area is less than the capacity of error correction, the quick response (QR) code can still be revised and thus decoded correctly with an error correction algorithm.In order to take full advantage of the 2D barcode fault tolerance, the rewritable area of a 2D barcode is artificially introduced by dividing the 2D barcode and regarding some areas as the stained areas with new meanings.For example, the selection of information can be implemented by writing information to the rewritable areas.Nevertheless, the rewritable area may increase the possibility of replacing error, so the rewritable area's size must be wisely defined.For example, the coordinates of the rewritable area can be set according to QR code international standard, ISO/IEC 18004:2015 "automatic identification and data collection technology, bar code technology specification, QR code" [32].In this work, the rewritable area is located in the middle of the 2D barcode, which enables the quick location of the rewritable area by graphics coordinates and therefore reduces the scan read time and enhances the accuracy in reading.The size of the rewritable area (the number of grids n) cannot exceed the error correction capacity r of the 2D barcode.
A four bits (2 × 2) rewritable area on the QR code pattern is shown in Figure 3.
The rewriteable area can be designed as a rectangle.For example, the total number of codewords in the QR code encoding regions is n.With eight small grids for each codeword, the total number of grids in the encoding region is defined as follows: Supposing c indicates the number of small grids on each edge of QR barcode, the central point coordinate of the 2D barcode is as follows: where [c/2] is the positive integer not greater than c/2.The length and the width of the rectangular rewritable area are a and b, respectively, so the coordinates of rewritable area are calculated as: Suppose that u indicates the error correction capacity of QR code.The error correction capacity at different levels is shown in Table 1.Its value is usually one of 7%, 15%, 25% and 30%.
Because the size of the rewritable area must be less than the error correction capacity of QR codes, some limitations about the size of the rewritable area need to be set: where [m × u] is the positive integer not greater than m × u.Therefore, the rewritable area's size must be less than the error correction capacity of each data block, which can ensure that the 2D barcode can be decoded correctly.The motivation behind the discussion above is to make the best use of the error-correction capacity of the 2D barcode.In practice, the rewritable area can be reduced according to actual situations.However, in any case, the area cannot be higher than the area defined in Equation (10).In order to give special consideration to the actual applications, such as the stain of 2D barcode, a certain amount of error correction space should be reserved for 2D barcode error correction.

Codeword Number
Error

Design Principle of Rewritable and Sustainable 2D Barcode
This section illustrates the design principle of the rewritable and sustainable two-dimensional (2D) barcode, which is described from three aspects.The design principle of the rewriteable area and the encryption algorithm is explained in detail, and then the encoding process of the rewriteable and sustainable 2D barcode is presented.

Design and Principle of Rewritable Area
According to the fault-tolerant mechanism, as long as the soiled area is less than the capacity of error correction, the quick response (QR) code can still be revised and thus decoded correctly with an error correction algorithm.In order to take full advantage of the 2D barcode fault tolerance, the rewritable area of a 2D barcode is artificially introduced by dividing the 2D barcode and regarding some areas as the stained areas with new meanings.For example, the selection of information can be implemented by writing information to the rewritable areas.Nevertheless, the rewritable area may increase the possibility of replacing error, so the rewritable area's size must be wisely defined.For example, the coordinates of the rewritable area can be set according to QR code international standard, ISO/IEC 18004:2015 "automatic identification and data collection technology, bar code technology specification, QR code" [32].In this work, the rewritable area is located in the middle of the 2D barcode, which enables the quick location of the rewritable area by graphics coordinates and therefore reduces the scan read time and enhances the accuracy in reading.The size of the rewritable area (the number of grids n) cannot exceed the error correction capacity r of the 2D barcode.
A four bits (2 × 2) rewritable area on the QR code pattern is shown in Figure 3.The rewriteable area can be designed as a rectangle.For example, the total number of codewords in the QR code encoding regions is .With eight small grids for each codeword, the total number of grids in the encoding region is defined as follows: Supposing  indicates the number of small grids on each edge of QR barcode, the central point coordinate of the 2D barcode is as follows: where [c/2] is the positive integer not greater than /2.The length and the width of the rectangular rewritable area are  and , respectively, so the coordinates of rewritable area are calculated as: Suppose that  indicates the error correction capacity of QR code.The error correction capacity at different levels is shown in Table 1.Its value is usually one of 7%, 15%, 25% and 30%.
Because the size of the rewritable area must be less than the error correction capacity of QR codes, some limitations about the size of the rewritable area need to be set: where [ × ] is the positive integer not greater than  × .Therefore, the rewritable area's size must be less than the error correction capacity of each data block, which can ensure that the 2D barcode can be decoded correctly.The motivation behind the discussion above is to make the best use of the error-correction capacity of the 2D barcode.In practice, the rewritable area can be reduced according to actual situations.However, in any case, the area cannot be higher than the area defined in Equation (10).In order to give special consideration to the actual applications, such as the stain of 2D barcode, a certain amount of error correction space should be reserved for 2D barcode error correction.
For the QR code version 3-H (codeword number: 70, error correction word number: 44) as an example,  = 29, then  = 8,  = 4 are reasonable settings.Each of the four little grids represents a writeable bit, so rewritable area can be written as 4 × 2 writeable bits, totaling eight grids.The eight grids can be numbered as shown in Figure 4.Each rewritable bit has two kinds of states (black (1) and white (0)) and eight grids which can express 2 different meanings.

Design of Information Encryption Algorithm
In the rewritable and sustainable QR code, the information encoding area contains different information segments.By adding the rewritable area on the QR code, different information segments are chosen to be read according to the rewritable area's contents.However, if only with the introduction of the rewritable area, all information will be read by general QR code readers, which cannot satisfy the confidentiality of information.As a result, the codewords must be encrypted

Design of Information Encryption Algorithm
In the rewritable and sustainable QR code, the information encoding area contains different information segments.By adding the rewritable area on the QR code, different information segments are chosen to be read according to the rewritable area's contents.However, if only with the introduction of the rewritable area, all information will be read by general QR code readers, which cannot satisfy the confidentiality of information.As a result, the codewords must be encrypted according to specific rules when being encoded.A key function of the rewritable and sustainable 2D barcode is dividing input information into groups, forming new information according to users' needs, and then selectively reading information according to the black and white sequences of rewritable areas.Data encryption means to hide the original information according to certain regulations, which is different from the standard reading equipment such as mobile phones that can read out the traditional QR code.Only when the sequence of the rewritable area is extracted successfully can the information in the corresponding segment be read effectively.In order to improve the confidentiality of information, a data encryption algorithm is designed for strong encryption and easy application, based on the related knowledge of the finite field [33] and matrix theory.
The modified data encryption arithmetic shown in this paper is based on the finite field GF 2 8 .
In the finite field GF 2 8 , there are 256 elements, whose values range from 0 to 255.A data matrix A is generated according to the information data, whose element values are represented by the elements of the finite field GF 2 8 .Then encryption matrix B is formed based on the finite field GF(2 8 ).In the encryption process, encrypted matrix C can be calculated by A × B because all operations are conducted within the finite field.The encrypted matrix C is in the range of 0-255, which will not result in changes in the codeword length.Therefore, it has positive effects on the isolation between the generation of QR code image and the effects of the encryption step.The encryption algorithm is based on the finite field and the related knowledge of the matrix theory.Specific steps are as follows: 1.
Convert encoded information to a stream of bits.Then every eight bits is a byte indicating a value between 0 and 255.The values are expressed in the finite field elements.Encoded information as: 2. Form an information matrix A j by every m × m data from step 1. 3.
Form an encryption matrix B j with elements in the finite field. 4.
Multiply information matrix A j by encryption matrix B j , then to get the encrypted information matrix C j .
The operation above is carried out within the finite field, therefore, the elements of the encrypted matrix are still in the range of 0-255.The encoding process can continue after the encrypted matrix is converted into a stream of bits.
In addition, according to the relevant knowledge of the matrix theory, as long as the encrypted matrix C j is multiplied by the inverse matrix of encryption matrix B j −1 , the original data matrix A j can be calculated and therefore decryption can be achieved: The encryption algorithm of rewritable and sustainable 2D barcode can be shown by Figure 5.

Encode Method of Rewritable and Sustainable 2D Barcode
This is an example of an equation: after adding rewritable area to the 2D barcode and integrating the data encryption into the encoding process, the encoding method of the rewritable and sustainable 2D barcode can be described as follows: 1. First of all, divide the data into segments that the users enter according to the needs.Then, insert the identifications between two segments, using "*" as separator.2. Using the modified data encryption algorithm to encrypt the input information.3. Generate a 2D barcode image according to the encrypted information by the 2D barcode generating software.4. Finally, add a rewritable and sustainable layer on the 2D barcode.

Verification of Information Input on Rewritable Area
In this section, we present experiments to verify the feasibility of the design.Firstly, the experimental setup is described; then the encoding method of the rewritable and sustainable twodimensional (2D) barcode is given.Finally, some examples of writing information in the rewritable and sustainable 2D barcode and verifying the decoding results are shown in Figure 6.

Encode Method of Rewritable and Sustainable 2D Barcode
This is an example of an equation: after adding rewritable area to the 2D barcode and integrating the data encryption into the encoding process, the encoding method of the rewritable and sustainable 2D barcode can be described as follows: 1.
First of all, divide the data into segments that the users enter according to the needs.Then, insert the identifications between two segments, using "*" as separator.

2.
Using the modified data encryption algorithm to encrypt the input information.

3.
Generate a 2D barcode image according to the encrypted information by the 2D barcode generating software.4.
Finally, add a rewritable and sustainable layer on the 2D barcode.

Verification of Information Input on Rewritable Area
In this section, we present experiments to verify the feasibility of the design.Firstly, the experimental setup is described; then the encoding method of the rewritable and sustainable two-dimensional (2D) barcode is given.Finally, some examples of writing information in the rewritable and sustainable 2D barcode and verifying the decoding results are shown in Figure 6.

Verification of Information Input on Rewritable Area
In this section, we present experiments to verify the feasibility of the design.Firstly, the experimental setup is described; then the encoding method of the rewritable and sustainable twodimensional (2D) barcode is given.Finally, some examples of writing information in the rewritable and sustainable 2D barcode and verifying the decoding results are shown in Figure 6.

Experimental Setup
In order to do the verification, the new software of the rewritable and sustainable 2D barcode is necessary.We chose Android Studio as a software development tool to develop the software.Besides, the encoding and decoding software of the rewritable and sustainable 2D barcode runs on the Android 9.0.Moreover, the barcode recognition software ZXing AndroidSDK (Version ZXing-3.1.0.jar) [34] and WeChat (Version 7.0.17)are used to decode and identify the rewritable and sustainable 2D barcode, respectively.

Experimental Setup
In order to do the verification, the new software of the rewritable and sustainable 2D barcode is necessary.We chose Android Studio as a software development tool to develop the software.Besides, the encoding and decoding software of the rewritable and sustainable 2D barcode runs on the Android 9.0.Moreover, the barcode recognition software ZXing AndroidSDK (Version ZXing-3.1.0.jar) [34] and WeChat (Version 7.0.17)are used to decode and identify the rewritable and sustainable 2D barcode, respectively.

Encoding of Rewritable and Sustainable 2D Barcode
An example of a traceability system for Chinese herbal medicine is analyzed in this section to show the feasibility of information input in the rewritable and sustainable 2D barcode.In the logistics industry and traceability systems, states or locations of goods need to be recorded and confirmed repeatedly.The insurance of safety and the records of condition are two main problems, which can be solved effectively by the rewritable and sustainable 2D barcode.More specifically, the encrypted 2D barcode can be the unique identification of the goods, and the condition of the goods can be written in the rewritable area.
"Name", "traceability ID", "type", and "manager" are the information served as the identification of the goods.There are eight grids in the rewritable area, which can describe, respectively, the results of tests for eight aspects about a certain object: pesticide content, soil organic matter content, PH of soil, heavy metal content in soil, heavy metal content in production, Total Suspended Particulate in air, heavy metal content in water, organic matter content in water (blackened gird indicates qualification; void grid indicates fail).
Firstly, users need to input information needed to be encoded, such as "Pseudo-ginseng, 082020, Midsize, Mike".The QR code version and the (3-H) correction level need to be selected.After the preprocessing, the data are transformed into decimal numbers.As for anti-counterfeiting in the traceability system, the information should be encrypted.
The encrypted information is encoded into a 2D barcode and added to the rewritable area.The eight grids in the rewritable area are arranged in a rectangle and preset to be "00000000" as default values, which represents the checking results of eight environmental conditions during the growth of herbal medicinal.Finally, the writable two-dimensional code is generated as shown in Figure 7.
preprocessing, the data are transformed into decimal numbers.As for anti-counterfeiting in the traceability system, the information should be encrypted.
The encrypted information is encoded into a 2D barcode and added to the rewritable area.The eight grids in the rewritable area are arranged in a rectangle and preset to be "00000000" as default values, which represents the checking results of eight environmental conditions during the growth of herbal medicinal.Finally, the writable two-dimensional code is generated as shown in Figure 7.

Traceability and Identification in Rewritable and Sustainable 2D Barcode
If the supposed results of the test about the environment are that the pesticide content, organic matter content in the soil, heavy metal content in the soil, heavy metal content in production, heavy metal content in water, organic matter content in water are qualified, but soil PH and (Total Suspended Particulate) TSP in the air are unqualified.Consequently, the sequence in the rewritable area should be "11011011".For a normal 2D barcode, if the 2D barcode is printed, more information cannot be added.However, with the rewritable and sustainable 2D barcode, the information about the test results can be added on the tractability identification, as shown in Figure 8.After blackening the corresponding position of the test index, the product can enter the next checking link, which realizes multiple uses of one code and improves circulation efficiency and resource utilization.

Traceability and Identification in Rewritable and Sustainable 2D Barcode
If the supposed results of the test about the environment are that the pesticide content, organic matter content in the soil, heavy metal content in the soil, heavy metal content in production, heavy metal content in water, organic matter content in water are qualified, but soil PH and (Total Suspended Particulate) TSP in the air are unqualified.Consequently, the sequence in the rewritable area should be "11011011".For a normal 2D barcode, if the 2D barcode is printed, more information cannot be added.However, with the rewritable and sustainable 2D barcode, the information about the test results can be added on the tractability identification, as shown in Figure 8.After blackening the corresponding position of the test index, the product can enter the next checking link, which realizes multiple uses of one code and improves circulation efficiency and resource utilization.
traceability system, the information should be encrypted.
The encrypted information is encoded into a 2D barcode and added to the rewritable area.The eight grids in the rewritable area are arranged in a rectangle and preset to be "00000000" as default values, which represents the checking results of eight environmental conditions during the growth of herbal medicinal.Finally, the writable two-dimensional code is generated as shown in Figure 7.

Traceability and Identification in Rewritable and Sustainable 2D Barcode
If the supposed results of the test about the environment are that the pesticide content, organic matter content in the soil, heavy metal content in the soil, heavy metal content in production, heavy metal content in water, organic matter content in water are qualified, but soil PH and (Total Suspended Particulate) TSP in the air are unqualified.Consequently, the sequence in the rewritable area should be "11011011".For a normal 2D barcode, if the 2D barcode is printed, more information cannot be added.However, with the rewritable and sustainable 2D barcode, the information about the test results can be added on the tractability identification, as shown in Figure 8.After blackening the corresponding position of the test index, the product can enter the next checking link, which realizes multiple uses of one code and improves circulation efficiency and resource utilization.Because of the addition of the rewritable area and the encryption algorithm, the special decoder is needed to scan 2D code in Figure 5 and get the correctly decoded information.Decoding results by the general 2D code decoder are shown in Figure 9, which are obviously wrong.
However, after scanned by the special decoder for the rewritable and sustainable 2D barcode, the rewritable areas' information can be identified correctly.The 2D barcode generated from the encrypted information can be the identification of the herbal medicine, while the rewritable area encoded according to the input information can show the results of production quality.Decoded by the special reader, the result is shown in Figure 10.
To sum up, identification and traceability can be achieved effectively and conveniently by the rewritable and sustainable 2D barcode, especially in the logistics industry and traceability systems for which information needs to be recorded and confirmed frequently.
Because of the addition of the rewritable area and the encryption algorithm, the special decoder is needed to scan 2D code in Figure 5 and get the correctly decoded information.Decoding results by the general 2D code decoder are shown in Figure 9, which are obviously wrong.However, after scanned by the special decoder for the rewritable and sustainable 2D barcode, the rewritable areas' information can be identified correctly.The 2D barcode generated from the encrypted information can be the identification of the herbal medicine, while the rewritable area encoded according to the input information can show the results of production quality.Decoded by the special reader, the result is shown in Figure 10.However, after scanned by the special decoder for the rewritable and sustainable 2D barcode, the rewritable areas' information can be identified correctly.The 2D barcode generated from the encrypted information can be the identification of the herbal medicine, while the rewritable area encoded according to the input information can show the results of production quality.Decoded by the special reader, the result is shown in Figure 10.

Discussion
As previous descriptions, the current writeable area is only a simple rectangle style.In the future, the writable area can be designed in conjunction with the visual attention mechanism [35,36].In this way, it will have a better look and feel while ensuring the writable function.Additionally, different writable layers can be designed for more field applications, for instance, as a special identification in visual tracking [37], navigation and positioning [11].What is more, it is possible to design a selectable information input writable barcode on the existing basis.When different positions in the writable area are painted, different information can be expressed, thereby realizing one code with multiple uses.

Conclusions
In order to cope with the traditional two-dimensional (2D) barcode that can only express static information, this paper proposes a new design of the rewritable and sustainable 2D barcode based on the fault-tolerant mechanism and data encryption algorithm.By data encryption and the insertion of the rewritable and sustainable layer, this design achieves the addition of new information into the 2D barcode.The details of the design are discussed in this paper, and some experiments prove the feasibility.As in the Internet of Things (IoT) application example, the data are successfully divided into segments and chosen to be read in different stages according to the information in the rewritable area, or some additional information varied in each process (i.e., the results of the production quality tests) can be added on the rewritable area.Consequently, because of the rewritable area, the 2D barcode can be adaptable to different stages in the application without being redesigned and reprinted, which increases the efficiency and flexibility of the 2D barcode.Experimental results have illustrated that the advantages of rewritable and sustainable 2D barcodes in the traceability of herbal medicine compared with the conventional 2D barcodes, which have significant applications and market value in the future smart IoT applications.

Figure 1 .
Figure 1.The traceability and circulation process of herbal medicine.Figure 1.The traceability and circulation process of herbal medicine.

Figure 1 .
Figure 1.The traceability and circulation process of herbal medicine.Figure 1.The traceability and circulation process of herbal medicine.

Figure 2 .
Figure 2. The structure of quick response (QR) code.

Figure 2 .
Figure 2. The structure of quick response (QR) code.

For
the QR code version 3-H (codeword number: 70, error correction word number: 44) as an example, c = 29, then a = 8, b = 4 are reasonable settings.Each of the four little grids represents a writeable bit, so rewritable area can be written as 4 × 2 writeable bits, totaling eight grids.The eight grids can be numbered as shown in Figure 4.Each rewritable bit has two kinds of states (black (1) and white (0)) and eight grids which can express 2 8 different meanings.Sustainability 2020, 12, x FOR PEER REVIEW 6 of 13

Figure 5 .
Figure 5.The encryption algorithm of a rewritable and sustainable 2D barcode.

Figure 8 .
Figure 8. Rewritable and sustainable 2D barcode with test results.

Figure 8 .
Figure 8. Rewritable and sustainable 2D barcode with test results.Figure 8. Rewritable and sustainable 2D barcode with test results.

Figure 8 .
Figure 8. Rewritable and sustainable 2D barcode with test results.Figure 8. Rewritable and sustainable 2D barcode with test results.

Figure 9 .
Figure 9. Fault decoding results.(a) The decoding result using Zxing Android SDK.(b) The decoding result using WeChat recognition software.

Figure 9 .
Figure 9. Fault decoding results.(a) The decoding result using Zxing Android SDK.(b) The decoding result using WeChat recognition software.

Figure 9 .
Figure 9. Fault decoding results.(a) The decoding result using Zxing Android SDK.(b) The decoding result using WeChat recognition software.

Table 2 .
The error-correction level of QR code version 3.