Cryptographic algorithms are the core of data encryption, and their identification is a prerequisite for in-depth analysis of cryptography. Cryptographic algorithm identification is the process of distinguishing or identifying encryption methods by analyzing potentially distinctive information in the ciphertext when the ciphertext is known. It serves as the foundation for cryptanalysis work. The machine learning-based approach for identifying cryptographic algorithms extracts ciphertext features and trains the machine learning algorithm to build a cryptographic system identification classifier. It has the characteristics of high accuracy, concise operation process, and strong practicability. The ciphertext's complexity and the inter-data interference both rise with the number of cryptographic algorithms. This will lead to a reduction in the recognition rate of traditional machine learning cryptographic algorithm recognition solutions, poor recognition stability, and huge challenges to recognition capabilities. Deep learning algorithms have the characteristics of strong learning ability, a large amount of data processing, wide-coverage, good adaptability, and portability, etc., and have become a hot spot in the realm of cryptographic algorithm identification. In this work, a cryptographic algorithm identification methodology based on the Transformer algorithm is proposed, and the ciphertext feature extraction approach in the NIST randomness test is improved. In the research on cryptographic algorithm identification, we selected five block cipher algorithms: AES, 3DES, Blowfish, CAST, and RC2 as the research objects, and conducted two-class and five-class recognition experiments. According to experimental data, the approach suggested in this article has superior accuracy and stability than the classic machine learning model when the ciphertext size and other experimental variables are the same. Among them, on ciphertext files ranging from 1kb to 512kb, compared to the accuracy of the conventional classic machine learning algorithms SVM, GNB, KNN, RF, and LR, the average recognition accuracy of the two categories is 0.855, which is 29% higher. 33.9%, 28.5%, 34.2%, and 29.9%. Compared with the MLP accuracy of the same deep learning algorithm, the accuracy is also improved by 9%. When conducting the five-category experiment, the recognition accuracy of the scheme put forward in this piece is not less than 0.4. When the ciphertext file is 512KB, the recognition accuracy is as high as 0.42, and the average recognition accuracy of the five categories is 0.412. It is far greater than the other five classic machine learning algorithms and significantly better than the 20% random classification accuracy. Other algorithms' recognition rates fluctuate as ciphertext file sizes change. Among them, the Transformer algorithm has the smallest fluctuation and the best overall effect.