QR two-dimensional code anti-counterfeiting method and QR two-dimensional code anti-counterfeiting system

By generating anti-counterfeiting QR codes through binary inversion and hashing algorithms on the QR code dot matrix, the problem of easy counterfeiting of existing QR codes is solved, achieving high security and low cost anti-counterfeiting effect, which is suitable for product traceability and logistics management.

CN122113975BActive Publication Date: 2026-07-21CHENGDU JIXIANGMA TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHENGDU JIXIANGMA TECHNOLOGY CO LTD
Filing Date
2026-04-28
Publication Date
2026-07-21

Smart Images

  • Figure CN122113975B_ABST
    Figure CN122113975B_ABST
Patent Text Reader

Abstract

The application relates to the field of two-dimensional code anti-counterfeiting technology, in particular to a QR two-dimensional code anti-counterfeiting method and a QR two-dimensional code anti-counterfeiting system. The QR two-dimensional code anti-counterfeiting method utilizes the fault-tolerant mechanism of the QR two-dimensional code, carries out a binary inversion operation on 1-N dot matrices selected from a content area or a fault-tolerant area through a preset selection algorithm after a standard QR two-dimensional code image is generated. The number of inverted dots is determined by the two-dimensional code dot matrix specification, and the inverted dot position is uniquely determined by the text content carried by the two-dimensional code and the total dot matrix number, so that one product corresponds to one code. Since the number of inverted dots is extremely small, the normal reading of the two-dimensional code is not affected. During anti-counterfeiting verification, a remote service platform first compares the two-dimensional code text content, and then compares the dot matrix details, and judges the authenticity by detecting whether the preset inverted dots exist. The application has the advantages of strong compatibility, high anti-counterfeiting security, low cost, traceability and anti-channeling, and is suitable for various anti-counterfeiting scenes such as commodities, bills and certificates.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of QR code anti-counterfeiting technology, specifically to a QR code anti-counterfeiting method and system. Background Technology

[0002] QR codes are widely used in various fields such as product traceability, logistics management, invoices and certificates, and product anti-counterfeiting due to their ease of reading, large information capacity, and strong adaptability. However, traditional QR codes only carry basic information such as text, URLs, and codes. Their images themselves do not possess any unique anti-counterfeiting features, making them extremely easy for criminals to forge through methods such as photographic replication and software regeneration. This renders the QR code's anti-counterfeiting function ineffective and fails to effectively protect the authenticity of goods, invoices, etc.

[0003] Existing QR code anti-counterfeiting solutions mostly rely on comparing information from a backend database. This involves analyzing the content of the QR code and matching it with preset data in the backend to determine authenticity. However, this approach has a significant flaw: QR code images can be completely copied. Counterfeiters only need to obtain the text content of the QR code (e.g., through photo recognition or direct copying) to regenerate an identical QR code using standard QR code generation software. In this case, the backend database can only compare the text content and cannot distinguish whether the QR code is genuine or a counterfeit, resulting in extremely low anti-counterfeiting security.

[0004] QR codes inherently possess a fault-tolerance mechanism. Based on their fault-tolerance levels (L, M, Q, H), even if some modules (dot matrix) are damaged, obscured, or slightly modified, as long as the modification is within the fault-tolerance threshold, they can still be read normally by standard scanning devices. Currently, this fault-tolerance feature is only used to address scenarios such as QR code damage or obstruction, and has not yet been effectively explored and applied to image-level anti-counterfeiting. Summary of the Invention

[0005] To overcome the technical problems of existing QR codes, such as easy copying, poor anti-counterfeiting reliability, lack of image-level anti-counterfeiting features, and low counterfeiting costs, this invention provides a QR code anti-counterfeiting method and system. This method and system achieves high security, low cost, and strong compatibility by inverting the binary representation of specific dots (0 becomes 1, 1 becomes 0), thus solving the shortcomings of existing anti-counterfeiting schemes, improving anti-counterfeiting reliability, and being easy to promote and apply.

[0006] To achieve the above objectives, this invention provides a QR code anti-counterfeiting method, including a QR code generation step and an anti-counterfeiting verification step. Specifically, the anti-counterfeiting QR code generation step includes: Step A1: Obtaining the unique anti-counterfeiting text of the object to be anti-counterfeited, and generating a standard QR code image based on the unique anti-counterfeiting text, wherein the standard QR code image has a preset fault tolerance level; Step A2: Determining the number N of inverted points according to the dot matrix specifications of the standard QR code image, where N is an integer greater than or equal to 1 and less than or equal to the fault tolerance threshold under the dot matrix specifications; Step A3: Converting the unique anti-counterfeiting text into an integer value, and performing a modulo operation on the total number of dots in the content area and fault tolerance area of ​​the standard QR code image using the integer value to obtain the coordinates of N inverted points; Step A4: In the standard QR code image, performing a binary inversion operation on the corresponding dot matrix based on the coordinates of the N inverted points to generate an anti-counterfeiting QR code; Specifically, the anti-counterfeiting verification step includes: Step B... Step B1: Assign a unique text to each object to be verified, and generate a corresponding anti-counterfeiting QR code according to steps A1 to A4 for deployment; Step B2: Receive the QR code image to be verified uploaded by the user terminal; Step B3: Decode the QR code image to be verified and extract its text content; if the text content does not match the anti-counterfeiting text pre-stored in the database of the remote anti-counterfeiting service platform, it is determined to be a counterfeit QR code; Step B4: If the text content matches the anti-counterfeiting text, regenerate a genuine anti-counterfeiting QR code according to the text content and the preset dot matrix specifications, following the operation steps of steps A2 to A4; Step B5: Perform a dot matrix-level point-by-point comparison between the QR code image to be verified and the genuine anti-counterfeiting QR code to determine whether there are any inverted points in the QR code image to be verified that are exactly the same in position, number, and inverted state as the genuine anti-counterfeiting QR code; if the comparison results are consistent, it is determined to be a genuine QR code; if the comparison results are inconsistent, it is determined to be a counterfeit QR code.

[0007] Preferably, the correspondence between the number of inverted points N and the dot matrix specification in step A2 is as follows: when the dot matrix specification is 21×21, N=2; when the dot matrix specification is 25×25, N=2; when the dot matrix specification is 29×29, N=4; when the dot matrix specification is 33×33 or higher, N increases according to the total number of dots, and the value of N ensures that all inverted points are within the fault tolerance threshold range of the fault tolerance level corresponding to the dot matrix specification.

[0008] Preferably, step A3 specifically includes: performing SHA-256 or MD5 hash operation on the unique anti-counterfeiting text to generate a hash string of fixed length; sequentially extracting multiple non-overlapping consecutive character segments from the hash string, converting each character segment into an integer value; performing modulo operation on the total number of dots in the content area and the fault tolerance area of ​​the standard QR code image using each integer value to obtain the corresponding remainder, with each remainder uniquely corresponding to the dot number or coordinates of a dot, serving as the position of the inverted point.

[0009] Preferably, step A3 further includes: converting each character in the unique anti-counterfeiting text into a corresponding integer value according to its ASCII code or Unicode code; sequentially selecting the converted integer values, and performing modulo operation on the total number of dots in the content area and the fault tolerance area of ​​the standard QR code image respectively to obtain the corresponding remainders, each remainder uniquely corresponding to the number or coordinates of a dot matrix, which is used as the position of the inverted point.

[0010] Preferably, in step A4, the inverted point is located in the content area or error-tolerant area of ​​the standard QR code image, and the number N of all inverted points is less than the maximum number of error points allowed in the standard QR code image under a preset error tolerance level.

[0011] Preferably, the dot matrix-level point-by-point comparison in step B5 includes: comparing the binary values ​​at all inverted coordinate positions of the QR code image to be verified with those of the genuine anti-counterfeiting QR code; if the binary values ​​at all inverted coordinate positions are the same, and the difference in binary values ​​at non-inverted positions does not exceed the fault tolerance threshold, then the dot matrix comparison is determined to be consistent.

[0012] Preferably, the object to be protected against counterfeiting is a commodity, invoice, or certificate, and the unique anti-counterfeiting text of each object is different, achieving one item, one code.

[0013] Preferably, when generating genuine product anti-counterfeiting QR codes, the remote anti-counterfeiting service platform uses the same hash algorithm, the same character segment selection rules, the same modulo operation method, and the same rules for determining the number of negation points as in the QR code generation steps.

[0014] Accordingly, the present invention also provides a QR code anti-counterfeiting system for implementing the QR code anti-counterfeiting method provided by the present invention, comprising: a QR code generation module for determining the inverted point according to the dot matrix specification and hash modulo algorithm and performing binary inversion; a database module for storing the unique text of the object to be anti-counterfeited and the corresponding QR code information; a verification module for performing dual verification of text content comparison and inverted dot matrix details; and an output module for returning the verification result of genuine or counterfeit products to the user.

[0015] The present invention has at least the following technical effects through the technical solution provided by the present invention: The QR code anti-counterfeiting method provided by this invention only inverts a very small number of dots (such as 2 or 4), and the amount of modification is far below the fault tolerance threshold of the QR code. All standard scanning devices can read it normally, without requiring users to change their scanning tools or adjust the scanning process. Even if counterfeiters obtain the text content carried by the QR code by taking a picture or copying it, they cannot know the algorithm for selecting the inverted dots (hash method, character segment selection rules, modulo operation method, etc.), so they cannot generate a QR code image containing the correct inverted dots. The authenticity can be effectively distinguished by verifying the second dot matrix. Each object to be anti-counterfeited (goods, tickets, certificates) corresponds to a unique anti-counterfeiting text, thereby generating a unique anti-counterfeiting QR code. It can be used not only for anti-counterfeiting verification but also linked with a backend database to achieve product traceability, logistics tracking, and anti-counterfeiting management. It eliminates the need for hardware such as encryption chips, special inks, and dedicated reading devices, generating and verifying QR codes solely through software algorithms. The generation and verification costs are virtually zero, making it widely applicable to anti-counterfeiting scenarios for various commodities, invoices, and certificates. The algorithm is flexible and can dynamically improve the anti-counterfeiting level: the correspondence of the number of inverted points, hash algorithms (MD5, SHA-1, SHA-256, etc.), character segment selection rules, and modulo operation methods can all be used as confidential parameters and can be changed periodically. Even if counterfeiters crack the algorithm for a certain batch, they cannot predict subsequent batches, significantly increasing the difficulty of counterfeiting. Attached Figure Description

[0016] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings: Figure 1 This is an overall flowchart of the QR code anti-counterfeiting method provided in the embodiments of the present invention; Figure 2 This is a flowchart of the anti-counterfeiting verification steps in an embodiment of the present invention; Figure 3 This is a structural diagram of the QR code anti-counterfeiting system provided in an embodiment of the present invention. Detailed Implementation

[0017] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.

[0018] In this invention, the terms "system" and "network" are used interchangeably. "Multiple" refers to two or more; therefore, in this invention, "multiple" can also be understood as "at least two." "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Additionally, the character " / ", unless otherwise specified, generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, it should be understood that in the description of this invention, terms such as "first" and "second" are used only for descriptive purposes and should not be construed as indicating or implying relative importance or order.

[0019] This invention provides a QR code anti-counterfeiting method, such as... Figure 1 and Figure 2 The diagram shows steps for generating and verifying anti-counterfeiting QR codes. The generation step specifically includes: Step A1: Obtaining the unique anti-counterfeiting text of the object to be protected against counterfeiting, and generating a standard QR code image based on the unique anti-counterfeiting text. The standard QR code image has a preset fault tolerance level. Step A2: Determining the number of inverted points N based on the dot matrix specifications of the standard QR code image, where N is an integer greater than or equal to 1 and less than or equal to the fault tolerance threshold under the dot matrix specifications. Step A3: Converting the unique anti-counterfeiting text into an integer value, and performing a modulo operation on the total number of dots in the content area and fault tolerance area of ​​the standard QR code image using the integer value to obtain the coordinates of N inverted points. Step A4: In the standard QR code image, performing a binary inversion operation on the corresponding dot matrix based on the coordinates of the N inverted points to generate an anti-counterfeiting QR code. The verification step specifically includes: Step B1: Dividing each object to be protected against counterfeiting into... Step B1: Assign a unique text and generate a corresponding anti-counterfeiting QR code according to steps A1 to A4 for deployment; Step B2: Receive the QR code image to be verified uploaded by the user terminal; Step B3: Decode the QR code image to be verified and extract its text content; if the text content does not match the anti-counterfeiting text pre-stored in the database of the remote anti-counterfeiting service platform, it is determined to be a counterfeit QR code; Step B4: If the text content matches the anti-counterfeiting text, regenerate a genuine anti-counterfeiting QR code according to the text content and the preset dot matrix specifications, following the operation steps of steps A2 to A4; Step B5: Perform a dot matrix-level point-by-point comparison between the QR code image to be verified and the genuine anti-counterfeiting QR code to determine whether there are any inverted points in the QR code image to be verified that are exactly the same in position, number, and inverted state as the genuine anti-counterfeiting QR code; if the comparison results are consistent, it is determined to be a genuine QR code; if the comparison results are inconsistent, it is determined to be a counterfeit QR code.

[0020] In this embodiment of the invention, the steps are described in detail below. Specifically, the anti-counterfeiting QR code generation step includes: Step A1: This step involves obtaining a unique anti-counterfeiting text and generating a standard QR code. Specifically, the unique anti-counterfeiting text of the object to be protected against (e.g., a product, a receipt, or a certificate) is obtained. This anti-counterfeiting text can be a URL containing the product's unique code (e.g., "12345678" is the product's unique code) or a unique string of numbers or letters (e.g., 9876543210ABCDEF). Based on this unique anti-counterfeiting text, a standard QR code image is generated using a standard QR code encoding algorithm. Standard QR codes have built-in error correction redundancy during the encoding process. Depending on their fault tolerance level (L, M, Q, H), a certain percentage of modules (dot matrix) can be damaged or modified without affecting normal readability. This standard QR code image has a preset fault tolerance level, such as M level (approximately 15% fault tolerance) or Q level (approximately 25% fault tolerance). The fault tolerance level can be selected according to anti-counterfeiting requirements, but it must be ensured that the modified QR code can still be recognized normally by all standard scanning devices.

[0021] Step A2: This step involves determining the number of inverted points N based on the dot matrix specifications. Specifically, an inverted point refers to a dot matrix element that requires binary inversion. The number of inverted points N is determined based on the dot matrix specifications (i.e., version) of the standard QR code image, where N is an integer greater than or equal to 1 and less than or equal to the fault tolerance threshold for that dot matrix specification. Furthermore, the correspondence between the number of inverted points N and the dot matrix specifications is as follows: when the dot matrix specification is 21×21, N=2; when the dot matrix specification is 25×25, N=2; when the dot matrix specification is 29×29, N=4; when the dot matrix specification is 33×33 or higher, N increases incrementally according to the total number of dots, for example, determining the number of inverted points at a rate of 0.5% to 1% of the total number of dots, but ensuring that the modification amount of all inverted points does not exceed the maximum number of erroneous dots allowed for that fault tolerance level.

[0022] Step A3: This step involves converting the unique anti-counterfeiting text into integer values ​​and obtaining the coordinates of the inverted point through modulo operation. Specifically, the unique anti-counterfeiting text is converted into one or more integer values. Then, each integer value is used to perform a modulo operation on the total number of dots in the content area and the fault tolerance area of ​​the standard QR code image to obtain the coordinates of each inverted point. There is more than one algorithm for determining the coordinates. As long as the algorithm can consistently output an invertable coordinate from a string as input, it is acceptable. The coordinates can be represented as (row, column) or as a linear numbering of the dots (e.g., numbered 1, 2, 3…N from top to bottom and left to right; converting the string to an integer and taking the modulo of this total number determines which dot it is; this inverted point can fall into either the fault tolerance area or the content area). Inverted points must fall into either the fault tolerance area or the content area of ​​the QR code, ensuring they do not fall into the functional area. If a point falls into the functional area, it is discarded, the above algorithm is executed, and a new suitable inverted point is determined. For step A3, as long as the text content and dot matrix specifications of the QR code are the same, the inverted point position determined by the algorithm in this step will be exactly the same; if the text content is different (even if the dot matrix specifications are the same), the inverted point position will necessarily be different, thus realizing the anti-counterfeiting basis of "one item, one code"; the embodiments of the present invention provide two specific conversion and modulus extraction methods, specifically: Method 1: Perform SHA-256 or MD5 hashing on the unique anti-counterfeiting text to generate a fixed-length hash string (e.g., SHA-256 generates a 64-bit hexadecimal string). Extract multiple non-overlapping consecutive character segments from this hash string (e.g., every 8 characters per segment), and convert each segment into an integer value. Perform a modulo operation on the total number of dots in the content area and the error-tolerant area of ​​the standard QR code image using each integer value, obtaining the remainder. Each remainder uniquely corresponds to a dot number or coordinate, which is used as the position for inverting the dot.

[0023] Method 2: Convert each character in the unique anti-counterfeiting text to its corresponding integer value according to its ASCII or Unicode code. Select the converted integer values ​​in sequence (if the number of integer values ​​is less than N, they can be used in a loop or in combination), and perform modulo operation on the total number of dots in the content area and the fault tolerance area of ​​the standard QR code image respectively to obtain the remainder. Each remainder corresponds to the position of a negation point.

[0024] Step A4: This step involves performing a binary inversion operation on the selected dot matrix to generate an anti-counterfeiting QR code. Specifically, in the standard QR code image, based on the coordinates of the N inverted points obtained in Step A3, the corresponding dot matrix position is located, and a binary inversion operation is performed: if the binary value of the dot matrix is ​​0, it is changed to 1; if it is 1, it is changed to 0. The inverted points can be located in the content area or the error tolerance area of ​​the standard QR code image, but the total number of inverted points N must be less than the maximum number of erroneous dots allowed by the standard QR code image under the preset error tolerance level. After modification, the final anti-counterfeiting QR code is obtained. Because the number of inverted points is extremely small, this QR code can still be read normally by all standard scanning devices, without affecting its normal function.

[0025] Furthermore, the anti-counterfeiting verification steps specifically include: Step B1: This step involves assigning a unique anti-counterfeiting text and generating a deployment anti-counterfeiting QR code. Specifically, a unique anti-counterfeiting text (such as a unique anti-counterfeiting URL, unique code, etc.) is assigned to each object to be protected against counterfeiting (goods, invoices, or certificates). Following steps A1 to A4 above, a corresponding anti-counterfeiting QR code with a specific inverted point is generated for each unique anti-counterfeiting text. This QR code is then printed or pasted onto the corresponding object (e.g., the corresponding goods, invoices, or certificates) to complete the "one item, one code" deployment.

[0026] Step B2: This step involves receiving the QR code image uploaded by the user. Specifically, after purchasing goods or obtaining receipts / certificates, the consumer or verifier uses a mobile phone or other terminal device to photograph the QR code image on the goods, receipts, or certificates, and uploads the image to the remote anti-counterfeiting service platform (server) to initiate an anti-counterfeiting verification request. The remote anti-counterfeiting service platform then initiates dual verification.

[0027] Step B3: This step involves the first layer of verification – content verification. Specifically, the remote anti-counterfeiting service platform decodes the uploaded QR code image to be verified and extracts its text content. This text content is then compared with pre-stored anti-counterfeiting text in the platform's database (e.g., comparing the text content with a pre-set anti-counterfeiting database for goods, invoices / certificates). If the text content does not match the pre-stored anti-counterfeiting text (e.g., no record exists in the database, or the corresponding product status has changed), the QR code is directly determined to be counterfeit, and a "counterfeit" result is returned to the user.

[0028] Step B4: This step involves the second layer of verification—dot matrix verification. Specifically, if the text content in Step B3 matches the anti-counterfeiting text, the platform, based on the decoded text content and the dot matrix specifications of the QR code (version information can be automatically identified from the QR code image), regenerates a standard genuine anti-counterfeiting QR code with specific inverted dots, using the exact same algorithm as in the anti-counterfeiting QR code generation step (i.e., the same rules for determining the number of inverted dots, the same hash algorithm or ASCII conversion method, the same character segment selection rules, the same modulo operation method, and the same rules for determining the number of inverted dots). This genuine anti-counterfeiting QR code contains preset inverted dots.

[0029] Step B5: This step involves a point-by-point comparison at the dot matrix level to determine authenticity. Specifically, the user-uploaded QR code image to be verified is compared point-by-point at the dot matrix level with the regenerated genuine anti-counterfeiting QR code. The focus is on detecting whether there are preset inverted points in the uploaded QR code image, and whether the position and number of these inverted points are completely consistent with the regenerated genuine anti-counterfeiting QR code. The specific comparison method is as follows: compare the binary values ​​at the coordinates of all inverted points in the QR code image to be verified with those in the genuine anti-counterfeiting QR code. If the binary values ​​at all inverted point coordinates are the same (preset inverted points exist and their positions and numbers are correct), and the differences in binary values ​​at non-inverted point positions (e.g., differences due to photography, printing, or damage) do not exceed the threshold allowed by the QR code's error tolerance level, then the dot matrix comparison is considered consistent, the QR code is genuine, and a "genuine product" result is returned to the user. If the binary value at any inverted point coordinate is different from that of the genuine anti-counterfeiting QR code, or if the number of inverted points is inconsistent (e.g., no preset inverted point, missing inverted point, or inverted point position is incorrect), the dot matrix comparison is determined to be inconsistent, the QR code to be verified is counterfeit, and a "counterfeit" result is returned to the user.

[0030] In summary, during the anti-counterfeiting verification process, even if counterfeiters obtain the text content carried by the QR code through methods such as taking photos or replicating, and regenerate the QR code, they cannot reproduce the preset inverted points (because counterfeiters do not know the algorithm for selecting inverted points, and cannot determine the position and number of inverted points). Therefore, the dot matrix details of the generated counterfeit QR code differ from those of the genuine QR code, and can be quickly identified through the second key dot matrix verification.

[0031] Example 1: Anti-counterfeiting implementation of 21×21 version QR code (corresponding to N=2, using SHA-256 hash modulo method) Step A1: Obtain the unique anti-counterfeiting text and generate a standard QR code. Assign a unique anti-counterfeiting URL to a product: "12345678" is the product's unique code. Using this URL as content, generate a 21x21 version of a standard QR code, with an M-level fault tolerance (allowing approximately 15% dot matrix modification). The total number of dots in the content area and the fault tolerance area of ​​this QR code is 21x21=441.

[0032] Step A2: Determine the number of inverted points; based on the 21×21 dot matrix specification, the number of inverted points N=2.

[0033] Step A3: Convert the unique anti-counterfeiting text to an integer value, and obtain the coordinates of the inverted point through modulo operation; perform a SHA-256 hash operation on the unique anti-counterfeiting URL to obtain a 64-bit hexadecimal hash string (this is just an example; the actual hash value is a fixed-length hash value): ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890; Select the first 8 characters of the hash string "ABCDEF12" and convert them to an integer value: 11259375; Taking the integer value modulo the total number of dots 441, we get the modulus as: 11259375 ÷ 441 = 25531 remainder 204; The remainder 204 corresponds to dot matrix number 204 (numbered sequentially from top to bottom and left to right, starting from 0). Converting the number to coordinates: row number = 204 ÷ 21 = 9, column number = 204 % 21 = 15, resulting in the coordinates of the first inverted point (9, 15).

[0034] Select the 9th to 16th characters of the hash string "34567890" and convert them to the integer value: 872415240; Modulo 441: 872415240 ÷ 441 = 1978265 remainder 375 Coordinates: Row number = 375 ÷ 21 = 17, Column number = 375 % 21 = 18, resulting in the second inverted point coordinates (17, 18).

[0035] The coordinates of the two inverted points are determined to be (9,15) and (17,18), respectively. Both inverted points are located within the fault tolerance zone of the QR code (to avoid affecting the decoding of the critical content area). Ensure that the inverted points fall into the fault tolerance zone or content area of ​​the QR code but not into the functional area of ​​the QR code. If it falls into the functional area, discard the inverted point and execute the above algorithm to re-determine a suitable inverted point.

[0036] Step A4: Perform a binary inversion operation to generate an anti-counterfeiting QR code; in the standard QR code image, find the dot matrix at coordinates (9,15), assume its original binary value is 0, and change it to 1; find the dot matrix at coordinates (17,18), assume its original binary value is 1, and change it to 0. The modified QR code is the anti-counterfeiting QR code.

[0037] Step B1: Assign a unique anti-counterfeiting text and generate a deployment anti-counterfeiting QR code; print or affix the anti-counterfeiting QR code to the surface of the product.

[0038] Step B2: Receive the QR code image to be verified uploaded by the user; after purchasing, the consumer uses their mobile phone to photograph the QR code and upload it to the remote anti-counterfeiting service platform.

[0039] Step B3: First layer of verification – Content verification The platform decodes the URL, compares it with the database, and confirms that the URL corresponds to a valid product (content verification passed).

[0040] Step B4: Second verification – dot matrix verification Based on the URL and 21×21 specification, the platform regenerates the genuine product anti-counterfeiting QR code using the same SHA-256 hash, the same character segment selection rules (first 8 characters, second 8 characters), and the same modulo operation, which includes the inverted points (9,15) and (17,18).

[0041] Step B5: Perform pixel-by-pixel comparison at the dot matrix level to determine authenticity. The platform compares the image uploaded by the user with the genuine product's anti-counterfeiting QR code using a dot matrix comparison: it checks the binary values ​​at positions (9,15) and (17,18) one by one. If both are consistent with the genuine product (for example, (9,15) is 1 and (17,18) is 0), and the differences at other positions do not exceed the M-level fault tolerance threshold, then it is determined to be a genuine product and the "genuine product" result is returned.

[0042] Counterfeiting scenario: If the counterfeiter only copies the URL and uses standard QR code generation software to generate a 21×21 QR code without any inverted points, the platform will find that the binary values ​​at positions (9,15) and (17,18) are inconsistent with the genuine product (for example, both are the original standard values ​​0 and 1) when comparing the dot matrix, and will determine it as counterfeit.

[0043] Example 2: Anti-counterfeiting implementation of 29×29 version QR code (corresponding to N=4, using MD5 hash modulo method, and the inverted point is located in a mixture of content area and fault tolerance area). Step A1: Obtain the unique anti-counterfeiting text and generate a standard QR code. The product's unique code is selected: 9876543210ABCDEF (pure code excluding URL prefix). Using this code, a standard QR code of version 29×29 is generated, with a fault tolerance level of Q (allowing approximately 25% dot matrix modification). The total number of dots is 29×29=841.

[0044] Step A2: Determine the number of inverted points; based on the 29×29 dot matrix specification, the number of inverted points N=4.

[0045] Step A3: Convert the unique anti-counterfeiting text to an integer value, and obtain the coordinates of the inverted point through modulo operation; perform an MD5 hash operation on the unique code to obtain a 32-bit hexadecimal hash string (example): a1b2c3d4e5f67890a1b2c3d4e5f67890 Extract consecutive 8-character segments without overlapping: The first segment "a1b2c3d4" is converted to an integer value: 2712847316; taking the modulus of 841: 2712847316 ÷ 841 = 3225749 with a remainder of 207, so the inverse point is numbered 207, and the coordinates are (207 ÷ 29 = 7, 207 % 29 = 4), which is (7, 4).

[0046] The second segment "e5f67890" is converted to an integer value: 3852819344; taking the modulus of 841: 3852819344 ÷ 841 = 4581518 with a remainder of 666, so the inverse point is numbered 666, and the coordinates are (666 ÷ 29 = 22, 666 % 29 = 28), which is (22, 28).

[0047] The third segment "a1b2c3d4" is a repeated example. The subsequent characters in the actual MD5 result are different. This is just a demonstration. Assume that the third segment "12345678" is converted to an integer value and the modulo is taken to get the number 112. The coordinates are (112÷29=3, 112%29=25), which is (3,25).

[0048] The fourth segment is taken from the different segments after the last 8 characters "e5f67890". Let's assume the number is 450 and the coordinates are (450÷29=15, 450%29=15), which is (15,15).

[0049] The coordinates of the four inverted points are (7,4), (22,28), (3,25), and (15,15). Among them, (7,4) and (3,25) are located in the content area, and (22,28) and (15,15) are located in the fault tolerance area.

[0050] Step A4: Perform a binary inversion operation to generate an anti-counterfeiting QR code. In a standard 29×29 QR code, the binary inversion (0 becomes 1, 1 becomes 0) is performed on the dots at the four coordinates mentioned above. Due to the strong Q-level fault tolerance, the modification of the four dots is completely within the fault tolerance range.

[0051] Steps B1-B5: Deployment and Verification Process The anti-counterfeiting QR code is printed on the product. During verification, the platform decodes the code 9876543210ABCDEF, uses the same MD5 hash algorithm, the same 8-character segment truncation rule, and the same modulo operation to regenerate the genuine product's QR code, and compares it with the dot matrix of the user-uploaded image. If all four inverted dots match, the product is determined to be genuine; otherwise, it is counterfeit.

[0052] Please see Figure 3 Based on the same inventive concept, embodiments of the present invention provide a QR code anti-counterfeiting system for implementing the QR code anti-counterfeiting method provided by the present invention. The system includes the following modules: QR code generation module: This module determines the inverted points according to the dot matrix specifications and hash modulo algorithm, and performs binary inversion. It receives unique anti-counterfeiting text and dot matrix specification parameters, automatically completes standard QR code generation, determines the number of inverted points, calculates the coordinates of the inverted points (using hash modulo or ASCII modulo), performs binary inversion, and finally outputs an anti-counterfeiting QR code image.

[0053] Database module: Used to store the unique text and corresponding QR code information of the object to be protected against counterfeiting. This module can be a relational database (such as MySQL) and must contain at least the anti-counterfeiting text field, the object identifier field, and the status field (such as whether it has been sold or verified).

[0054] Verification Module: This module performs dual verification by comparing text content and inverting dot matrix details. It includes a decoding unit (extracting the QR code text content), a content comparison unit (matching with the database), a genuine QR code regeneration unit (regenerating using the same algorithm), and a dot matrix comparison unit (comparing and inverting the binary values ​​of each dot position).

[0055] Output module: Used to return the verification result to the user whether the product is genuine or counterfeit. The output method can be a prompt on a mobile app page, a result display on a webpage, or an SMS notification, etc.

[0056] The QR code anti-counterfeiting method provided by this invention only inverts a very small number of dots (such as 2 or 4), and the amount of modification is far below the fault tolerance threshold of the QR code. All standard scanning devices can read it normally, without requiring users to change their scanning tools or adjust the scanning process. Even if counterfeiters obtain the text content carried by the QR code by taking a picture or copying it, they cannot know the algorithm for selecting the inverted dots (hash method, character segment selection rules, modulo operation method, etc.), so they cannot generate a QR code image containing the correct inverted dots. The authenticity can be effectively distinguished by verifying the second dot matrix. Each object to be anti-counterfeited (goods, tickets, certificates) corresponds to a unique anti-counterfeiting text, thereby generating a unique anti-counterfeiting QR code. It can be used not only for anti-counterfeiting verification but also linked with a backend database to achieve product traceability, logistics tracking, and anti-counterfeiting management. It eliminates the need for hardware such as encryption chips, special inks, and dedicated reading devices, generating and verifying QR codes solely through software algorithms. The generation and verification costs are virtually zero, making it widely applicable to anti-counterfeiting scenarios for various commodities, invoices, and certificates. The algorithm is flexible and can dynamically improve the anti-counterfeiting level: the correspondence of the number of inverted points, hash algorithms (MD5, SHA-1, SHA-256, etc.), character segment selection rules, and modulo operation methods can all be used as confidential parameters and can be changed periodically. Even if counterfeiters crack the algorithm for a certain batch, they cannot predict subsequent batches, significantly increasing the difficulty of counterfeiting.

[0057] Furthermore, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the present invention.

[0058] The optional embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the embodiments of the present invention are not limited to the specific details in the above embodiments. Within the scope of the technical concept of the embodiments of the present invention, various simple modifications can be made to the technical solutions of the embodiments of the present invention, and these simple modifications all fall within the protection scope of the embodiments of the present invention.

[0059] It should also be noted that the various specific technical features described in the above embodiments can be combined in any suitable manner without contradiction. To avoid unnecessary repetition, the embodiments of the present invention will not describe the various possible combinations separately.

[0060] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. This program is stored in a storage medium and includes several instructions to cause a microcontroller, chip, or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0061] Furthermore, various different implementations of the present invention can be combined arbitrarily, as long as they do not violate the spirit of the present invention, they should also be regarded as the content disclosed in the present invention.

Claims

1. A QR code anti-counterfeiting method, characterized in that, This includes the steps for generating and verifying anti-counterfeiting QR codes; The anti-counterfeiting QR code generation step specifically includes: Step A1: Obtain the unique anti-counterfeiting text of the object to be protected against counterfeiting, and generate a standard QR code image based on the unique anti-counterfeiting text. The standard QR code image has a preset fault tolerance level. Step A2: Determine the number N of inverted points according to the dot matrix specifications of the standard QR code image, where N is an integer greater than or equal to 1 and less than or equal to the fault tolerance threshold under the dot matrix specifications; Step A3: Convert the unique anti-counterfeiting text into an integer value, and use the integer value to perform a modulo operation on the total number of dots in the content area and the fault tolerance area of ​​the standard QR code image to obtain the coordinates of N inverted points; specifically including: Perform SHA-256 or MD5 hash operation on the unique anti-counterfeiting text to generate a fixed-length hash string; Extract multiple non-overlapping consecutive character segments sequentially from the hash string, and convert each character segment into an integer value; Each integer value is used to perform a modulo operation on the total number of dots in the content area and the fault tolerance area of ​​the standard QR code image to obtain the corresponding remainder. Each remainder uniquely corresponds to the number or coordinates of a dot matrix, which serves as the position of the inverted point. Step A4: In the standard QR code image, according to the coordinates of the N inverted points, perform a binary inversion operation on the corresponding dot matrix to generate an anti-counterfeiting QR code; The anti-counterfeiting verification steps specifically include: Step B1: Assign a unique text to each object to be protected against counterfeiting, and generate the corresponding anti-counterfeiting QR code according to steps A1 to A4 for deployment; Step B2: Receive the QR code image to be verified uploaded by the user terminal; Step B3: Decode the QR code image to be verified and extract its text content; if the text content does not match the anti-counterfeiting text pre-stored in the database of the remote anti-counterfeiting service platform, it is determined to be a counterfeit QR code. Step B4: If the text content matches the anti-counterfeiting text, then according to the text content and the preset dot matrix specifications, regenerate the genuine anti-counterfeiting QR code according to the operation steps of steps A2 to A4. Step B5: Perform a dot matrix-level comparison between the QR code image to be verified and the genuine anti-counterfeiting QR code to determine whether there are any inverted points in the QR code image to be verified that are exactly the same as the genuine anti-counterfeiting QR code in terms of position, number, and inverted state. If the comparison results match, the QR code is determined to be genuine; if the comparison results do not match, the QR code is determined to be counterfeit.

2. The QR code anti-counterfeiting method according to claim 1, characterized in that, The correspondence between the number of inverted points N and the dot matrix specifications in step A2 is as follows: When the dot matrix size is 21×21, N=2; When the dot matrix size is 25×25, N=2; When the dot matrix size is 29×29, N=4; When the dot matrix size is 33×33 or larger, N increases with the total number of dots, and the value of N ensures that all inverted dots are within the fault tolerance threshold range of the corresponding fault tolerance level for that dot matrix size.

3. The QR code anti-counterfeiting method according to claim 1, characterized in that, Step A3 specifically also includes: Each character in the unique anti-counterfeiting text is converted into its corresponding integer value according to its ASCII code or Unicode code. The converted integer values ​​are selected sequentially, and modulo operations are performed on the total number of dots in the content area and the fault tolerance area of ​​the standard QR code image to obtain the corresponding remainders. Each remainder uniquely corresponds to the number or coordinates of a dot matrix, which is used as the position of the inverted point.

4. The QR code anti-counterfeiting method according to claim 1, characterized in that, In step A4, the inverted point is located in the content area or error-tolerant area of ​​the standard QR code image, and the number N of all inverted points is less than the maximum number of error points allowed by the standard QR code image under the preset error tolerance level.

5. The QR code anti-counterfeiting method according to claim 1, characterized in that, The point-by-point comparison at the lattice level in step B5 includes: Compare the binary values ​​at all inverted point coordinates of the QR code image to be verified with those of the genuine anti-counterfeiting QR code one by one; If the binary values ​​at all inverted point coordinates are the same, and the differences in binary values ​​at non-inverted point coordinates do not exceed the fault tolerance threshold, then the dot matrix comparison is considered consistent.

6. The QR code anti-counterfeiting method according to claim 1, characterized in that, The objects to be protected against counterfeiting are commodities, invoices, or certificates. Each object has a unique anti-counterfeiting text, achieving one item, one code.

7. The QR code anti-counterfeiting method according to claim 1, characterized in that, When generating genuine product anti-counterfeiting QR codes, the remote anti-counterfeiting service platform uses the same hash algorithm, the same character segment selection rules, the same modulo operation method, and the same rules for determining the number of negation points as in the QR code generation steps.

8. A QR code anti-counterfeiting system, used to implement the QR code anti-counterfeiting method as described in any one of claims 1-7, characterized in that, include: The QR code generation module is used to determine the invert point according to the dot matrix specification and hash modulo algorithm and perform binary inversion; The database module is used to store the unique text and corresponding QR code information of the object to be protected against counterfeiting; The verification module is used to perform dual verification of text content comparison and inversion of dot matrix details; The output module is used to return the verification result of whether the product is genuine or counterfeit to the user.