A fragile watermark-based nc code integrity anomaly detection method

By using a fragile watermark-based NC code integrity detection method, the problem of tampering detection during NC code transmission is solved, enabling real-time detection and precise location of tampering, thus ensuring processing accuracy and security.

CN119720136BActive Publication Date: 2025-10-17HARBIN INST OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411761783.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-10-17
Estimated Expiration
2044-12-03

AI Technical Summary

Technical Problem

Existing NC code detection methods lack effective tamper detection means during transmission, leading to reduced machining accuracy and production safety hazards. Traditional integrity verification methods cannot accurately detect tampering locations and have low accuracy.

Method used

By employing a fragile watermarking technology, the geometric features and instruction information of the NC code tool trajectory coordinate data are analyzed. The segmentation algorithm divides the NC code into program segments and embeds the watermark information into the tool trajectory, enabling real-time detection and location of tampering.

Benefits of technology

It achieves highly sensitive detection of NC code, can accurately locate the tampering position, improve security and concealment, while maintaining the machining accuracy without being affected, and supports real-time detection and rapid repair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119720136B_ABST
    Figure CN119720136B_ABST
Patent Text Reader

Abstract

The application discloses a kind of NC code integrity anomaly detection methods based on fragile watermark, the method first, by analyzing the geometric characteristics of tool trajectory, combine G code, M code and other instruction information in code, using feature point detection algorithm identifies the area that corner is larger or geometric change is remarkable as watermark embedding key position;Then, generate unique watermark information and embed it into selected redundant coordinate points, ensure that it does not affect the geometric shape of tool trajectory;Next, after transmission is completed, recover watermark information from embedding point by watermark extraction technology, and save it for subsequent comparison;Finally, by comparing the extracted watermark with original watermark, detect whether tampering occurs, if there is abnormal, locate tampering position and stop processing operation, ensure safety.The application realizes highly sensitive detection to NC code by fragile watermark technology, can make accurate judgment to any tampering, ensure the integrity and security of code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of numerical control technology and relates to an NC code integrity detection method, in particular to an NC code integrity anomaly detection method based on digital watermark technology. Background Art

[0002] With the continuous development of industrial automation and intelligent manufacturing, CNC technology is playing an increasingly important role in the manufacturing industry. NC code, as a key instruction in CNC machining, directly determines machining accuracy and product quality. However, in the actual machining process, NC code may be subject to problems such as data tampering, interference, and errors in the code itself at every stage, from programming to transmission and execution. These issues not only reduce the precision of machined parts but also pose serious safety risks. Therefore, ensuring the integrity of NC code during transmission and execution has become a pressing technical challenge.

[0003] Existing NC code detection methods often focus on syntax and logic errors in the code, but lack effective means to detect code tampering during transmission. Traditional integrity verification methods, when used in complex CNC machining environments, suffer from issues such as inability to accurately detect the location of tampering and low detection accuracy. Therefore, research on NC code integrity detection methods based on digital watermarks can effectively improve the detectability and location accuracy of code tampering, ensuring that the code has not been tampered with during transmission without affecting the execution accuracy of the machining task. Summary of the Invention

[0004] NC codes may be tampered with during transmission to CNC machine tools. However, traditional NC code transmission processes lack effective anti-tampering measures and are unable to detect code integrity in real time. Tampering cannot be detected in a timely manner, which in turn affects processing quality and production safety. The present invention provides an NC code integrity anomaly detection method based on fragile watermarks to protect NC codes from possible tampering during transmission. The present invention analyzes the characteristics of tool path coordinate data in NC codes and, in combination with geometric features and special codes, proposes a program segment division algorithm to achieve reasonable grouping of NC codes. Using fragile watermark technology, watermark information is embedded into the NC code, enabling timely detection and location of tampering when the code is tampered with. The watermark embedding process maintains invisibility by not changing the tool path geometry, while ensuring the reversibility of the embedded watermark, meaning that the original NC code can be fully restored without being attacked.

[0005] The purpose of the present invention is achieved through the following technical solutions:

[0006] A method for detecting anomalies in NC code integrity based on fragile watermarks includes the following steps:

[0007] Step S1: analyze the NC code tool path coordinate data, extract its geometric characteristics and instruction information, and identify the feature trajectory area;

[0008] Step S2: based on the analysis of the tool path data, using the segmentation algorithm based on geometric features and instruction information, the NC code is divided into multiple program segments, each program segment is composed of a group of trajectory data with similar characteristics or functions, these program segments are the basic units of watermark generation and embedding, including function instruction segment and trajectory data segment;

[0009] Step S3: according to the characteristics of each program segment and the key for generating the hash value of each program segment, generate group watermark and global watermark, combine watermark information with trajectory data;

[0010] Step S4: apply watermark embedding technology to embed watermark into NC code tool path coordinates, ensuring the geometric shape unchanged;

[0011] Step S5: after the transmission of NC code, use watermark extraction algorithm to extract the embedded watermark and compare it with the original watermark;

[0012] Step S6: according to the comparison result, judge whether the NC code is tampered with, if not, proceed with normal processing;

[0013] Step S7: if tampering is detected, use tampering positioning algorithm to locate the abnormal position and analyze the tampering type;

[0014] Step S8: output the tampering positioning result and prompt the operator to take measures.

[0015] Compared with the prior art, the present application has the following advantages:

[0016] 1、The present application realizes high sensitivity detection of NC code through fragile watermark technology, which can accurately judge any tampering (such as insertion, deletion or modification) and ensure the integrity and security of the code. At the same time, combined with group watermark and global watermark, it can accurately locate the specific program segment or trajectory point that is tampered with, realize fine-grained abnormal positioning, greatly facilitate the rapid troubleshooting and repair of problems.

[0017] 2、The watermark embedding design of the present application has high invisibility, which does not change the geometric shape of the tool path, neither affects the machining precision, nor is easy to be detected, thereby improving the security and concealment.

[0018] 3、The present application has good reversibility, which can completely remove the watermark and restore the original NC code data without tampering, ensuring that the machining precision is absolutely protected.

[0019] 4. In terms of security, the present application encrypts the watermark by means of a key, so that even if the attacker masters the embedding algorithm, without obtaining the key, it is impossible to forge a valid watermark, greatly improving the anti-attack ability of the system.

[0020] 5. The present application is flexible in design, can be divided by program segment and various embedding strategies, and is suitable for NC codes and tool path characteristics of different complexity, and can be widely applied to various machining scenes.

[0021] 6. The present application can not only detect tampering, but also analyze the type of tampering (such as insertion, deletion or modification), providing clear basis for problem tracing and repair.

[0022] 7. The present application supports real-time detection, can quickly find problems and take measures after the transmission of NC code is completed, and fully guarantees the safety and efficiency of machining. BRIEF DESCRIPTION OF DRAWINGS

[0023] Figure 1 Flowchart of NC code integrity anomaly detection method based on fragile watermark;

[0024] Figure 2 Specific flowchart of NC code integrity anomaly detection method based on fragile watermark;

[0025] Figure 3 Trajectory shape comparison before and after adding redundant trajectory points;

[0026] Figure 4 Intact line deletion of NC code;

[0027] Figure 5 NC code before being attacked;

[0028] Figure 6 Integrity detection result of code receiving end in attack test 2;

[0029] Figure 7 Sequence number shift detection algorithm;

[0030] Figure 8 Detection result after using sequence number shift detection algorithm for repair;

[0031] Figure 9 Integrity detection result of code receiving end in attack test 3;

[0032] Figure 10 First time sequence number shift detection result;

[0033] Figure 11 Second time sequence number shift detection result;

[0034] Figure 12This is the NC code before the attack;

[0035] Figure 13 Tampering with the results for attack test 4;

[0036] Figure 14 The integrity test result of the receiving end of attack test 4 code;

[0037] Figure 15 The results of attack test 4 are analyzed using the sequence number shift detection method. DETAILED DESCRIPTION

[0038] The technical solution of the present invention is further described below with reference to the accompanying drawings, but is not limited thereto. Any modification or equivalent replacement of the technical solution of the present invention that does not depart from the spirit and scope of the technical solution of the present invention should be included in the scope of protection of the present invention.

[0039] The present invention provides a method for detecting NC code integrity anomalies based on fragile watermarks, such as Figure 1 As shown in the figure, first, by analyzing the geometric features of the tool trajectory and combining the G code, M code and other instruction information in the code, the feature point detection algorithm is used to identify the area with large corners or significant geometric changes as the key position for watermark embedding; then, a unique watermark information is generated and embedded into the selected redundant coordinate points to ensure that the geometric shape of the tool trajectory is not affected; then, after the transmission is completed, the watermark information is restored from the embedded point through watermark extraction technology and saved for subsequent comparison; finally, by comparing the extracted watermark with the original watermark, whether tampering has occurred is detected. If there is any abnormality, the tampering position is located and the processing operation is stopped to ensure safety. Figure 2 The specific steps are as follows:

[0040] Step S1: Analyze the NC code tool path coordinate data, extract its geometric characteristics and instruction information, and identify the characteristic trajectory area. The specific steps are as follows:

[0041] Step S11: Perform detailed analysis on the tool path data in the NC code to identify its key characteristics.

[0042] Step S12: By extracting the geometric characteristics of the tool movement, such as straight segments, curve segments and corners, the characteristic trajectory areas with significant characteristics in the NC code are identified. The characteristic trajectory areas refer to the key trajectory points or areas extracted in the NC code based on geometric characteristics and instruction information for watermark embedding and detection. These areas include trajectory positions with special geometric shapes, such as large corners or rapid change points.

[0043] Step S13: extracting functional instruction information (such as G code and M code) in the code to help divide different program segments, providing a clear segmentation basis for subsequent watermark embedding.

[0044] NC code tool path data has the following characteristics:

[0045] 1) The entire NC code production process is complex, with high production costs in manpower and material resources, and high requirements for usability and precision. Once the precision does not meet the requirements, the processed parts are likely to lose their usability.

[0046] 2) The storage and program execution of NC code tool path data are linear and orderly. The program portion of the NC code is executed in a linear order. The decoder reads and decodes each line of code, transmitting the data to the controller to control the machine tool's transmission device to achieve processing.

[0047] 3) The tool path data of the NC code has low data redundancy. The spatial relationship characteristics of the tool path points are relatively complex. The tool path data points have a compact structure and low redundant bits, resulting in low data redundancy.

[0048] Based on the above three characteristics, embedding watermarks by modifying the coordinate data of trajectory points may distort the trajectory shape and easily attract the attention of attackers. Figure 3 As shown in the figure, P1 and P2 are redundant trajectory points. Adding watermark trajectory points similar to P1 and P2 to the two tool trajectory points will not affect the shape of the tool trajectory. At the same time, the movement of data point P1 on the line segment where D2 and D3 are located will not affect the shape of the tool trajectory, making the watermark highly invisible and not easily noticed by attackers.

[0049] Step S2: Based on the analysis of the tool trajectory data, a segmentation algorithm based on geometric features and instruction information is used to divide the NC code into multiple program segments. Each program segment consists of a set of trajectory data with similar characteristics, typically including a functional instruction segment and a trajectory data segment. The functional instruction segment contains specific operation instructions, such as G00 rapid positioning and G01 linear interpolation; the trajectory data segment represents the specific motion path of the tool. This segmentation ensures flexibility in watermark embedding and facilitates precise location of tampering during detection.

[0050] In this step, in order to realize the division of NC code program segments, set f d To realize the division method; in order to facilitate the processing of data in each group, let f I The NC code segment grouping data is converted into the standard segment grouping data format, which contains all the information of the original NC code. In order to achieve the purpose of generating watermarks, let f h Generate group G based on key K1 i The hash value of the generated hash value is then extracted based on the key K2, and the fixed bit length H is finally obtained.i As shown in formula (1):

[0051]

[0052] In the formula, F is the original NC code content to be divided; P i is the i-th group of NC code segment F after using the division algorithm; N is the division result, a total of N groups; G i is the i-th group of code that has been standardized; K1 is a hash value generated together with G i ; K2 is a key for determining the position of extracting fixed bits from the generated hash value; H i is the watermark information generated according to the hash value and K2.

[0053] Step S3: Generate group watermark and global watermark according to the characteristics of each program segment and the key for generating the hash value of each program segment, and combine the watermark information with the trajectory data. The specific steps are as follows:

[0054] After completing the NC code division, an independent group watermark is generated for each program segment to ensure the integrity of each code segment, and a global watermark is also generated for overall integrity verification, wherein: the generation of the watermark is based on the hash value of each group, and the hash value is encrypted using a symmetric encryption key to increase security. The combination of such group watermark and global watermark can provide double protection when tampering occurs, not only can detect local tampering, but also can identify global abnormalities.

[0055] Step S4: Apply watermark embedding technology to embed the watermark generated in step S3 into the key position of the tool trajectory of the NC code, and ensure that the embedding of the watermark is completed without changing the geometric shape. The selection of the embedding point is based on the characteristics of the trajectory data, for example, adding watermark between adjacent trajectory points, or modifying the least significant bit of a specific trajectory point, so as to ensure the concealment of the watermark. Through various embedding strategies, the watermark is embedded in the machining process and is difficult to be found, thereby protecting the integrity of the NC code.

[0056] In this step, let f e be the watermark embedding method, and the watermark H i is embedded into the position of the trajectory data according to the key K1, so as to prevent illegal extraction of the watermark information and leakage of the original NC code, thereby enhancing the security of the watermark information, as shown in formula (2):

[0057] f e :D g ×K1×H i →D g +D e (2)

[0058] D = D + D g is the original NC code; K1 is used to determine the position of the embedded trajectory data; when K1 is used to generate a hash value, it is denoted as K 1-gen ; when K1 is used to locate and extract watermark information, it is denoted as K 1-extract ; D e is the part of the original NC code that is different after embedding the watermark, i.e., the embedded trajectory data points. Therefore, D g + D e is the final NC code with watermark.

[0059] Step S5: After the NC code is transmitted, the embedded watermark is extracted using a watermark extraction algorithm and compared with the original watermark. The specific steps are as follows:

[0060] After the NC code is transmitted, the embedded watermark information is extracted from the receiving end and compared with the original watermark: first, the grouped watermark is extracted and verified piece by piece, and then the global watermark is extracted for overall comparison. By comparing the extracted watermark with the original watermark, it can be effectively judged whether the NC code has been tampered with during transmission. If the extracted watermark and the original watermark are completely consistent, it is determined that the code is complete; otherwise, the abnormal detection process is entered.

[0061] Step S6: According to the comparison result, it is judged whether the NC code has been tampered with, and if not, normal processing is carried out. The specific steps are as follows:

[0062] Through the extraction and comparison of the watermark, the integrity of the NC code can be judged. If all the watermarks are consistent, it means that the code has not been tampered with, and the normal processing process is entered; if it is found that the watermarks are inconsistent, it means that the code may have been tampered with, at which time the system pauses the execution of the NC code and enters the next step of tamper detection and positioning process to prevent incomplete code from affecting production safety.

[0063] In this step, let f1 be the NC code division algorithm, divide the received NC code and standardize the groups, let f h1 be a method for extracting watermark information H r according to the key K1, let f2 realize the extraction of the original NC code, and let f3 realize the restoration of the NC code to generate a hash value according to the key K1, and then extract a fixed number of bits from the generated hash value according to the key K2, and finally compare the extracted hash value with H r . If they are exactly the same, it means that there has been no tampering, otherwise there has been tampering, as shown in equation (3):

[0064]

[0065] D = D + D r is the received NC code; G riis the i-th divided group; H r is the extracted watermark information; D is the restored NC code; s is the detection output result, which is a Boolean value, where 1 indicates tampering and requires anomaly detection, and 0 indicates no tampering and normal processing.

[0066] Step S7: If tampering is detected, use the tamper positioning algorithm to locate the abnormal position and analyze the tampering type. The specific steps are as follows:

[0067] After detecting code tampering, use the tamper positioning algorithm to accurately locate the abnormal position. The core principle of this algorithm is to detect the integrity of the watermark in each segment based on the grouping watermark, and quickly determine the tampered group position by comparing the grouping hash values. Then, combined with the overall consistency of the global watermark, further determine whether the tampering involves the function instruction segment or the trajectory data segment, and distinguish the specific tampering type. First, extract the watermark of each group and compare it with the original watermark to mark the abnormal group. Then, verify the trajectory points or function instructions one by one within the abnormal group to distinguish the tampering type (such as deletion, insertion, or modification). Finally, through the position information of the watermark embedding point, mark the specific tampering position and generate a detailed detection report. Combined with the sensitivity of the grouping watermark and the overall consistency of the global watermark, this algorithm can improve the positioning accuracy to the instruction level or trajectory point level within the group. By comparing the watermarks segment by segment, determine the specific tampered paragraph, further analyze whether it is a function instruction segment or a trajectory data segment that has an anomaly, and record the tampering type in detail, such as deletion, insertion, or modification. This step ensures the accuracy of positioning, allowing the operator to clearly understand the specific location and impact range of tampering.

[0068] Step S8: Output the tamper positioning result and prompt the operator to take measures. The specific steps are as follows:

[0069] The results of tamper detection are fed back to the operator, including the integrity status of the NC code and detailed tampering information. If the code is complete, continue processing; if tampering is detected, the system prompts the operator to pause processing and take appropriate handling measures, such as regenerating the NC code or retransmitting reliable code. Through this process, the NC code integrity detection method effectively guarantees the safety and reliability of numerical control processing.

[0070] Example:

[0071] Attack test 1: When the attacker only deletes the entire row of trajectory data in G5 group, deletes the entire row of code with sequence number N1426, as shown in Figure 4 .

[0072] Receiver integrity test results and tampering possibility analysis: When performing group watermark detection at the receiver, only the fifth group, G5, was found to be abnormal; all other groups were normal. Groups G4 and G6 contained the special code segments above and below G5, and no abnormalities occurred in G4 and G6. This indicates that the abnormality can only occur in the trajectory data segment of group G5. When deleting the data of a single trajectory point in G5, including the sequence number of that row, if the sequence number is not adjusted, an interval error occurs, and the fixed interval becomes a multiple of the original. When the number of deleted rows is N, and the fixed interval is T, the fixed interval becomes T*(N+1).

[0073] Analysis results: The trajectory data segment of group G5 was deleted abnormally. The code had a fixed interval of 2, and the interval between N1428 and N1424 became 4, and N=1 lines of code were deleted.

[0074] Attack Test 2: NC code before the attack Figure 5 As shown in the figure, the attacker performs a deletion attack on the trajectory data of group G5, deletes 3 lines of code, and globally updates the sequence number.

[0075] The integrity test result of the code receiving end: It is found that the G5 group and all subsequent groups have abnormalities, such as Figure 6 As shown in Figure 2, the extracted global watermarks all show abnormalities.

[0076] Analysis of tampering possibility: When an attacker deletes the data of multiple track points in group G5, including the sequence number of the row, and readjusts the sequence number, the sequence numbers of all groups after G5 are tampered with. Since the sequence number also participates in the hash operation, all watermark verification fails. The attacker may have deleted or inserted code and readjusted the sequence number. To solve this problem, the present invention uses a sequence number shift detection algorithm. The process is as follows: Figure 7 As shown, by increasing or decreasing the global sequence number of the abnormal group to find a possible legal sequence number, the sequence number anomaly can be recovered, which is conducive to the advancement of tampering positioning work.

[0077] When the sequence number shift algorithm is used to try, the sequence numbers of each group after G5 are incremented. Each time the sequence number is incremented, the group after G5 is checked for integrity. If only the G5 check fails, it means that the attacker has deleted the trajectory data segment of the G5 group. If the sequence number increment is n intervals, it means that the number of deleted vertices is n. When the sequence number increment is 3, the sixth group and all subsequent groups have returned to normal. Figure 8 shown.

[0078] Analysis results: The G5 group trajectory data segment was attacked by deletion, with the marker number 3, indicating that 3 lines of code were deleted.

[0079] Attack test 3: the attacker deletes the code of the track data segment of G5 group and G 12 group at the same time and adjusts the sequence number.

[0080] Code receiving end integrity detection result: when receiving abnormal code at the receiving end, it is found that G5 group and subsequent groups are abnormal, as shown in Figure 9 .

[0081] Tampering possibility analysis: using the one-time sequence number shift detection method, it is found that G6 to G 11 group has returned to normal, but abnormality still occurs at G 12 and the following, as shown in Figure 10 , G 12 may be deleted or inserted by the attacker.

[0082] For the groups after G 12 , the sequence number shift detection method is used again for further judgment, and the incremental shift method is adopted, and the result is shown in Figure 11 , at this time only G5 group and G 12 group have abnormal watermarks, and after extracting the global watermark, the detection result is that the global special code segment is normal and the global track data segment is abnormal, so it can be judged that the tool track data of G5 group and G 12 group are all subjected to deletion attack. If other conditions occur, such as abnormality of a group after G 12 , the sequence number shift detection method is continued to be used for analysis, which will not be described here.

[0083] Analysis result: the track data segments of G5 group and G 12 group are subjected to deletion attack.

[0084] Attack test 4: the NC code before being attacked is shown in Figure 12 .

[0085] The attacker deletes D3 (N797), D4, and D5 points of G5 group, and after the deletion, adjusts the sequence number, and the corner at D2 point is greater than the threshold value of 90 degrees, and the tampering result is shown in Figure 13 .

[0086] Code receiving end integrity detection result: when receiving abnormal code at the receiving end, it is found that G5 group and subsequent groups are abnormal, as shown in Figure 14 .

[0087] Analysis of tampering possibility: The attacker's deletion of trajectory points will cause errors in grouping during the watermark extraction phase. In this test, the angle threshold is set to 90 degrees and the angle increment threshold is set to 2. Therefore, the original trajectory D2 (N796) is not considered a special code segment. After deleting points D3, D4, and D5, the angle threshold of point D2 is greater than 90 degrees, causing D2 to become a special code segment. The original G5 group is the group that was attacked by the deletion attack. After tampering, when the receiving end detects it, the original G5 group is divided into new Group and group, and the tampered trajectory data segments of the original G5 group are regarded as new The following special code snippet of the group and The special code segment above is at position D2 (N796). Because an additional set of watermarks is extracted based on deleting three points, All subsequent groups of the group had abnormal sequence numbers. The sequence number shift detection method was first used for analysis. The results were as follows Figure 15 As shown in the figure, after extracting the global watermark and performing integrity check, abnormalities were found.

[0088] Analysis results: Both the special code segment and the global watermark of the trajectory data will have anomalies, so we can only locate The following special code snippet of the group, Trajectory data segment, Group the special code segment above, The trajectory data segment, in essence, the positioning result is the trajectory data segment of the original G5 group. Due to the exception of the global special code segment, in addition to the new Group and All other groups outside the group are normal, which means that the abnormal location of the special code segment can only occur in The following special code snippet of the group and The above special code segments are grouped together, and these two special code segments are the same special code segment, so the exception occurs at D2 (N796).

Claims

1. A method for detecting NC code integrity anomalies based on fragile watermarks, characterized in that The method comprises the following steps: Step S1: Analyze the NC code tool trajectory coordinate data, extract its geometric characteristics and instruction information, and identify the characteristic trajectory area; Step S2: Based on the analysis of the tool path data, the NC code is divided into multiple program segments using a segmentation algorithm based on geometric features and instruction information. Each program segment consists of a group of trajectory data with similar characteristics or functions, including a function instruction segment and a trajectory data segment. In order to realize the division of the NC code program segments, it is set To realize the division method; in order to facilitate the processing of data in each group, set The NC code segment grouping data is converted into the standard segment grouping data format, which contains all the information of the original NC code. In order to achieve the purpose of generating watermarks, Implement according to key Generate Groups The hash value, then based on the key The process of extracting fixed bits from the generated hash value, and finally obtaining a fixed bit length , as shown in formula (1): (1) Where, The original NC code program content to be divided; NC code segment After using the partitioning algorithm groups; is the result of the division, a total of Group; For the standardized Group code; for peace Generate hash values ​​together; To determine the position of a fixed bit to be extracted from the generated hash value according to the key; Based on the hash value and Generated watermark information; Step S3: Generate group watermarks and global watermarks based on the characteristics of each program segment and the key used to generate the hash value of each program segment, and combine the watermark information with the trajectory data; Step S4: Apply watermark embedding technology to embed the watermark into the tool path coordinates of the NC code to ensure that the geometric shape remains unchanged; Step S5: After the NC code is transmitted, the embedded watermark is extracted using a watermark extraction algorithm and compared with the original watermark; Step S6: Based on the comparison result, determine whether the NC code has been tampered with. If not, perform normal processing. The NC code division algorithm divides the received NC code and standardizes the groups. According to the key Extract watermark information method, set Extract the original NC code and set Implement the restored NC code according to the key Generate a hash value and then use the key Extract fixed bits from the generated hash value and finally compare the extracted hash value with If they are exactly the same, it means no tampering has occurred, otherwise tampering has occurred, as shown in formula (3): (3) Where, is the received NC code; After the division Grouping; is the extracted watermark information; is the restored NC code; The output result of the test is in the form of a Boolean value, where 1 means that the test has been tampered with and anomaly detection is required, and 0 means that the test has not been tampered with and the processing can proceed normally. Step S7: If tampering is detected, use the tampering location algorithm to locate the abnormal position and analyze the tampering type; Step S8: Output the tampering positioning result and prompt the operator to take measures.

2. The NC code integrity anomaly detection method based on fragile watermark according to claim 1 is characterized in that The specific steps of step S1 are as follows: Step S11: Analyze the tool path data in the NC code in detail to identify its key characteristics; Step S12: Identifying characteristic trajectory regions with significant features in the NC code by extracting geometric characteristics of the tool motion; Step S13: extracting functional instruction information from the code to help divide different program segments, providing a clear segmentation basis for subsequent watermark embedding.

3. The NC code integrity anomaly detection method based on fragile watermark according to claim 1 is characterized in that The specific steps of step S3 are as follows: After the NC code is divided, an independent group watermark is generated for each program segment to ensure the integrity of each code segment. In addition, a global watermark is generated for overall integrity verification, where the watermark is generated based on the hash value of each group and the hash value is encrypted using a symmetric encryption key to increase security.

4. The NC code integrity anomaly detection method based on fragile watermark according to claim 1 is characterized in that In step S4, it is assumed that is the watermark embedding method, according to the key To select a watermark It is embedded into the position of the trajectory data to prevent the illegal extraction of watermark information and the leakage of the original NC code, thereby enhancing the security of the watermark information, as shown in formula (2): (2) Where, is the original NC code; It is used to determine the location of the embedded trajectory data; The part that is different from the original NC code after embedding the watermark, that is, the embedded trajectory data points, is the final NC code containing watermark.

5. The NC code integrity anomaly detection method based on fragile watermark according to claim 1 is characterized in that The specific steps of step S5 are as follows: When the NC code is transmitted, the embedded watermark information is extracted from the receiving end and compared with the original watermark: first, the group watermark is extracted and its consistency is verified segment by segment, and then the global watermark is extracted for overall comparison.

6. The NC code integrity anomaly detection method based on fragile watermark according to claim 1 is characterized in that The specific steps of step S6 are as follows: The integrity of the NC code is determined by extracting and comparing watermarks. If all watermarks are consistent, the code has not been tampered with and the normal processing process begins. If watermark inconsistencies are found, the code may have been tampered with. At this time, the system suspends the execution of the NC code and enters the next step of tamper detection and positioning to prevent incomplete code from affecting production safety.

7. The NC code integrity anomaly detection method based on fragile watermark according to claim 1 is characterized in that The specific steps of step S7 are as follows: After detecting code tampering, the tampering location algorithm is used to accurately locate the abnormal position. By comparing the watermarks section by section, the specific tampered section is determined. Further analysis is conducted to determine whether the abnormality occurs in the functional instruction section or the trajectory data section, and the type of tampering is recorded in detail.

8. The NC code integrity anomaly detection method based on fragile watermark according to claim 1 is characterized in that The specific steps of step S8 are as follows: The results of the tamper detection are fed back to the operator, including the integrity status of the NC code and detailed tampering information. If the code is intact, processing continues; if tampering is detected, the system prompts the operator to suspend processing and take appropriate measures, such as regenerating the NC code or retransmitting reliable code.