Cryptographic algorithm recognition method based on image recognition and attention convolutional neural network

By converting ciphertext data into color pixel images and constructing an attention convolutional neural network model, the problems of low accuracy and high computational complexity in existing cryptographic algorithm recognition technologies are solved, achieving efficient cryptographic algorithm recognition.

CN121600293APending Publication Date: 2026-03-03GUILIN UNIV OF ELECTRONIC TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-14
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing technologies have low accuracy and high computational complexity in identifying ciphertexts with unknown encryption algorithms, making it difficult to effectively distinguish between different cryptographic algorithms.

Method used

The encrypted data is converted into a color pixel image, an attention convolutional neural network model is constructed, and features are extracted through a multi-head attention mechanism to achieve cryptographic algorithm recognition.

Benefits of technology

It improves the accuracy of cryptographic algorithm recognition, reduces computational complexity, and has good versatility and recognition efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121600293A_ABST
    Figure CN121600293A_ABST
Patent Text Reader

Abstract

The invention discloses a cryptographic algorithm recognition method based on image recognition and an attention convolutional neural network. The cryptographic algorithm recognition method comprises the following steps: firstly, converting ciphertext data into a binary format; blocking the ciphertext data according to the size of 32 bits, converting each block into a color pixel block, and then forming a color pixel image; constructing and training an attention convolutional neural network model, and extracting features of the pixel map; and finally, aiming at unknown ciphertext data, using the trained model to complete cryptographic algorithm identification. According to the method, the information density in the image data can be increased by converting the ciphertext data into the color pixel image, and the difference between the ciphertext data encrypted by different cryptographic algorithms can be reflected more clearly, so that the accuracy of a final recognition result is improved; meanwhile, the attention mechanism and the convolutional neural network model are combined, feature association of different subspaces is better captured through the multi-head attention mechanism, the feature extraction capability of the convolutional neural network is improved, and the recognition accuracy of the model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of information security, specifically a cryptographic algorithm recognition method based on image recognition and attention convolutional neural networks. Background Technology

[0002] Many existing cryptanalysis techniques are designed based on the assumption that the cryptographic algorithms that generate ciphertext are known. In other words, identifying cryptographic algorithms is a prerequisite for conducting specific cryptanalysis. Therefore, identifying cryptographic algorithms has become a fundamental task in practical cryptanalysis.

[0003] Cryptographic algorithm identification involves extracting features from ciphertext encrypted with unknown encryption algorithms and analyzing the extracted feature values ​​to identify the encryption algorithm used to generate the ciphertext. Cryptographic algorithm identification primarily employs statistical methods and machine learning techniques. Statistical methods involve extracting various statistical indicators from the ciphertext for identification. Machine learning methods involve extracting features from the ciphertext, constructing a classifier, training a classification model on a training dataset based on the ciphertext features and defined algorithm labels, and then using the trained model to classify and predict test data containing only ciphertext features.

[0004] To effectively identify cryptographic algorithms, this invention proposes a cryptographic algorithm identification method based on image recognition and attention convolutional neural networks. This method converts ciphertext into binary format, divides it into blocks of fixed length, and converts the binary ciphertext data into color pixel images. An attention convolutional neural network model is constructed for training and testing to extract features from the pixel images and complete the cryptographic algorithm identification. Summary of the Invention

[0005] This invention proposes a cryptographic algorithm recognition method based on image recognition and attention convolutional neural networks. First, the ciphertext data is converted into binary format. Second, the ciphertext data is divided into blocks of 32 bits each, and each block is converted into a colored pixel block to form a colored pixel image of the ciphertext data. Third, an attention convolutional neural network model is constructed and trained to extract features from the pixel image. Finally, for unknown ciphertext data, the trained model is used to complete the cryptographic algorithm recognition.

[0006] The technical solution to achieve the objective of this invention is:

[0007] A password recognition method based on image recognition and attention convolutional neural networks specifically includes the following steps:

[0008] (1) Data preprocessing;

[0009] The plaintext is encrypted using various cryptographic algorithms to generate ciphertext data, and all ciphertext data is then converted into binary format.

[0010] (2) Convert the encrypted data into a color pixel image;

[0011] All binary format ciphertext data is divided into blocks of 32 bits each, and any insufficient parts are padded with zeros. Each block of data is then converted into a colored pixel block, which further forms a colored pixel image of the ciphertext data.

[0012] (3) Construction and training of attention convolutional neural network models;

[0013] Build and train a convolutional neural network model that incorporates an attention mechanism to extract features from pixel images;

[0014] (4) Password recognition based on a trained attention convolutional neural network model;

[0015] For unknown ciphertext data, a trained model is used to identify the cryptographic algorithm.

[0016] In the cryptographic algorithm identification method of the present invention, the data preprocessing in step (1) includes the following specific steps:

[0017] (1.1) Using k cryptographic algorithms, encrypt s pieces of plaintext data respectively to generate the corresponding ciphertext dataset CipherD={c1,c2,…,c i ,…,c v}, v = k × s, 1 ≤ i ≤ v; where 80% of the data is used as the training set data and the remaining 20% ​​of the data is used as the test set data;

[0018] (1.2) Convert all ciphertext data into binary format;

[0019] (1.3) For the training set data, according to the cryptographic algorithm corresponding to each ciphertext data, set the cryptographic algorithm label Lab. The value of the Lab label is the index 0 to k-1 of the cryptographic algorithm among the k cryptographic algorithms.

[0020] In the cryptographic algorithm identification method of the present invention, step (2) involves converting the ciphertext data into a colored pixel image, and the specific steps are as follows:

[0021] In computer graphics, a grayscale image typically consists of 8 bits forming a pixel; a color image is composed of three primary color components (R, G, B), each using 8 bits to represent its intensity, and an 8-bit alpha channel to represent the image's transparency and translucency. Thus, a color pixel image requires 32 bits. Compared to grayscale pixel images, color pixel images have higher information density and can more clearly present the distribution of colors and subtle differences in detail. If ciphertext data is converted into a color pixel image, the distribution of different colors and subtle differences in detail may reflect the differences between different cryptographic algorithms.

[0022] (2.1) In order to better extract the features of ciphertext data encrypted with different cryptographic algorithms and classify and identify them, the ciphertext data is divided into blocks of 32 bits each. If the last block is less than 32 bits, it is padded with zeros.

[0023] (2.2) Convert all blocks into color pixel blocks: According to the RGBA format, convert each block into a color pixel block using 32 bits. Input the 0-7 bits of the encrypted block data into the red channel, the 8-15 bits into the green channel, the 16-23 bits into the blue channel, and the 24-31 bits into the alpha channel.

[0024] (2.3) After converting all blocks of a ciphertext data into colored pixel blocks, arrange the colored pixel blocks from left to right and from top to bottom to form a colored pixel image of the ciphertext data.

[0025] (2.4) Convert all encrypted data into color pixel images using the method described above;

[0026] (2.5) Since different encryption algorithms generate ciphertext of different lengths, after converting the ciphertext data into color pixel images, these color pixel images may have different sizes. Neural networks cannot handle datasets with different dimensions, so it is necessary to unify the size of all color pixel images. The specific method is as follows:

[0027] (2.5.1) Calculate the average side length of all color pixel images and round it up to get the result e. Use e as the alignment standard.

[0028] (2.5.2) Use the Resize function to stretch all pixel images with a side length less than e to a side length of e; and compress pixel images with a side length greater than e to a side length of the average value, thereby unifying the size of all pixel images.

[0029] In the cryptographic algorithm identification method of the present invention, the construction and training of the attention convolutional neural network model in step (3) are as follows:

[0030] (3.1) Construct an attention-based convolutional neural network model;

[0031] From input to output, it consists of an input layer, two convolutional blocks, three fully connected layers, and an output layer.

[0032] The input layer does not process the data in any way; it is only responsible for importing the data into the model.

[0033] The two convolutional blocks have the same structure, and each convolutional block includes: a convolutional layer, a pooling layer, and an attention layer;

[0034] The attention layer employs a multi-head attention mechanism, which projects the input data through Query, Key, and Value projections respectively. Attention weights are calculated using Query and Key projections, and then a weighted sum is generated using Value projection based on the calculated attention weights to produce the attention output for the current position. Finally, the input data entering the attention layer is added to the weighted sum of the attention outputs, and the result is normalized before being output.

[0035] First convolutional block:

[0036] The kernel size of the convolutional layer is 3×3×16, the stride is 1, the padding is 1, and the activation function is Tanh.

[0037] The pooling kernel size of the pooling layer is 2×2, the step size is 1, the padding is 1, and the max pooling method is used.

[0038] The attention layer has a Query kernel size of 1×1×2, a Key kernel size of 1×1×2, and a Value kernel size of 1×1×2.

[0039] The second convolutional block:

[0040] The convolutional layer has a kernel size of 3×3×32, a stride of 1, padding = 1, and an activation function of Tanh.

[0041] The pooling kernel size of the pooling layer is 2×2, the step size is 1, the padding is 1, and the max pooling method is used.

[0042] The attention layer has a Query kernel size of 1×1×4, a Key kernel size of 1×1×4, and a Value kernel size of 1×1×4.

[0043] The fully connected layer 1 has 3072 neurons and uses the Tanh activation function; the fully connected layer 2 has 512 neurons and uses the Tanh activation function; the fully connected layer 3 has 64 neurons and uses the Tanh activation function.

[0044] The input dimension of the output layer is 64, the output dimension is the number of cryptographic algorithms used (k), and the activation function is Softmax.

[0045] (3.2) Model training;

[0046] (3.2.1) Training is performed using the training set data of the encrypted data and its label values ​​as input data;

[0047] (3.2.2) Set the batch size to 32, the learning rate to 0.001, the number of iterations to 100, the loss function to cross-entropy, and the optimizer to Adam;

[0048] (3.2.3) Terminate training when the network training reaches the maximum number of iterations.

[0049] In the cryptographic algorithm identification method of the present invention, step (4) involves cryptographic algorithm identification based on a trained attention convolutional neural network model. The specific steps are as follows:

[0050] (4.1) Test using the test set of encrypted data;

[0051] (4.2) Based on the trained attention convolutional neural network model, test the predicted label of the output ciphertext data to determine the cryptographic algorithm corresponding to the ciphertext data.

[0052] The beneficial effects of this invention are:

[0053] (1) The method of the present invention uses image recognition to identify cryptographic algorithms. Compared with grayscale pixel images, color pixel blocks have higher information density and can more clearly present the color distribution and subtle details. These differences may reflect the differences between ciphertext data encrypted with different cryptographic algorithms, thereby improving the accuracy of the final recognition result.

[0054] (2) The method of the present invention combines the attention mechanism and the convolutional neural network model. Through the multi-head attention mechanism, it can better capture the feature associations of different subspaces. In addition to effectively capturing the local features of the data, it can increase the ability to learn the global dependence and long-term correlation between the data, improve the feature extraction ability of the convolutional neural network, and improve the recognition accuracy of the model.

[0055] (3) The method of the present invention has good versatility, does not require the design of a feature extraction method, does not require the calculation of ciphertext features in data preprocessing, only requires the ciphertext generated image as input, which reduces computational complexity, reduces computational overhead, and improves the efficiency of model recognition. Attached Figure Description

[0056] Figure 1This is a flowchart of the cryptographic algorithm recognition method based on image recognition and attention convolutional neural network in the present invention;

[0057] Figure 2 This is a structural diagram of the attention convolutional neural network model in the method of this invention;

[0058] Figure 3 This is a structural diagram of the attention mechanism in the method of the present invention. Detailed Implementation

[0059] The present invention will be further described below with reference to the embodiments and accompanying drawings, but this is not intended to limit the scope of the invention.

[0060] Example

[0061] Reference Figure 1 A password recognition algorithm based on image recognition and attention convolutional neural networks includes the following steps:

[0062] (1) Data preprocessing;

[0063] (2) Convert the encrypted data into a color pixel image;

[0064] (3) Construction and training of attention convolutional neural network models;

[0065] (4) Password algorithm recognition based on a trained attention convolutional neural network model.

[0066] The data preprocessing described in step (1) includes the following specific steps:

[0067] (1.1) Using k cryptographic algorithms, encrypt s pieces of plaintext data respectively to generate the corresponding ciphertext dataset CipherD={c1,c2,…,c i ,…,c v}, v = k × s, 1 ≤ i ≤ v; where 80% of the data is used as the training set data and the remaining 20% ​​of the data is used as the test set data;

[0068] (1.2) Convert all ciphertext data into binary format;

[0069] (1.3) For the training set data, according to the cryptographic algorithm corresponding to each ciphertext data, set the cryptographic algorithm label Lab. The value of the Lab label is the index 0 to k-1 of the cryptographic algorithm among the k cryptographic algorithms.

[0070] The specific method for converting the encrypted data into a color pixel image in step (2) is as follows:

[0071] In computer graphics, a grayscale image typically consists of 8 bits forming a pixel; a color image is composed of three primary color components (R, G, B), each using 8 bits to represent its intensity, and an 8-bit alpha channel to represent the image's transparency and translucency. Thus, a color pixel image requires 32 bits. Compared to grayscale pixel images, color pixel images have higher information density and can more clearly present the distribution of colors and subtle differences in detail. If ciphertext data is converted into a color pixel image, the distribution of different colors and subtle differences in detail may reflect the differences between different cryptographic algorithms.

[0072] (2.1) In order to better extract the features of ciphertext data encrypted with different cryptographic algorithms and classify and identify them, the ciphertext data is divided into blocks of 32 bits each. If the last block is less than 32 bits, it is padded with zeros.

[0073] (2.2) Convert all blocks into color pixel blocks: According to the RGBA format, convert each block into a color pixel block using 32 bits. Input the 0-7 bits of the encrypted block data into the red channel, the 8-15 bits into the green channel, the 16-23 bits into the blue channel, and the 24-31 bits into the alpha channel.

[0074] (2.3) After converting all blocks of a ciphertext data into colored pixel blocks, arrange the colored pixel blocks from left to right and from top to bottom to form a colored pixel image of the ciphertext data.

[0075] (2.4) Convert all encrypted data into color pixel images using the method described above;

[0076] (2.5) Since different encryption algorithms generate ciphertext of different lengths, after converting the ciphertext data into color pixel images, these color pixel images may have different sizes. Neural networks cannot handle datasets with different dimensions, so it is necessary to unify the size of all color pixel images. The specific method is as follows:

[0077] (2.5.1) Calculate the average side length of all color pixel images and round it up to get the result e. Use e as the alignment standard.

[0078] (2.5.2) Use the Resize function to stretch all pixel images with a side length less than e to a side length of e; and compress pixel images with a side length greater than e to a side length of the average value, thereby unifying the size of all pixel images.

[0079] The construction and training of the attention convolutional neural network model described in step (3) are as follows:

[0080] (3.1) Construct an attention-based convolutional neural network model, referring to... Figure 2 ;

[0081] From input to output, it consists of an input layer, two convolutional blocks, three fully connected layers, and an output layer.

[0082] The input layer does not process the data in any way; it is only responsible for importing the data into the model.

[0083] The two convolutional blocks have the same structure, and each convolutional block includes: a convolutional layer, a pooling layer, and an attention layer;

[0084] Among them, reference Figure 3 The attention layer employs a multi-head attention mechanism, which projects the input data into the Query, Key, and Value layers respectively. Attention weights are calculated using the Query and Key projections, and then the Value projection is used to perform a weighted summation based on the calculated attention weights to generate the attention output for the current position. Finally, the input data entering the attention layer is added to the weighted summation output, and the result is normalized before being output.

[0085] First convolutional block:

[0086] The kernel size of the convolutional layer is 3×3×16, the stride is 1, the padding is 1, and the activation function is Tanh.

[0087] The pooling kernel size of the pooling layer is 2×2, the step size is 1, the padding is 1, and the max pooling method is used.

[0088] The attention layer has a Query kernel size of 1×1×2, a Key kernel size of 1×1×2, and a Value kernel size of 1×1×2.

[0089] The second convolutional block:

[0090] The convolutional layer has a kernel size of 3×3×32, a stride of 1, padding = 1, and an activation function of Tanh.

[0091] The pooling kernel size of the pooling layer is 2×2, the step size is 1, the padding is 1, and the max pooling method is used.

[0092] The attention layer has a Query kernel size of 1×1×4, a Key kernel size of 1×1×4, and a Value kernel size of 1×1×4.

[0093] The fully connected layer 1 has 3072 neurons and uses the Tanh activation function; the fully connected layer 2 has 512 neurons and uses the Tanh activation function; the fully connected layer 3 has 64 neurons and uses the Tanh activation function.

[0094] The input dimension of the output layer is 64, the output dimension is the number of cryptographic algorithms used (k), and the activation function is Softmax.

[0095] (3.2) Model training;

[0096] (3.2.1) Training is performed using the training set data of the encrypted data and its label values ​​as input data;

[0097] (3.2.2) Set the batch size to 32, the learning rate to 0.001, the number of iterations to 100, the loss function to cross-entropy, and the optimizer to Adam;

[0098] (3.2.3) Terminate training when the network training reaches the maximum number of iterations.

[0099] Step (4) involves performing password recognition based on a trained attention convolutional neural network model. The specific steps are as follows:

[0100] (4.1) Test using the test set of encrypted data;

[0101] (4.2) Based on the trained attention convolutional neural network model, test the predicted label of the output ciphertext data to determine the cryptographic algorithm corresponding to the ciphertext data.

[0102] Based on the method of this invention, 11 cryptographic algorithms were used as verification and identification objects, including AES, SM4, DES, RC4, Grain, RSA, SM2, SM3, SM9, SHA1, and MD5; three different types of datasets were used: text data, image data, and audio data. The text dataset consisted of classic foreign literary works, the image dataset used the CIFAR100 dataset, and the audio dataset used the RAVDESS dataset. Accuracy was used as the evaluation criterion. Test results showed that the method of this invention has high accuracy, with recognition accuracy rates of 80.8%, 99.7%, and 99.3% for text data, image data, and audio data, respectively.

Claims

1. A password recognition method based on image recognition and attention convolutional neural networks, comprising the following steps: (1) Data preprocessing; The plaintext is encrypted using various cryptographic algorithms to generate ciphertext data, and all ciphertext data is then converted into binary format. (2) Convert the encrypted data into a color pixel image; All binary format ciphertext data is divided into blocks of 32 bits each, and any insufficient parts are padded with zeros. Each block of data is then converted into a colored pixel block, which further forms a colored pixel image of the ciphertext data. (3) Construction and training of attention convolutional neural network models; Build and train a convolutional neural network model that incorporates an attention mechanism to extract features from pixel images; (4) Password recognition based on a trained attention convolutional neural network model; For unknown ciphertext data, a trained model is used to identify the cryptographic algorithm.

2. The cryptographic algorithm recognition method based on image recognition and attention convolutional neural networks according to claim 1, characterized in that, The data preprocessing described in step (1) includes the following specific steps: (1.1) Using k cryptographic algorithms, encrypt s pieces of plaintext data respectively to generate the corresponding ciphertext dataset CipherD={c1,c2,…,c i ,…,c v }, v = k × s, 1 ≤ i ≤ v; where 80% of the data is used as the training set data and the remaining 20% ​​of the data is used as the test set data; (1.2) Convert all ciphertext data into binary format; (1.3) For the training set data, according to the cryptographic algorithm corresponding to each ciphertext data, set the cryptographic algorithm label Lab. The value of the Lab label is the index 0 to k-1 of the cryptographic algorithm among the k cryptographic algorithms.

3. The cryptographic algorithm recognition method based on image recognition and attention convolutional neural networks according to claim 2, characterized in that, The specific method for converting the encrypted data into a color pixel image in step (2) is as follows: In computer graphics, a grayscale image typically consists of 8 bits forming a pixel; a color image is composed of three primary color components (R, G, B), each using 8 bits to represent its intensity, and an 8-bit alpha channel to represent the image's transparency and translucency. Thus, a color pixel image requires 32 bits. Compared to grayscale pixel images, color pixel images have higher information density and can more clearly present the distribution of colors and subtle differences in detail. If ciphertext data is converted into a color pixel image, the distribution of different colors and subtle differences in detail may reflect the differences between different cryptographic algorithms. (2.1) In order to better extract the features of ciphertext data encrypted with different cryptographic algorithms and classify and identify them, the ciphertext data is divided into blocks of 32 bits each. If the last block is less than 32 bits, it is padded with zeros. (2.2) Convert all blocks into color pixel blocks: According to the RGBA format, convert each block into a color pixel block using 32 bits. Input the 0-7 bits of the encrypted block data into the red channel, the 8-15 bits into the green channel, the 16-23 bits into the blue channel, and the 24-31 bits into the alpha channel. (2.3) After converting all blocks of a ciphertext data into colored pixel blocks, arrange the colored pixel blocks from left to right and from top to bottom to form a colored pixel image of the ciphertext data. (2.4) Convert all encrypted data into color pixel images using the method described above; (2.5) Since different encryption algorithms generate ciphertext of different lengths, after converting the ciphertext data into color pixel images, these color pixel images may have different sizes. Neural networks cannot handle datasets with different dimensions, so it is necessary to unify the size of all color pixel images. The specific method is as follows: (2.5.1) Calculate the average side length of all color pixel images and round it up to get the result e. Use e as the alignment standard. (2.5.2) Use the Resize function to stretch all pixel images with a side length less than e to a side length of e; and compress pixel images with a side length greater than e to a side length of the average value, thereby unifying the size of all pixel images.

4. The cryptographic algorithm recognition method based on image recognition and attention convolutional neural networks according to claim 3, characterized in that, The construction and training of the attention convolutional neural network model described in step (3) are as follows: (3.1) Construct an attention-based convolutional neural network model; From input to output, it consists of an input layer, two convolutional blocks, three fully connected layers, and an output layer. The input layer does not process the data in any way; it is only responsible for importing the data into the model. The two convolutional blocks have the same structure, and each convolutional block includes: a convolutional layer, a pooling layer, and an attention layer; The attention layer employs a multi-head attention mechanism, which projects the input data through Query, Key, and Value projections respectively. Attention weights are calculated using Query and Key projections, and then a weighted sum is generated using Value projection based on the calculated attention weights to produce the attention output for the current position. Finally, the input data entering the attention layer is added to the weighted sum of the attention outputs, and the result is normalized before being output. First convolutional block: The kernel size of the convolutional layer is 3×3×16, the stride is 1, the padding is 1, and the activation function is Tanh. The pooling kernel size of the pooling layer is 2×2, the step size is 1, the padding is 1, and the max pooling method is used. The attention layer has a Query kernel size of 1×1×2, a Key kernel size of 1×1×2, and a Value kernel size of 1×1×2. The second convolutional block: The convolutional layer has a kernel size of 3×3×32, a stride of 1, padding = 1, and an activation function of Tanh. The pooling kernel size of the pooling layer is 2×2, the step size is 1, the padding is 1, and the max pooling method is used. The attention layer has a Query kernel size of 1×1×4, a Key kernel size of 1×1×4, and a Value kernel size of 1×1×4. The fully connected layer 1 has 3072 neurons and uses the Tanh activation function; the fully connected layer 2 has 512 neurons and uses the Tanh activation function; the fully connected layer 3 has 64 neurons and uses the Tanh activation function; the input dimension of the output layer is 64, the output dimension is the number of cryptographic algorithms used k, and the activation function is Softmax. (3.2) Model training; (3.2.1) Training is performed using the training set data of the encrypted data and its label values ​​as input data; (3.2.2) Set the batch size to 32, the learning rate to 0.001, the number of iterations to 100, the loss function to cross-entropy, and the optimizer to Adam; (3.2.3) Terminate training when the network training reaches the maximum number of iterations.

5. The cryptographic algorithm recognition method based on image recognition and attention convolutional neural networks according to claim 4, characterized in that, Step (4) involves performing password recognition based on a trained attention convolutional neural network model. The specific steps are as follows: (4.1) Test using the test set of encrypted data; (4.2) Based on the trained attention convolutional neural network model, test the predicted label of the output ciphertext data to determine the cryptographic algorithm corresponding to the ciphertext data.