Intelligent comparison and analysis method and system for similarity of examination answer codes
By combining adaptive instrumentation and dynamic behavior features with static structural features, a unified code representation is constructed and an adversarial discriminant network is adopted, which solves the shortcomings of code plagiarism detection in existing technologies and achieves accurate identification and detection of multiple plagiarism strategies.
Patent Information
- Application Number
- CN202511086651.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-05
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-08-05
AI Technical Summary
Existing technologies rely too much on static feature analysis in code plagiarism detection, making it difficult to capture the dynamic execution behavior characteristics of the code. They lack adaptability and learning capabilities, and are unable to effectively identify diverse plagiarism strategies and emerging plagiarism techniques. The detection effect is particularly poor in large-scale examination scenarios.
Adaptive instrumentation technology is used to determine the optimal instrumentation location, collect the program's execution path sequence and memory access pattern, and combine static structural features to construct a dynamic behavior feature vector. Feature encoding network and adversarial discriminant network are used for multi-level recognition, generating a unified code representation, building a code similarity measurement model, and using a multi-level adversarial sample library for training to improve recognition capabilities.
It achieves accurate detection of code plagiarism, can identify shallow and deep deformations, improves the ability to identify different types of plagiarism strategies, and provides more reliable analysis of exam answer code similarity.
Smart Images

Figure CN120631735A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to educational information technology, and in particular to a method and system for intelligently comparing and analyzing the similarity of test answer codes. Background Art
[0002] In programming course teaching and examinations, code plagiarism seriously affects teaching quality and evaluation fairness. With the popularization of programming education and the widespread use of online examination platforms, automatic detection of code plagiarism has become particularly important. The main defects and shortcomings of existing technologies include: Existing code similarity detection methods overly rely on static feature analysis and ignore the dynamic execution behavior of programs. Plagiarists can circumvent detection based on static features by modifying variable names, adjusting code structure, and rewriting expressions. These modified codes still exhibit similar execution patterns and memory access characteristics at runtime, but existing technologies struggle to capture these deeper similarities.
[0003] Existing technologies lack the ability to adaptively identify diverse plagiarism strategies. Different types of code transformations require different detection strategies. For example, variable replacement requires focusing on identifier mapping relationships, while control flow reconstruction requires focusing on logical equivalence. Existing methods typically use a single similarity metric, making it difficult to simultaneously address multiple plagiarism strategies. Detection effectiveness is particularly degraded when dealing with mixed transformations.
[0004] Existing code similarity detection methods lack effective learning mechanisms to address the ever-evolving nature of plagiarism techniques. They rely on fixed rules and thresholds, making it difficult to learn from historical data about the changing patterns of plagiarism patterns and poorly adapting to emerging strategies. Especially in large-scale exam scenarios, existing technologies are unable to effectively leverage identified plagiarism cases to improve detection of similar plagiarism in the future. Summary of the Invention
[0005] The embodiments of the present invention provide a method and system for intelligently comparing and analyzing the similarity of test answer codes, which can solve the problems in the prior art.
[0006] A first aspect of an embodiment of the present invention provides a method for intelligently comparing and analyzing the similarity of test answer codes, including: The optimal instrumentation location is adaptively determined based on code complexity and characteristic path analysis of the exam code to be tested. The instrumented code is executed to collect the program's execution path sequence and memory access patterns. Timing correlation analysis is used to capture the execution timing dependencies between code snippets and construct a dynamic behavior feature vector. Extracting static structural features of the test answer code to be tested; fusing the static structural features with the dynamic behavior feature vector to construct a unified code representation; Based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork, which respectively recognize variable replacement deformation, control flow reconstruction deformation, and mixed deformation. During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable replacement samples, control flow reconstruction samples, and mixed deformation samples. The code similarity measurement model is used to calculate the similarity between the code to be tested and the answers of other candidates, identify and locate code fragments suspected of plagiarism, and generate a comparison analysis report.
[0007] In an optional embodiment, The steps for adaptively determining the optimal instrumentation location for the exam code to be tested based on code complexity and characteristic path analysis include: Establish a multi-dimensional code complexity index, the multi-dimensional code complexity index including a structural complexity index and a data flow complexity index; construct a path feature vector based on the multi-dimensional code complexity index, the path feature vector including the type characteristics of each node on the path and its corresponding weight; use the path feature vector to calculate the path importance based on the path complexity, execution frequency and data dependency, and identify the program execution path including conditional branch points, loop structure points and feature calculation points; Evaluate candidate insertion points on the program execution path, and determine the importance of the probe insertion location by calculating the information gain between the original system entropy and the conditional entropy after the probe is inserted; calculate the probe density based on the importance of the candidate insertion points, combined with the code segment length and local complexity weight, and optimize the insertion location; A lightweight probe is designed at an optimally selected insertion location, and the time overhead, memory overhead, and input / output overhead of the lightweight probe are calculated; and the probe sampling frequency is adaptively adjusted according to the ratio of the current overhead to the target overhead threshold.
[0008] In an optional embodiment, Execute the instrumented code, collect the program's execution path sequence and memory access pattern, and capture the execution timing dependencies between code snippets through timing correlation analysis. The steps for constructing a dynamic behavior feature vector include: Constructing a timing execution graph comprising a plurality of execution units, wherein edges in the timing execution graph represent timing dependencies between the execution units; calculating the timing dependency strength of the edges in the timing execution graph, wherein the timing dependency strength is determined by timing occurrence frequency and time interval characteristics; Generate a multi-order subgraph pattern based on the temporal dependency strength, and obtain support by calculating the ratio of the number of occurrences of the multi-order subgraph pattern in the execution trace to the total number of execution traces; construct an adversarial verification network, generate adversarial samples by randomly perturbing the execution sequence, and calculate a stability coefficient based on the difference in support of the subgraph pattern in the original execution sequence and the adversarial sample; and calculate a significance score based on a weighted combination of the support, the temporal dependency strength, and the stability coefficient; Extracting timing features of the timing execution graph, the timing features including timing pattern features calculated based on the timing dependency strength, the significance score, and execution sequence entropy; The path features of the execution path sequence, the memory features of the memory access pattern and the timing features are weightedly fused to construct a dynamic behavior feature vector.
[0009] In an optional embodiment, The steps of extracting static structural features of the test answer code to be tested; fusing the static structural features with the dynamic behavior feature vector to construct a unified code representation include: Extracting an abstract syntax tree of the test answer code, and constructing a data flow graph and a control flow graph based on the abstract syntax tree; extracting lexical features from the abstract syntax tree, the lexical features including a code identifier sequence, a reserved word sequence, and an operator sequence; Extracting data flow features from the data flow graph, wherein the data flow features include variable definition-use chains, type distribution of data dependency edges, and depth distribution of data flow paths; extracting control flow features from the control flow graph, wherein the control flow features include topological sequence of basic blocks, loop nesting depth, and branch structure complexity; Performing weighted combination on the lexical features, the data flow features, and the control flow features to obtain static structural features; An attention fusion network is constructed, the static structural features are used as query vectors, the dynamic behavior feature vectors are used as key-value pairs, and the fusion attention weights are obtained by calculating the correlation between the query vectors and the key-value pairs; the static structural features and the dynamic behavior feature vectors are adaptively fused based on the fusion attention weights to obtain a unified code representation.
[0010] In an optional embodiment, Based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork. The steps of respectively recognizing variable replacement deformation, control flow reconstruction deformation, and mixed deformation include: A multi-layer perceptron is used to construct a feature encoding network, a dimensionality reduction mapping is performed on the unified code representation to obtain an encoding vector, and the encoding vector is processed by L2 regularization constraint and feature normalization; Construct a local deformation recognition subnetwork, extract variable feature vectors based on the variable position matrix, calculate the variable similarity matrix, use the attention mechanism to calculate the variable replacement probability, and identify variable replacement deformation; Construct a global reconstruction identification subnetwork, extract basic block topology features to construct a control flow similarity matrix, calculate graph structure similarity based on the longest common subsequence, analyze the structural transformation distance of loop expansion and conditional reorganization, and identify control flow reconstruction-type deformations; A hybrid deformation recognition subnetwork is constructed, and the variable replacement type deformation features and the control flow reconstruction type deformation features are jointly analyzed through multi-level feature extraction and dual-stream feature fusion. Adaptive feature fusion mechanism and multi-scale context aggregation are used for hybrid deformation recognition.
[0011] In an optional embodiment, The steps of constructing the hybrid deformation recognition sub-network include: Perform multi-level feature extraction on the input features and construct a feature pyramid network containing backbone features and lateral connection features; Construct a dual-stream feature fusion network, obtain local deformation features through multi-layer perceptron processing, and obtain global reconstruction features through graph neural network processing; Adaptively fusing the local deformation feature and the global reconstruction feature based on a dynamic gating unit, wherein the dynamic gating unit calculates a gating vector using a learnable weight matrix and a bias vector, and uses a compression excitation module to calculate feature importance coefficients of the local deformation feature and the global reconstruction feature, and weightedly fuses the local deformation feature and the global reconstruction feature according to the gating vector and the feature importance coefficient to obtain a fused feature; Constructing an attention context pooling module, calculating the attention weights at multiple scales based on the fused features, extracting multi-scale context features from the fused features, adaptively fusing the context features at multiple scales, and performing a residual connection with the fused features to obtain the final features; The hybrid deformation pattern similarity and confidence score are calculated based on the final features, and the consistency of the final features under different data augmentation perspectives is constrained by feature consistency regularization.
[0012] In an optional embodiment, During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules. The steps for generating variable replacement samples, control flow reconstruction samples, and mixed deformation samples include: Calculate variable naming similarity based on the longest common subsequence, calculate usage pattern similarity based on the variable usage context set, and combine variable naming similarity and usage pattern similarity through a balance coefficient to generate a variable mapping matrix; Calculating a variable replacement probability based on the variable mapping matrix, generating a variable replacement sample according to the variable replacement probability, generating a control flow reconstruction sample based on a loop transformation function and a branch reorganization metric, and combining the variable replacement sample and the control flow reconstruction sample through a mixing weight coefficient to generate a mixed deformation sample; Constructing a hierarchical sample index structure, storing the variable replacement samples, control flow reconstruction samples, and mixed deformation samples in different levels, calculating sample difficulty based on variable complexity, structural complexity, and mixed complexity, and organizing samples at different levels according to the sample difficulty; The statistical model recognizes the error rates of samples at different levels, calculates the sample importance by combining the recognition error rate and the sample difficulty through an adjustment coefficient, and dynamically updates the samples in the hierarchical sample index structure based on the sample importance; The sampling probability is calculated according to the average importance of samples at different levels, and training batch samples are selected from the hierarchical sample index structure based on the sampling probability. The model is trained using cross-entropy loss and multi-task learning objectives, and the learning rate is adaptively adjusted based on the average recognition error rate of the batch samples.
[0013] A second aspect of an embodiment of the present invention provides an intelligent comparison and analysis system for similarity of test answer codes, including: The first unit analyzes the code complexity and characteristic paths of the exam code to be tested, adaptively determining the optimal instrumentation locations. Probe code for recording execution information is inserted at conditional branch points, loop structure points, and characteristic calculation points. The instrumented code is executed to collect the program's execution path sequence and memory access patterns. Timing correlation analysis is used to capture the execution timing dependencies between code snippets and construct dynamic behavior feature vectors. The second unit is used to extract the static structural features of the test answer code to be tested; perform feature fusion on the static structural features and the dynamic behavior feature vector to construct a unified code representation; The third unit is used to construct a code similarity measurement model based on the unified code representation using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork, which respectively recognize variable replacement deformation, control flow reconstruction deformation, and mixed deformation. During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable replacement samples, control flow reconstruction samples, and mixed deformation samples. Through adversarial training, the code similarity measurement model's ability to recognize different plagiarism strategies is improved. The fourth unit is used to use the code similarity measurement model to calculate the similarity between the code to be tested and the answers of other candidates, identify and locate code fragments suspected of plagiarism, and generate a comparison analysis report.
[0014] According to a third aspect of an embodiment of the present invention, an electronic device is provided, including: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the aforementioned method.
[0015] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method described above is implemented.
[0016] The present invention achieves more accurate examination answer code plagiarism detection through a code similarity analysis method that combines dynamic and static feature fusion and adversarial learning training, effectively solving the problem that traditional methods are susceptible to interference.
[0017] The present invention captures the dynamic behavior characteristics of the code through adaptive instrumentation and execution path analysis, and combines it with static structural characteristics to build a unified code representation, making similarity detection more comprehensive and accurate. It can identify shallow deformations such as simple replacement of variable names and adjustment of code order, as well as deep deformations such as control flow reconstruction.
[0018] The present invention adopts a multi-subnetwork adversarial learning architecture and a multi-level adversarial sample library to conduct special training for different types of code deformation strategies, which greatly improves the system's ability to identify various types of plagiarism methods. At the same time, it can accurately locate plagiarized code fragments, providing more reliable technical support for educational examinations. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 Schematic diagram of the process of intelligent comparison and analysis of test answer code similarity according to an embodiment of the present invention; Figure 2 Extract flow charts for dynamic behavior features; Figure 3 This is a comparison chart of mixed deformation code recognition accuracy; Figure 4 Comparison chart of recognition accuracy of adversarial sample training methods. DETAILED DESCRIPTION
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0021] The following specific embodiments are used to describe the technical solution of the present invention in detail. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0022] Figure 1 FIG. 1 is a flow chart of a method for intelligently comparing and analyzing similarity of test answer codes according to an embodiment of the present invention. Figure 1 As shown, the method includes: Based on code complexity and characteristic path analysis, the optimal instrumentation locations are adaptively determined for the exam code to be tested. Probe code for recording execution information is inserted at conditional branch points, loop structure points, and characteristic calculation points. The instrumented code is executed to collect the program's execution path sequence and memory access patterns. Timing correlation analysis is used to capture the execution timing dependencies between code snippets and construct a dynamic behavior feature vector. Extracting static structural features of the test answer code to be tested; fusing the static structural features with the dynamic behavior feature vector to construct a unified code representation; Based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork, which respectively identify variable replacement deformation, control flow reconstruction deformation, and mixed deformation. During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable replacement samples, control flow reconstruction samples, and mixed deformation samples. Through adversarial training, the code similarity measurement model's ability to recognize different plagiarism strategies is improved. The code similarity measurement model is used to calculate the similarity between the code to be tested and the answers of other candidates, identify and locate code fragments suspected of plagiarism, and generate a comparison analysis report.
[0023] In an optional embodiment, the step of adaptively determining the optimal insertion location for the test answer code to be tested based on code complexity and characteristic path analysis includes: Establish a multi-dimensional code complexity index, the multi-dimensional code complexity index includes a structural complexity index and a data flow complexity index, wherein the structural complexity index calculates McCabe cyclomatic complexity based on the number of edges, nodes and connected components of the control flow graph, calculates Halstead complexity based on the number of operators and the number of operands, and the data flow complexity index calculates variable activity based on the weight of program points and the frequency of variable use; construct a path feature vector based on the multi-dimensional code complexity index, the path feature vector includes the type characteristics of each node on the path and its corresponding weight; use the path feature vector to calculate the path importance according to the path complexity, execution frequency and data dependency, and identify the program execution path including conditional branch points, loop structure points and feature calculation points; Evaluate candidate insertion points on the program execution path, and determine the importance of the probe insertion location by calculating the information gain between the original entropy and the conditional entropy after the probe is inserted; calculate the probe density based on the importance of the candidate insertion points, combined with the code segment length and local complexity weight, and optimize the insertion location based on the probe density; A lightweight probe is designed at the optimally selected insertion location, and the time overhead, memory overhead, and input / output overhead of the lightweight probe are calculated. The probe sampling frequency is adaptively adjusted according to the ratio of the current overhead to the target overhead threshold to collect execution information of the program execution path.
[0024] Exemplary multi-dimensional metrics include structural complexity and data flow complexity. When analyzing the structural complexity metric, McCabe's cyclomatic complexity is calculated by analyzing the code's control flow graph. Specifically, the number of edges (E), the number of nodes (N), and the number of connected components (P) in the control flow graph are obtained. The cyclomatic complexity value is E-N+2P. For example, for a code snippet containing 10 edges, 8 nodes, and 1 connected component, its McCabe's cyclomatic complexity is 10-8+2×1=4. Halstead complexity is also calculated based on the number of operators and operands. For example, if a function contains 15 different operators and 10 different operands, with a total operator occurrence count of 40 and an operand occurrence count of 35, its program length is 75 and its program volume is 364.15. For the data flow complexity metric, variable activity is calculated by analyzing the weights of each point in the program (e.g., assignment points have a weight of 1, calculation points have a weight of 2, and conditional points have a weight of 3) and the frequency of variable usage. For example, variable x is used 10 times in a piece of code, 5 of which are used in high-weight points (conditional judgments), and its activity score is 25.
[0025] Based on the multi-dimensional code complexity metrics described above, a path feature vector is constructed. The feature vector for each execution path contains the type characteristics of each node along the path and its corresponding weight. Node types can be conditional nodes, loop nodes, or data processing nodes, with weights determined based on the node's complexity and importance. For example, a path containing two conditional branch points (each with a weight of 3), one loop structure point (with a weight of 5), and four data processing points (each with a weight of 2) would have a feature vector of [3, 3, 5, 2, 2, 2, 2].
[0026] Path importance is calculated using the path feature vector. This calculation is based on path complexity (the weighted sum of the vector's elements), execution frequency (estimated through static analysis or obtained through early monitoring), and data dependency (the number of key data dependencies involved in the path). For example, if the path complexity is 19, the execution frequency is 0.3 (accounting for 30% of total execution), and the data dependency is 5 (there are five key data dependencies on the path), then its importance is 19 × 0.3 × 5 = 28.5. This method identifies program execution paths that include conditional branch points, loop structure points, and characteristic computation points.
[0027] The importance of a probe insertion location is determined by calculating the information gain between the original entropy and the conditional entropy after probe insertion. For example, if the entropy of a candidate point before probe insertion is 4.5 and the conditional entropy after probe insertion is 2.1, the information gain at that point is 2.4, indicating that inserting a probe at this location can provide more information about program behavior. The probe density is calculated based on the importance (information gain) of the candidate insertion point, combined with the code segment length and local complexity weight. For a code segment of 100 lines, if the average probe density is set to 0.05 (one probe every 20 lines of code) and the local complexity weight of a segment is 1.5, the actual probe density for that segment should be 0.05 × 1.5 = 0.075 (approximately one probe every 13 lines of code). The calculated probe density is used to optimize the selection of insertion locations, ensuring sufficient monitoring points on the critical path while avoiding the performance overhead of excessive instrumentation.
[0028] Lightweight probes are designed at optimally selected instrumentation locations. These probes have minimized time overhead, memory overhead, and input / output overhead. For example, a lightweight probe that only records a timestamp and the current execution point identifier has a time overhead of approximately 0.5 microseconds and a memory overhead of 16 bytes. The input / output overhead depends on how the probe data is stored. For example, when a memory buffer is used, the input / output overhead is close to zero. The probe sampling frequency is adaptively adjusted based on the ratio of the current overhead to the target overhead threshold. For example, if the current probe execution frequency is 1000 times per second, resulting in a 5% performance overhead, and the target overhead threshold is set to 3%, the sampling frequency will be adjusted to 600 times per second. In this way, while ensuring monitoring accuracy, the impact of the probe on program performance can be controlled, and execution information of the program execution path can be efficiently collected.
[0029] This paper constructs an adaptive optimal insertion location determination mechanism using multi-dimensional code complexity metrics and path feature vectors. This mechanism comprehensively considers structural and data flow complexity to achieve precise selection of insertion points. This method not only intelligently identifies key execution points within a program but also assesses the importance of insertion locations based on information gain theory, optimizing probe density and addressing the high overhead and critical path omissions associated with blind insertion in traditional instrumentation methods.
[0030] In an optional embodiment, executing the instrumented code, collecting the execution path sequence and memory access pattern of the program, capturing the execution timing dependency between code snippets through timing correlation analysis, and constructing a dynamic behavior feature vector include the following steps: Collecting a program execution path sequence, the execution path sequence including multiple execution point information, the execution point information including the execution point type, the execution point timestamp, the basic block identifier of the execution point, and the execution point context information; constructing a memory access vector, the memory access vector including the memory access address, the memory access operation type, the memory access data size, and the memory access timestamp, and calculating the temporal locality hit rate and the spatial locality hit rate based on the memory access vector; Constructing a sequential execution graph comprising a plurality of execution units, wherein the execution units include an execution unit identifier, an execution unit type, an execution unit start timestamp, an execution unit end timestamp, and execution unit context information, wherein edges in the sequential execution graph represent sequential dependencies between the execution units; Calculating the timing dependency strength of the edges in the timing execution graph, where the timing dependency strength is determined by a timing occurrence frequency and a time interval characteristic, wherein the timing occurrence frequency is calculated as a ratio of the number of occurrences of a successor execution unit relative to a predecessor execution unit to the total number of executions of the predecessor execution unit, and the time interval characteristic is calculated as a ratio of a difference between a start time of the successor execution unit and an end time of the predecessor execution unit to an average execution interval; A multi-order subgraph pattern is generated based on the timing dependency strength, and support is obtained by calculating the ratio of the number of occurrences of the multi-order subgraph pattern in the execution trace to the total number of execution traces; an adversarial verification network is constructed, adversarial samples are generated by randomly perturbing the execution sequence, and a stability coefficient is calculated based on the difference in support of the subgraph pattern in the original execution sequence and the adversarial sample; a significance score is calculated based on a weighted combination of the support, the timing dependency strength, and the stability coefficient, where the stability coefficient is used to reduce the weight of timing patterns that are susceptible to perturbations; Extract the path features of the execution path sequence, the memory features of the memory access vector and the timing features of the timing execution graph, wherein: the path features include the path frequency statistics, the path transfer probability and the key node coverage calculated based on the execution point information; the memory features include the memory access pattern features, the temporal locality hit rate, the spatial locality hit rate and the memory access density calculated based on the memory access address and the memory access operation type; the timing features include the key timing pattern features, the significance score and the execution sequence entropy calculated based on the timing dependency strength; and perform weighted fusion on the path features, the memory features and the timing features to construct a dynamic behavior feature vector.
[0031] Combine Figure 2 The dynamic behavior feature extraction flow chart illustrates this. For example, when executing an instrumented program, detailed information is recorded for each execution point. Each execution point is represented as a tuple, containing the execution point type (e.g., function call, conditional branch, loop), a microsecond-accurate timestamp, a unique identifier for the basic block in which it resides, and execution context information (e.g., call stack depth, thread ID, etc.). For example, a function call execution point is recorded as ("CALL", 1623481597.283645, "BB_0x4a8c2f", {"stack_depth": 3, "thread_id": 1001}). This information is written to the execution trace buffer in real time and analyzed after program execution completes.
[0032] Memory access pattern collection is achieved by monitoring the program's read and write operations. Each memory access is recorded as a vector containing the access address, operation type (read / write), data size, and access timestamp. For example, a memory read operation is recorded as (0x7fff5fbff8a0, "READ", 4, 1623481597.283752). Based on these records, the temporal locality hit rate is calculated, which is the proportion of repeated accesses to the same address within a certain time window (e.g., 5 milliseconds). The spatial locality hit rate is also calculated, which is the proportion of accesses to adjacent memory areas (e.g., within the same cache line). For the test program, the temporal locality hit rate is approximately 78.3%, and the spatial locality hit rate is approximately 64.2%.
[0033] Execution trace sequences are segmented into multiple execution units, each representing a basic component of program behavior. An execution unit is represented by a five-tuple consisting of a unique identifier, type (such as function body, loop body, conditional branch block), start timestamp, end timestamp, and context information. For example, a function execution unit is represented as ("EU_0x4a8f2c", "FUNCTION", 1623481597.283645, 1623481597.285012, {"name":"process_data", "args_count":3}). A sequential execution graph is constructed based on these execution units, with nodes representing execution units and edges representing execution order.
[0034] When calculating the dependency strength of edges in a sequential execution graph, two key metrics are considered: the frequency of occurrence of the sequence and the time interval characteristic. The frequency of occurrence is calculated by calculating the ratio of the number of occurrences of the successor execution unit relative to the predecessor execution unit to the total number of executions of the predecessor execution unit. For example, if execution unit A is executed a total of 100 times, 80 of which are immediately followed by execution unit B, the frequency of occurrence of the sequence from A to B is 0.8. The time interval characteristic is calculated by calculating the difference between the start time of the successor execution unit and the end time of the predecessor execution unit, and then calculating the ratio to the average execution interval. If the time interval between two execution units is much smaller than the average interval, the dependency strength is higher.
[0035] Based on the strength of timing dependencies, subgraph patterns consisting of two to four nodes are extracted from the sequential execution graph. These patterns represent frequently occurring behavioral sequences in the program. For each subgraph pattern, its support in the execution trace is calculated, which is the ratio of its number of occurrences to the total number of execution traces. To evaluate the stability of these patterns, an adversarial verification network is constructed to generate adversarial examples by randomly inserting, deleting, or replacing execution units in the original execution sequence. The difference in support of the subgraph pattern in the original execution sequence and the adversarial example is compared to calculate the stability coefficient. A higher stability coefficient indicates that the pattern is less sensitive to perturbations and is more likely to be an essential behavioral characteristic of the program.
[0036] The support, temporal dependency strength, and stability coefficient are weighted together to calculate the significance score of each subgraph pattern. For example, a three-node subgraph pattern with a support of 0.75, an average temporal dependency strength of 0.82, and a stability coefficient of 0.93, when weights of 0.3, 0.3, and 0.4 are used, yields a significance score of 0.833.
[0037] Path features are extracted from the execution path sequence, including the execution frequency distribution of each basic block, the path transition probability matrix, and the coverage of key nodes (such as program entry points and error handling code). Memory feature extraction includes memory access pattern characteristics (such as the proportion of continuous access and the proportion of random access), the previously calculated temporal and spatial locality hit rates, and memory access density (the number of memory operations per unit time). Timing feature extraction calculates key timing pattern characteristics, significance scores, and execution sequence entropy (a measure of the randomness and predictability of the execution path) based on the strength of timing dependencies.
[0038] Path features, memory features, and timing features are weighted and integrated to form a dynamic behavior feature vector. In practice, different weights can be assigned to different features, for example, a weight of 0.4 for path features, 0.25 for memory features, and 0.35 for timing features. These weights can be determined through experimental optimization on a training dataset. The resulting feature vector typically has a dimension between 200 and 500 and captures key behavioral characteristics of the program's dynamic execution, which can be used for subsequent program behavior analysis, anomaly detection, or similarity comparison.
[0039] The adversarial verification network and stability coefficient assessment mechanism introduced in this paper's timing dependency analysis effectively identify and reduce the weight of timing patterns susceptible to perturbations, improving the robustness of feature extraction. A weighted combination of support calculation and significance scores for multi-order subgraph patterns addresses the inadequate assessment of execution sequence stability in traditional dynamic analysis, enabling the extracted dynamic behavior features to more accurately reflect the inherent characteristics of the code rather than sporadic execution characteristics.
[0040] In an optional embodiment, the steps of extracting static structural features of the test answer code to be tested; and fusing the static structural features with the dynamic behavior feature vector to construct a unified code representation include: Extracting an abstract syntax tree of the test answer code, and constructing a data flow graph and a control flow graph based on the abstract syntax tree; extracting lexical features from the abstract syntax tree, the lexical features including a code identifier sequence, a reserved word sequence, and an operator sequence; Extracting data flow features from the data flow graph, wherein the data flow features include variable definition-use chains, type distribution of data dependency edges, and depth distribution of data flow paths; extracting control flow features from the control flow graph, wherein the control flow features include topological sequence of basic blocks, loop nesting depth, and branch structure complexity; Performing weighted combination on the lexical features, the data flow features, and the control flow features to obtain static structural features; An attention fusion network is constructed, the static structural features are used as query vectors, the dynamic behavior feature vectors are used as key-value pairs, and the fusion attention weights are obtained by calculating the correlation between the query vectors and the key-value pairs; the static structural features and the dynamic behavior feature vectors are adaptively fused based on the fusion attention weights to obtain a unified code representation.
[0041] For example, when extracting the static structural features of the test answer code, the source code is first parsed to generate an abstract syntax tree (AST). For a sorting algorithm code, such as "for(int i = 0; i <n-1;i++){for(intj=0;j<n-i-1;j++){if(array[j]> The syntax analyzer converts the code into an AST, a tree structure containing information such as node types, variable names, and operators. Based on this AST, a data flow graph and a control flow graph are constructed. The data flow graph records the dependencies between variables, such as the reading and modification of the variable array in the loop body. The control flow graph represents the program execution path, including basic blocks and their jump relationships. For example, the above code can be decomposed into an initialization block, a conditional judgment block, a loop body block, and an end block.
[0042] When extracting lexical features from the AST, we traverse the tree structure and obtain three types of key sequences: code identifier sequences such as [i, j, array, swap], reserved word sequences such as [for, int, if], and operator sequences such as [=, <, >, +, -]. These sequences are encoded using frequency statistics or N-gram models. For example, for identifiers, their occurrences in the code are counted and normalized to obtain a vector representation.
[0043] During data flow feature extraction, the data flow graph is analyzed to obtain the definition-use chain of variables. For example, variable i is defined at the initialization of a for loop and used in the loop condition and the auto-increment expression, forming a chain relationship [def(i) → use(i) → use(i)]. The data dependency edge type distribution is analyzed, such as data definition dependencies accounting for 60%, control dependencies accounting for 25%, and output dependencies accounting for 15%. The depth distribution of the data flow path is also calculated, such as path depth 1 accounting for 50%, depth 2 accounting for 30%, and depth 3 accounting for 20%. This generates a feature vector [0.5, 0.3, 0.2].
[0044] When extracting control flow features, we first arrange the basic blocks in the control flow graph in topological order, generating a sequence such as [entry, loop_init, loop_cond, loop_body, if_cond, if_body, loop_incr, exit]. We then calculate the loop nesting depth. For example, the maximum nesting depth of the sorting algorithm described above is 2. Branching structure complexity is determined by calculating cyclomatic complexity. The cyclomatic complexity of this example code is 4, indicating that the code contains four independent paths.
[0045] After obtaining all static features, a weighted combination of lexical features, data flow features, and control flow features is performed. Weights are assigned based on feature importance, for example, lexical features have a weight of 0.3, data flow features have a weight of 0.4, and control flow features have a weight of 0.3. Each type of feature is first normalized to convert it into a vector of the same dimension, and then linearly combined according to the weights to generate the final static structural feature vector. For example, the lexical feature vector [0.25, 0.35, 0.4] is multiplied by a weight of 0.3, the data flow feature vector [0.5, 0.3, 0.2] is multiplied by a weight of 0.4, and the control flow feature vector [0.2, 0.5, 0.3] is multiplied by a weight of 0.3. The static structural feature vector [0.33, 0.37, 0.3] is accumulated.
[0046] During the feature fusion stage, an attention fusion network is constructed to adaptively fuse static structural features with dynamic behavioral features. The static structural feature vector serves as the query vector, and the dynamic behavioral feature vector serves as the key-value pair. For a sorting algorithm, for example, the static structural feature vector is [0.33, 0.37, 0.3], and the dynamic behavioral feature vector is [0.6, 0.25, 0.15]. The correlation between the query vector and the key-value pair is calculated to obtain an attention score. Assume that the calculated attention score is [0.7, 0.2, 0.1], indicating the relative importance of different dimensions of the static and dynamic features. These attention scores are used as fusion weights to perform a weighted fusion of the static and dynamic features. For example, multiplying the first dimension of the static feature vector (0.33) by a weight of 0.7, and the first dimension of the dynamic feature vector (0.6) by a weight of 0.3, results in a first-dimensional value of 0.4 for the fused feature. This calculation is repeated for other dimensions, ultimately yielding the fused unified code representation vector [0.4, 0.34, 0.26].
[0047] The method of fusing static structural features with dynamic behavioral features of the present invention can comprehensively capture the grammatical structure, data dependencies, control flow, and runtime behavior of the code. The generated unified code representation more comprehensively reflects the characteristics of the test answer code, providing an accurate feature basis for subsequent code similarity analysis and cheating detection.
[0048] In an optional embodiment, based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork. The steps of respectively recognizing variable substitution deformation, control flow reconstruction deformation, and mixed deformation include: A multi-layer perceptron is used to construct a feature encoding network, and a dimensionality reduction mapping is performed on the unified code representation to obtain an encoding vector. The encoding vector is processed through L2 regularization constraint and feature normalization, and the encoding vector is used as a unified feature input of a subsequent recognition network; Construct a local deformation recognition subnetwork, extract variable feature vectors based on the variable position matrix, calculate the variable similarity matrix, use the attention mechanism to calculate the variable replacement probability, and identify variable replacement deformation; Construct a global reconstruction identification subnetwork, extract basic block topology features to construct a control flow similarity matrix, calculate graph structure similarity based on the longest common subsequence, analyze the structural transformation distance of loop expansion and conditional reorganization, and identify control flow reconstruction-type deformations; A hybrid deformation recognition subnetwork is constructed, and the variable replacement type deformation features and the control flow reconstruction type deformation features are jointly analyzed through multi-level feature extraction and dual-stream feature fusion. Adaptive feature fusion mechanism and multi-scale context aggregation are used for hybrid deformation recognition.
[0049] Exemplarily, the feature encoding network uses a multilayer perceptron structure to achieve dimensionality reduction mapping of the unified code representation. The network consists of three fully connected layers, with the input layer having nodes equal to the dimensions of the unified code representation (e.g., 1024 dimensions), the hidden layer having 512 nodes, and the output layer having 256 nodes. Each fully connected layer is followed by a Reluctant Unit (ReLU) activation function to enhance nonlinear expression capabilities. To prevent overfitting, a Dropout layer is added after the first and second fully connected layers, with a dropout rate set to 0.3. The resulting 256-dimensional encoding vector is subjected to L2 regularization with a regularization coefficient set to 0.0001, followed by feature normalization to ensure that the L2 norm of the encoding vector is 1.
[0050] The local deformation recognition subnetwork focuses on identifying variable substitution deformations. This subnetwork first extracts variable features based on the variable usage position matrix in the unified code representation. The variable usage position matrix has dimensions n×m, where n is the number of variables in the code and m is the code length. For each variable, a context window (window size 5) is extracted for each occurrence in the code. This context encoding vector is then generated through the aforementioned feature encoding network. Specifically, for each occurrence of a variable, the code content of the two positions before and after the position is extracted as context. This context is converted into a unified code representation and fed into the feature encoding network to generate a 256-dimensional encoding vector. If a variable appears multiple times in the code, the context encoding vectors for all occurrences are collected and merged into a unified variable feature vector through average pooling to ensure that the usage pattern of the variable in different contexts is captured. The cosine similarity of the variable feature vectors of the two code copies is calculated pairwise to construct a variable similarity matrix S with dimensions n1×n2, where n1 and n2 are the number of variables in the two code copies. Each matrix element represents the degree of similarity between a variable in the first code copy and another variable in the second code copy. The attention mechanism is used to calculate variable substitution probabilities. This is achieved by applying softmax normalization to each row of the similarity matrix to obtain a probability distribution of variable correspondences. This process converts the similarity between each variable and all variables in the other code into a probability distribution. The variable with the highest probability is the potential substitution target. A similarity threshold of 0.75 is set; variables exceeding this threshold are considered to be variable substitution relationships.
[0051] The global reconstruction identification subnetwork is designed for control flow reconstruction-type deformations. This subnetwork extracts topological structural features of basic blocks, which are code fragments without branches. Control flow analysis is performed on the code, extracting basic blocks and their connections, and constructing a control flow graph. This process first parses the code into an abstract syntax tree (AST). Branch statements (such as if-else and switch-case) and loop statements (such as for and while) are identified to demarcate basic block boundaries. Each basic block contains a sequence of code that is executed continuously without internal jumps and is represented as a node in the control flow graph. Jump relationships between basic blocks are represented as directed edges. Each basic block is mapped to a vector representation via a feature encoding network. The mapping process merges the unified code representations of all statements within the basic block and inputs them into the feature encoding network, outputting a 256-dimensional vector. Based on these vector representations, a similarity matrix is calculated between the basic blocks in the two code copies to guide subsequent graph structure matching. The longest common subsequence algorithm is applied to the control flow graphs of the two codes to calculate graph structural similarity. The algorithm is implemented through iterative dynamic programming tables, filling in similarity values diagonally. Its time complexity is O(n1×n2), where n1 and n2 are the number of basic blocks in the two code copies. Loop unrolling is implemented by identifying basic block sequences with repetitive patterns. Repeated segments within a basic block sequence are detected, and loop unrolling is considered when a basic block sequence appears more than three times. Conditional reorganization is identified by analyzing the adjustments to if-else structures. The order of conditional branches in the original and target code is compared, and the minimum number of edit operations required to transform one permutation into another is calculated as the structural transformation distance, with a threshold of 2.
[0052] The hybrid deformation recognition subnetwork identifies code in complex scenarios where multiple deformation types coexist. This subnetwork captures code features at different levels of abstraction through a multi-layer feature extraction mechanism. Its implementation encompasses three levels of abstraction: the lexical layer (identifiers, keywords, etc.), the syntactic layer (syntax tree structure), and the semantic layer (data flow, control flow). The lexical layer analyzes the code to extract identifier sequences, keyword sequences, and operator sequences, capturing local lexical patterns using the n-gram model. The syntactic layer constructs an abstract syntax tree and extracts tree structural features, including tree depth, node type distribution, and subtree patterns. The semantic layer analyzes data dependencies and control flow relationships, identifying call relationships and data transfer between statements. A two-stream feature fusion architecture is used to jointly analyze variable substitution and control flow reconstruction deformation features. This two-stream architecture comprises two parallel processing channels: one processes variable features, extracting variable substitution patterns through a multi-layer fully connected network; the other processes control flow features, preserving topological structure information through a graph neural network. Features from these two channels are combined through an adaptive feature fusion mechanism, which first calculates the importance weights of the two feature types and then performs a weighted fusion based on these weights. The adaptive fusion mechanism includes an attention module that dynamically adjusts fusion weights based on feature importance. The attention calculation process first converts the two types of features into query, key, and value vectors. It then calculates the similarity between the query and key to obtain an attention score. Finally, the attention score is used to weight the value vector to produce the fusion result. Multi-scale context aggregation captures contextual information at varying scales by setting receptive fields of different sizes (3, 5, and 7, respectively). Smaller receptive fields capture local details, while larger ones capture broader structural features. Features at multiple scales together form a comprehensive code representation.
[0053] For example, given two codes, the corresponding encoding vectors are first generated by unifying the code representation, and then fed into the three sub-networks for similarity calculation. The final similarity judgment comprehensively considers the outputs of the three sub-networks, using a weighted average method with weights of 0.3 for local deformation, 0.3 for global reconstruction, and 0.4 for mixed deformation.
[0054] This paper constructs a three-in-one adversarial discriminant network architecture. The local deformation recognition subnetwork accurately identifies variable substitutions based on the variable position matrix and attention mechanism; the global reconstruction recognition subnetwork effectively captures control flow changes through topological structure analysis and longest common subsequence calculation; and the mixed deformation recognition subnetwork realizes the joint analysis of multiple deformation features. This multi-level, multi-dimensional recognition network design significantly improves the model's ability to identify various plagiarized deformation strategies, solving the problem that traditional similarity metrics cannot effectively identify carefully designed code deformations.
[0055] In an optional embodiment, the step of constructing the blend deformation recognition sub-network includes: Perform multi-level feature extraction on the input features and construct a feature pyramid network containing backbone features and lateral connection features; Construct a dual-stream feature fusion network, obtain local deformation features through multi-layer perceptron processing, and obtain global reconstruction features through graph neural network processing; Adaptively fusing the local deformation feature and the global reconstruction feature based on a dynamic gating unit, wherein the dynamic gating unit calculates a gating vector using a learnable weight matrix and a bias vector, and uses a compression excitation module to calculate feature importance coefficients of the local deformation feature and the global reconstruction feature, and weightedly fuses the local deformation feature and the global reconstruction feature according to the gating vector and the feature importance coefficient to obtain a fused feature; Constructing an attention context pooling module, calculating attention weights at multiple scales based on the fused features, extracting multi-scale context features from the fused features according to the attention weights at multiple scales, adaptively fusing the context features at multiple scales through learnable scale weights, and performing a residual connection with the fused features to obtain the final features; Based on the final feature, a mixed deformation pattern similarity score is calculated, and the mixed deformation pattern similarity score is used to characterize the degree of mixed deformation between codes; a confidence score is calculated, and the confidence score is used to characterize the reliability of the similarity judgment; data enhancement is performed on the final feature to obtain features of multiple enhanced perspectives, and the consistency of features under different enhanced perspectives is constrained by feature consistency regularization, thereby improving the model's robust recognition ability for mixed deformation.
[0056] For example, the construction of the hybrid deformation recognition subnetwork begins with multi-level feature extraction of the input features. The original code features are received as input, and a feature pyramid network is constructed using a convolutional neural network. The network consists of five convolutional layers, each with a 3×3 kernel size, a stride of 2, and 64, 128, 256, 512, and 1024 channels, respectively. Each convolution layer is followed by batch normalization and a ReLU activation function. The backbone features are extracted through a top-down path, while lateral connection features are obtained through skip connections. For example, the 512-channel feature map of the fourth layer is reduced to 256 channels through a 1×1 convolution and then fused with the upsampled high-level features through element-wise addition. This multi-level feature extraction mechanism ensures that the network can simultaneously capture both local details and global structural information of the code, providing a rich feature foundation for subsequent two-stream feature fusion. This is particularly important for code recognition with multiple deformation types.
[0057] The construction of the dual-stream feature fusion network is to obtain local deformation features and global reconstruction features simultaneously. For the local deformation feature branch, a three-layer multi-layer perceptron structure is adopted, with the number of neurons in each layer being 1024, 512, and 256, and the activation function being LeakyReLU. The input features are processed through these fully connected layers, which can effectively capture the local structural change features of the code. In practical applications, this branch can identify local deformation patterns such as variable substitution and statement rearrangement, such as the case of transforming "for(int i=0; i<n; i++)" into "for(int j=0; j<n; j++)". For the global reconstruction feature branch, a graph neural network is used. First, the code is represented as an abstract syntax tree, and the edges between nodes represent syntactic relationships. The graph convolutional network is used for message passing, and the output dimension of each layer of graph convolution is 256, with a total of 3 layers set. The global reconstruction feature can capture the overall structural information of the code and has strong robustness to global deformations such as code logic reconstruction and control flow transformation. For example, when rewriting the "if-else" structure as the "switch-case" structure, although the local code is completely different, the global semantics remain consistent. These two branches extract features from different perspectives, providing complementary information sources for subsequent dynamic gating fusion and enabling a comprehensive analysis of the code deformation features.
[0058] The dynamic gating unit contains a learnable weight matrix W with a size of 512×256 and a bias vector b with a size of 256. After concatenating the local feature vector and the global feature vector, multiply by W and then add b, and normalize through the sigmoid function to obtain the gating vector g, whose value range is from 0 to 1. The squeeze-and-excitation module processes the local feature and the global feature respectively. For each feature vector, first compress the dimension to 1 through global average pooling, then pass through two fully connected layers (the reduction ratio of the first layer is 16, and the second layer restores the original dimension) and the sigmoid activation function to obtain the local feature importance coefficient α and the global feature importance coefficient β. The final fused feature is calculated as: the local feature multiplied by g multiplied by α plus the global feature multiplied by (1 - g) multiplied by β. If the code mainly has local deformations such as variable substitution, the gating vector will bias towards the local feature branch; if there are global deformations such as control flow reconstruction, the gating vector will bias towards the global feature branch. This adaptive fusion mechanism can dynamically adjust the weights of different features according to the characteristics of the input code, greatly improving the recognition flexibility for mixed deformations while ensuring computational efficiency.
[0059] The attention context pooling module calculates attention weights at multiple scales based on the fused features: local (window size 3), medium (window size 5), and global (window size equal to the feature length). For each scale, attention scores are calculated using a two-layer fully connected network, with the first layer dimension of 128 and the second layer dimension of 1. Normalized attention weights are then obtained through a softmax function. The fused features are weighted averaged based on the attention weights at different scales to produce the contextual features at the corresponding scale. A learnable scale weight vector w of size 3 is also introduced. After softmax normalization, it is multiplied with the contextual features at the three scales and summed to produce the final contextual feature. This feature is then residually connected with the original fused feature to form the final feature representation. This multi-scale design enables simultaneous attention to both local relationships and global structure within the code. The residual connection ensures that the original feature information is not lost during processing, which is crucial for maintaining semantic coherence in the code and significantly improves recognition accuracy when processing long code sequences.
[0060] Based on the final features, the blending and deformation pattern similarity and confidence scores are calculated. The similarity score is implemented using a two-layer fully connected network with dimensions of 128 and 1, respectively. It is ultimately mapped to a range of 0 to 1 using a sigmoid function, representing the degree of blending between the two code segments, with larger values indicating a higher likelihood of deformation. The confidence score is calculated using another two-layer fully connected network, ultimately outputting a value between 0 and 1, indicating the reliability of the similarity judgment. During data augmentation, various enhancement strategies are applied to the final features, including feature masking (randomly setting 15% of the features to zero), feature perturbation (adding Gaussian noise with a standard deviation of 0.1), and feature blending (blending with random sample features in a ratio of 0.7:0.3). Feature consistency regularization is used to calculate the cosine similarity loss between the original and enhanced features, ensuring consistency in feature representation across different viewpoints, thereby improving the model's robust recognition of blending and deformation. The dual output design of similarity and confidence scores not only determines code similarity but also assesses the reliability of the judgment, which is particularly important when dealing with edge cases and complex deformations, effectively reducing the false positive rate. Feature consistency regularization simulates various possible code deformations through data augmentation, greatly expanding the diversity of training samples and improving the model's generalization ability when facing unknown deformation patterns.
[0061] Figure 3This is a comparison chart of mixed-shape code recognition accuracy. The horizontal axis represents the mixed-shape complexity (the ratio of variable substitution and control flow reconstruction); the vertical axis represents recognition accuracy. The chart compares three methods: the present invention (the mixed-shape recognition subnetwork), the traditional CNN+LSTM method, and the CodeBERT model. As can be seen from the chart, the recognition accuracy of all methods decreases with increasing mixed-shape complexity, but the present invention's method shows the smallest decrease, maintaining a consistently high recognition accuracy. This fully demonstrates the significant advantages of the present invention in processing complex mixed-shape codes, especially in highly complex mixed-shape cases.
[0062] This paper designs an innovative hybrid deformation recognition subnetwork structure, achieving multi-level feature extraction through a feature pyramid network and processing local deformation and global reconstruction features separately through a dual-stream feature fusion network. The core innovation lies in the adaptive feature fusion mechanism implemented by a dynamic gating unit, which intelligently adjusts the weights of different feature types based on feature importance coefficients. This effectively overcomes the technical difficulty of traditional code similarity analysis methods in identifying hybrid deformations involving both variable substitution and control flow reconstruction, significantly improving the accuracy of detecting carefully designed and complex plagiarism behaviors.
[0063] In an optional embodiment, during the training phase, the steps of automatically constructing a multi-level adversarial sample library based on heuristic rules to generate variable replacement samples, control flow reconstruction samples, and blend deformation samples include: Calculate variable naming similarity based on the longest common subsequence, calculate usage pattern similarity based on the variable usage context set, and combine variable naming similarity and usage pattern similarity through a balance coefficient to generate a variable mapping matrix; Calculating a variable replacement probability based on the variable mapping matrix, generating a variable replacement sample according to the variable replacement probability, generating a control flow reconstruction sample based on a loop transformation function and a branch reorganization metric, and combining the variable replacement sample and the control flow reconstruction sample through a mixing weight coefficient to generate a mixed deformation sample; Constructing a hierarchical sample index structure, storing the variable replacement samples, control flow reconstruction samples, and mixed deformation samples in different levels, calculating sample difficulty based on variable complexity, structural complexity, and mixed complexity, and organizing samples at different levels according to the sample difficulty; The statistical model recognizes the error rates of samples at different levels, calculates the sample importance by combining the recognition error rate and the sample difficulty through an adjustment coefficient, and dynamically updates the samples in the hierarchical sample index structure based on the sample importance; The sampling probability is calculated according to the average importance of samples at different levels, and training batch samples are selected from the hierarchical sample index structure based on the sampling probability. The model is trained using cross-entropy loss and multi-task learning objectives, and the learning rate is adaptively adjusted based on the average recognition error rate of the batch samples.
[0064] For example, for two variable names A and B, they are decomposed into character sequences. For example, the variable names "countTotal" and "totalCount" are decomposed into the character sequences "countTotal" and "totalCount", respectively. The naming similarity is obtained by calculating the length of the longest common subsequence of the two sequences (in this case, "otal" and "count", with a length of 9) and dividing it by the average length of the two sequences, for example, 9 / ((10+10) / 2)=0.9. For the variable usage context set, the three lines of code before and after each variable is used in the code are collected as the context. For example, the usage context of variable x includes statements such as "x=y+1;" and "if(x>10){". The usage pattern similarity is obtained by calculating the Jaccard similarity of the two variable context sets. For example, if two variables have a total of 5 similar contexts, with a total of 8 and 7 contexts respectively, the similarity is 5 / 10=0.5. The naming similarity and usage pattern similarity are combined with a balance coefficient of 0.7, resulting in a final variable mapping matrix value of 0.7×0.9+0.3×0.5=0.78.
[0065] For each variable pair (i, j), the replacement probability is proportional to the value in the mapping matrix. The final replacement probability is obtained by multiplying the mapping matrix value by the base replacement rate (default is 0.5). For example, for a variable pair with a mapping value of 0.78, the replacement probability is set to 0.78 × 0.5 = 0.39, indicating a 39% probability of replacement during sample generation. When generating variable replacement samples, all variables in the code are iterated over and a random number between 0 and 1 is generated for each variable. If the random number is less than the variable's replacement probability, the replacement is performed. During replacement, the target variable with the highest similarity is selected based on the mapping matrix, while ensuring that the replaced variable name does not conflict within the current scope. For example, replacing "countTotal" in the original code with "totalCount" and modifying all references simultaneously.
[0066] For control flow refactoring samples, the loop transformation function is a mapping table structure containing multiple transformation rules, primarily encompassing four types of transformations: for to while, while to for, do-while to while, and nested loop unrolling. Each transformation defines specific pattern matching rules and transformation templates. For example, the for to while transformation rule includes identifying the initialization statement, conditional expression, and iteration statement of the for loop, then moving the initialization statement to the beginning of the loop, using the conditional expression as the while condition, and moving the iteration statement to the end of the loop body. For example, "for(inti=0;i<10;i++){sum+=i;}" is transformed into "inti=0;while(i<10){sum+=i;i++;}". The branch refactoring metric includes four basic operations: negating the condition and swapping branches, splitting compound conditions, merging adjacent conditions, and extracting common code. Each operation is assigned a complexity score to comprehensively assess the difficulty of the structure's refactoring. For example, refactoring "if(x>0){A}else{B}" to "if(x<=0){B}else{A}" uses conditional inversion and swapping branch operations.
[0067] The blended deformation sample combines the first two types of deformations using a blending weight coefficient λ (0 ≤ λ ≤ 1). Specifically, the degree of variable substitution is determined based on the value of λ, and then control flow reconfiguration is applied at a ratio of (1-λ). For example, when λ = 0.6, variable substitution is first applied at a strength of 60% (i.e., the probability of variable substitution is multiplied by 0.6), followed by control flow reconfiguration at a strength of 40% (selecting 40% of the reconfigurable control flow for transformation).
[0068] When constructing a hierarchical sample index structure, variable replacement samples are stored in the first layer, control flow reconstruction samples are stored in the second layer, and mixed deformation samples are stored in the third layer. Variable complexity is calculated by the number and importance of replaced variables. For example, the complexity of a sample that replaces five core variables is 5 × 1.2 = 6. Structural complexity is calculated by the number of reconstructed control flow structures and their nesting depth. For example, reconstructing three control flow structures with a nesting depth of 2 results in a complexity of 3 × 2 = 6. Mixed complexity is the weighted sum of variable complexity and structural complexity, for example, 0.5 × 6 + 0.5 × 6 = 6. Samples at different levels are organized based on these complexity metrics. For example, in the first layer, samples with a complexity of 1-3 are grouped as simple, those with a complexity of 4-7 as medium, and those with a complexity of 8 or higher as complex.
[0069] The statistical model calculates the recognition error rate for samples at different levels. For example, the model's error rate for the first-level simple group is 10%, for the medium group is 25%, and for the complex group is 40%. The recognition error rate and sample difficulty are adjusted by a factor of 0.8 to calculate the sample importance. For example, for a sample with a complexity of 6 and an error rate of 25%, its importance is 0.8 × 6 + 0.2 × 25 = 7.8. Based on these importance values, the hierarchical sample index structure is dynamically updated. For example, samples with an importance exceeding 8 are promoted to a higher priority, while samples with an importance below 3 are demoted or removed.
[0070] Sampling probabilities are calculated based on the average importance of samples at different levels. For example, if the average importance of the first level is 5, the second level is 7, and the third level is 9, totaling 21, then the sampling probabilities for the three levels are 5 / 21≈0.24, 7 / 21≈0.33, and 9 / 21≈0.43, respectively. Based on these probabilities, training batches are selected from the hierarchical sample index structure. For example, in a batch of 100, 24 samples are selected from the first level, 33 samples from the second level, and 43 samples from the third level. A cross-entropy loss function is used to calculate the difference between the model's predictions and the true labels. Multi-task learning objectives are also introduced, such as simultaneously predicting the functional category and security risk level of code. The learning rate is adaptively adjusted based on the average recognition error rate of the batch samples. For example, when the average error rate is above 30%, the learning rate is reduced by 0.8 times; when the average error rate is below 10%, the learning rate is increased by 1.2 times. This ensures that the model effectively learns the characteristics of adversarial examples during training.
[0071] Figure 4 This is a comparison chart of the recognition accuracy of adversarial sample training methods. The horizontal axis of the chart shows three different code deformation recognition scenarios: variable replacement recognition, control flow reconstruction recognition, and mixed deformation recognition; the vertical axis represents the recognition accuracy percentage, ranging from 0% to 80%. Through the comparison of the bar charts, it can be clearly seen that the method of the present invention (hierarchical adversarial training) performs best in all three deformation recognition scenarios. Specifically: in the variable replacement recognition task and the control flow reconstruction recognition task, the method of the present invention is significantly higher than the traditional random sampling training and basic adversarial training. In the most challenging mixed deformation recognition task, the accuracy of the method of the present invention is 57.5%, while the traditional random sampling training is only 22.5%, and the basic adversarial training is 37.0%. The hierarchical adversarial training method of the present invention has shown obvious technical advantages in all test scenarios, especially when dealing with complex scenarios such as control flow reconstruction and mixed deformation, the improvement is more significant than the traditional method.
[0072] This paper establishes a sample importance assessment system based on recognition error rate and sample difficulty, enabling dynamic updating and priority adjustment of training samples. Adaptive calculation of sampling probability and dynamic adjustment of learning rate further optimize the model training process, addressing issues such as insufficient adversarial samples, uneven sample difficulty distribution, and low training efficiency in traditional code similarity model training. This hierarchical, adaptive adversarial training framework significantly enhances the model's recognition and generalization capabilities for various deformation strategies.
[0073] In an optional embodiment, the steps of using the code similarity measurement model to calculate the similarity between the code to be tested and the answers of other candidates, performing cluster analysis on the candidates' answers based on the similarity results, identifying and locating suspected plagiarized code fragments, and generating a comparison analysis report include: The code similarity measurement model is used to calculate the similarity scores between the code to be tested and the answers of other candidates in three dimensions: variable substitution similarity, control flow reconstruction similarity, and mixed deformation similarity; Based on the similarity scores of the three dimensions, a similarity feature matrix is constructed, and the density clustering algorithm is used to cluster the candidates' answers to obtain code groups with similar behavioral characteristics; Compare the codes in each code group in pairs, calculate the local similarity at the code snippet level based on the similarity feature matrix, and mark the code snippets whose local similarity exceeds the preset similarity threshold as suspected plagiarism snippets; Count the number and distribution of suspected plagiarized fragments in each candidate's answers, and combine the similarity scores of the three dimensions to generate a risk level assessment result; Generate a comparison analysis report that includes similarity analysis results, location information of suspected plagiarized fragments, and risk level assessment results.
[0074] Each code is evaluated based on three dimensions: variable substitution similarity, control flow reconstruction similarity, and mixed deformation similarity. For variable substitution similarity, the score is calculated using the variable mapping probability matrix output by the aforementioned local deformation recognition subnetwork; for control flow reconstruction similarity, the graph structure similarity results of the global reconstruction recognition subnetwork are used; and for mixed deformation similarity, the output score of the mixed deformation recognition subnetwork is used. For example, the three-dimensional similarity scores for a pair of codes A and B might be: variable substitution similarity 0.85, control flow reconstruction similarity 0.62, and mixed deformation similarity 0.74, indicating that the two codes have a high degree of variable substitution behavior and a certain degree of control flow change.
[0075] Based on the similarity scores across the three dimensions, a similarity feature matrix is constructed. Assuming 100 candidate answers, a 100×100×3 feature matrix is generated, where each position [i, j, k] represents the similarity score between the i-th code and the j-th code in the k-th dimension (k = 0, 1, and 2 correspond to the three similarity types, respectively). These feature vectors are clustered using DBSCAN (density-based spatial clustering algorithm), with a density parameter ε set to 0.15 and a minimum sample size of 3. During clustering, each code is treated as a point in three-dimensional space, with its coordinates determined by the average similarity across the three dimensions. For example, if a code has an average variable substitution similarity of 0.4, an average control flow reconstruction similarity of 0.3, and an average blend shape similarity of 0.5 with all other codes, its coordinates are (0.4, 0.3, 0.5). After clustering, multiple code groups are identified. Codes within each group are close to each other in the three-dimensional similarity space and share similar behavioral characteristics. For example, a group of five code snippets might be identified that all employ similar variable replacement and control flow refactoring strategies.
[0076] When comparing the codes within each code group, the algorithm is no longer limited to global similarity, but is refined to the code snippet level. First, the code is divided into multiple snippets by function or code block, and then the local similarity between each pair of snippets is calculated. The local similarity calculation uses a sliding window technique, with the window size set to 10 lines of code and a step size of 5 lines. For each window position, the feature vector of the current code snippet is extracted and compared with all window positions of the other code, and the highest similarity and its position are recorded. For example, the local similarity between lines 20-30 of code A and lines 35-45 of code B reaches 0.92, which is much higher than their global similarity of 0.75, which may indicate that this code is directly copied. Code snippets whose local similarity exceeds the preset threshold (usually set to 0.85) are marked as suspected plagiarized snippets and highlighted in the visual interface.
[0077] The number and distribution of suspected plagiarized fragments in each code are counted. For example, 30% of the content in Code A is marked as suspected plagiarism, mainly concentrated in the core algorithm implementation part; while 45% of the content in Code B is marked, with a more dispersed distribution. Combining the similarity scores of the three dimensions, a risk level assessment result is generated. The risk level is generally divided into four levels: low risk (similarity less than 0.5, the proportion of suspected plagiarized fragments is less than 10%), medium risk (similarity between 0.5-0.7, or the proportion of suspected plagiarized fragments is 10%-25%), high risk (similarity between 0.7-0.85, or the proportion of suspected plagiarized fragments is 25%-50%), and extremely high risk (similarity greater than 0.85, or the proportion of suspected plagiarized fragments is greater than 50%).
[0078] Finally, a multi-part comparison analysis report is generated, displaying overall statistics, including the number of similar code groups detected, the distribution of code by risk level, and typical cases. For each pair of similar code, a three-dimensional similarity radar chart, a code comparison view of suspected plagiarized sections (with color markings indicating the degree of similarity), and an analysis of the type of variation. For example, the report might state: "The similarity between code A and B is 0.82, placing it at a high risk level; the variation primarily utilizes variable substitution and loop expansion. Lines 125-157 are extremely similar to lines 98-130 of the counterpart code (similarity 0.96), suggesting direct copying followed by variable renaming."
[0079] The present invention can effectively deal with various forms of code plagiarism, provide educational institutions with an objective and reliable code duplication checking tool, and improve the fairness and effectiveness of programming teaching.
[0080] A second aspect of an embodiment of the present invention provides an intelligent comparison and analysis system for similarity of test answer codes, including: The first unit analyzes the code complexity and characteristic paths of the exam code to be tested, adaptively determining the optimal instrumentation locations. Probe code for recording execution information is inserted at conditional branch points, loop structure points, and characteristic calculation points. The instrumented code is executed to collect the program's execution path sequence and memory access patterns. Timing correlation analysis is used to capture the execution timing dependencies between code snippets and construct dynamic behavior feature vectors. The second unit is used to extract the static structural features of the test answer code to be tested; perform feature fusion on the static structural features and the dynamic behavior feature vector to construct a unified code representation; The third unit is used to construct a code similarity measurement model based on the unified code representation using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork, which respectively recognize variable replacement deformation, control flow reconstruction deformation, and mixed deformation. During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable replacement samples, control flow reconstruction samples, and mixed deformation samples. Through adversarial training, the code similarity measurement model's ability to recognize different plagiarism strategies is improved. The fourth unit is used to use the code similarity measurement model to calculate the similarity between the code to be tested and the answers of other candidates, identify and locate code fragments suspected of plagiarism, and generate a comparison analysis report.
[0081] According to a third aspect of an embodiment of the present invention, an electronic device is provided, including: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the aforementioned method.
[0082] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method described above is implemented.
[0083] The present invention may be a method, an apparatus, a system and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for executing various aspects of the present invention.
[0084] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An intelligent comparison and analysis method for similarity of test answer codes, characterized in that: include: The optimal instrumentation location is adaptively determined based on code complexity and characteristic path analysis of the exam code to be tested. The instrumented code is executed to collect the program's execution path sequence and memory access patterns. Timing correlation analysis is used to capture the execution timing dependencies between code snippets and construct a dynamic behavior feature vector. Extracting static structural features of the test answer code to be tested; fusing the static structural features with the dynamic behavior feature vector to construct a unified code representation; Based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork, which respectively recognize variable replacement deformation, control flow reconstruction deformation, and mixed deformation. During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable replacement samples, control flow reconstruction samples, and mixed deformation samples. The code similarity measurement model is used to calculate the similarity between the code to be tested and the answers of other candidates, identify and locate code fragments suspected of plagiarism, and generate a comparison analysis report.
2. The method according to claim 1, characterized in that The steps for adaptively determining the optimal instrumentation location for the exam code to be tested based on code complexity and characteristic path analysis include: Establish a multi-dimensional code complexity index, the multi-dimensional code complexity index including a structural complexity index and a data flow complexity index; construct a path feature vector based on the multi-dimensional code complexity index, the path feature vector including the type characteristics of each node on the path and its corresponding weight; use the path feature vector to calculate the path importance based on the path complexity, execution frequency and data dependency, and identify the program execution path including conditional branch points, loop structure points and feature calculation points; Evaluate candidate insertion points on the program execution path, and determine the importance of the probe insertion location by calculating the information gain between the original system entropy and the conditional entropy after the probe is inserted; calculate the probe density based on the importance of the candidate insertion points, combined with the code segment length and local complexity weight, and optimize the insertion location; A lightweight probe is designed at an optimally selected insertion location, and the time overhead, memory overhead, and input / output overhead of the lightweight probe are calculated; and the probe sampling frequency is adaptively adjusted according to the ratio of the current overhead to the target overhead threshold.
3. The method according to claim 1, characterized in that Execute the instrumented code, collect the program's execution path sequence and memory access pattern, and capture the execution timing dependencies between code snippets through timing correlation analysis. The steps for constructing a dynamic behavior feature vector include: Constructing a timing execution graph comprising a plurality of execution units, wherein edges in the timing execution graph represent timing dependencies between the execution units; calculating the timing dependency strength of the edges in the timing execution graph, wherein the timing dependency strength is determined by timing occurrence frequency and time interval characteristics; Generate a multi-order subgraph pattern based on the temporal dependency strength, and obtain support by calculating the ratio of the number of occurrences of the multi-order subgraph pattern in the execution trace to the total number of execution traces; construct an adversarial verification network, generate adversarial samples by randomly perturbing the execution sequence, and calculate a stability coefficient based on the difference in support of the subgraph pattern in the original execution sequence and the adversarial sample; and calculate a significance score based on a weighted combination of the support, the temporal dependency strength, and the stability coefficient; Extracting timing features of the timing execution graph, the timing features including timing pattern features calculated based on the timing dependency strength, the significance score, and execution sequence entropy; The path features of the execution path sequence, the memory features of the memory access pattern and the timing features are weightedly fused to construct a dynamic behavior feature vector.
4. The method according to claim 1, wherein Extract the static structural features of the test answer code to be tested; The steps of fusing the static structural features with the dynamic behavior feature vectors to construct a unified code representation include: Extracting an abstract syntax tree of the test answer code, and constructing a data flow graph and a control flow graph based on the abstract syntax tree; extracting lexical features from the abstract syntax tree, the lexical features including a code identifier sequence, a reserved word sequence, and an operator sequence; Extracting data flow features from the data flow graph, wherein the data flow features include variable definition-use chains, type distribution of data dependency edges, and depth distribution of data flow paths; extracting control flow features from the control flow graph, wherein the control flow features include topological sequence of basic blocks, loop nesting depth, and branch structure complexity; Performing weighted combination on the lexical features, the data flow features, and the control flow features to obtain static structural features; An attention fusion network is constructed, the static structural features are used as query vectors, the dynamic behavior feature vectors are used as key-value pairs, and the fusion attention weights are obtained by calculating the correlation between the query vectors and the key-value pairs; the static structural features and the dynamic behavior feature vectors are adaptively fused based on the fusion attention weights to obtain a unified code representation.
5. The method according to claim 1, characterized in that Based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork. The steps of respectively recognizing variable replacement deformation, control flow reconstruction deformation, and mixed deformation include: A multi-layer perceptron is used to construct a feature encoding network, a dimensionality reduction mapping is performed on the unified code representation to obtain an encoding vector, and the encoding vector is processed by L2 regularization constraint and feature normalization; Construct a local deformation recognition subnetwork, extract variable feature vectors based on the variable position matrix, calculate the variable similarity matrix, use the attention mechanism to calculate the variable replacement probability, and identify variable replacement deformation; Construct a global reconstruction identification subnetwork, extract basic block topology features to construct a control flow similarity matrix, calculate graph structure similarity based on the longest common subsequence, analyze the structural transformation distance of loop expansion and conditional reorganization, and identify control flow reconstruction-type deformations; A hybrid deformation recognition subnetwork is constructed, and the variable replacement type deformation features and the control flow reconstruction type deformation features are jointly analyzed through multi-level feature extraction and dual-stream feature fusion. Adaptive feature fusion mechanism and multi-scale context aggregation are used for hybrid deformation recognition.
6. The method according to claim 5, characterized in that The steps of constructing the hybrid deformation recognition sub-network include: Perform multi-level feature extraction on the input features and construct a feature pyramid network containing backbone features and lateral connection features; Construct a dual-stream feature fusion network, obtain local deformation features through multi-layer perceptron processing, and obtain global reconstruction features through graph neural network processing; Adaptively fusing the local deformation feature and the global reconstruction feature based on a dynamic gating unit, wherein the dynamic gating unit calculates a gating vector using a learnable weight matrix and a bias vector, and uses a compression excitation module to calculate feature importance coefficients of the local deformation feature and the global reconstruction feature, and weightedly fuses the local deformation feature and the global reconstruction feature according to the gating vector and the feature importance coefficient to obtain a fused feature; Constructing an attention context pooling module, calculating the attention weights at multiple scales based on the fused features, performing multi-scale context feature extraction on the fused features, adaptively fusing the context features at multiple scales, and performing a residual connection with the fused features to obtain the final features; The hybrid deformation pattern similarity and confidence score are calculated based on the final features, and the consistency of the final features under different data augmentation perspectives is constrained by feature consistency regularization.
7. The method according to claim 1, characterized in that During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules. The steps for generating variable replacement samples, control flow reconstruction samples, and mixed deformation samples include: Calculate variable naming similarity based on the longest common subsequence, calculate usage pattern similarity based on the variable usage context set, and combine variable naming similarity and usage pattern similarity through a balance coefficient to generate a variable mapping matrix; Calculating a variable replacement probability based on the variable mapping matrix, generating a variable replacement sample according to the variable replacement probability, generating a control flow reconstruction sample based on a loop transformation function and a branch reorganization metric, and combining the variable replacement sample and the control flow reconstruction sample through a mixing weight coefficient to generate a mixed deformation sample; Constructing a hierarchical sample index structure, storing the variable replacement samples, control flow reconstruction samples, and mixed deformation samples in different levels, calculating sample difficulty based on variable complexity, structural complexity, and mixed complexity, and organizing samples at different levels according to the sample difficulty; The statistical model recognizes the error rates of samples at different levels, calculates the sample importance by combining the recognition error rate and the sample difficulty through an adjustment coefficient, and dynamically updates the samples in the hierarchical sample index structure based on the sample importance; The sampling probability is calculated according to the average importance of samples at different levels, and training batch samples are selected from the hierarchical sample index structure based on the sampling probability. The model is trained using cross-entropy loss and multi-task learning objectives, and the learning rate is adaptively adjusted based on the average recognition error rate of the batch samples.
8. An intelligent comparison and analysis system for similarity of test answer codes, for implementing the method according to any one of claims 1 to 7, characterized in that: include: The first unit analyzes the code complexity and characteristic paths of the exam code to be tested, adaptively determining the optimal instrumentation locations. Probe code for recording execution information is inserted at conditional branch points, loop structure points, and characteristic calculation points. The instrumented code is executed to collect the program's execution path sequence and memory access patterns. Timing correlation analysis is used to capture the execution timing dependencies between code snippets and construct dynamic behavior feature vectors. The second unit is used to extract the static structural features of the test answer code to be tested; Fusing the static structural features with the dynamic behavior feature vectors to construct a unified code representation; The third unit is used to construct a code similarity measurement model based on the unified code representation using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a mixed deformation recognition subnetwork, which respectively recognize variable replacement deformation, control flow reconstruction deformation, and mixed deformation. During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable replacement samples, control flow reconstruction samples, and mixed deformation samples. Through adversarial training, the code similarity measurement model's ability to recognize different plagiarism strategies is improved. The fourth unit is used to use the code similarity measurement model to calculate the similarity between the code to be tested and the answers of other candidates, identify and locate code fragments suspected of plagiarism, and generate a comparison analysis report.
9. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Test case multiplexing method based on program path similarity
CN116627818A
Deep learning code plagiarism detection method based on multi-head attention mechanism
CN116738963A
Method and system for quickly constructing and multiplexing application framework
CN119576290A
Method and system for analyzing similarity of software codes
CN119988185A
Multi-modal feature fusion software supply chain vulnerability intelligent positioning method
CN120068095A
Cited By
Enterprise information dynamic modeling method based on multi-dimensional data driving
CN120874855A
An intelligent invigilation method and system based on multi-modal fusion
CN122416377A