In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
The following code is the implementation of the MD5 algorithm in C++ language, the programming tool is VC2013. Although the encapsulation, security and efficiency of the code are far less than the standard implementation in RFC documents or the source code of OpenSSL (these codes have been studied for a long time and still not understood, their efficiency is high, but their readability is not high, so they are not suitable for children's shoes with a weak foundation), but the algorithm is more intuitive, clear and easy to understand, making it easy for children's shoes with a weak foundation to read. I belong to C++ beginners, the code may not be concise enough, not beautiful enough, many places are not thoughtful, I hope you will forgive me, but also hope that there can be experts to correct criticism.
Note: the MD5 operation is performed for every 64 characters processed. The MD5 algorithm itself is not too difficult, mainly because the preprocessing process of the input message is more troublesome.
# pragma warning (disable: 4996) / / VC2013 has added a security mechanism. If you don't add this sentence, a compilation error will occur # include#include#include#include#include using namespace std;typedef unsigned int UNINT / rename unsigned int to facilitate programming # define S11 7#define S12 12#define S13 17#define S14 22#define S21 5#define S22 9#define S23 14#define S24 20#define S31 4#define S32 11#define S33 16#define S34 23#define S41 6#define S42 10#define S43 15#define S44 21UNINT hash_state [4]; UNINT word_32 [16]; char block [64]; / / initialization Vector () {hash_state [0] = 0x67452301 Hash_state [1] = 0xefcdab89; hash_state [2] = 0x98badcfe; hash_state [3] = 0x10325476;} / / convert a character array of length 64 into an integer array of length 16, that is, convert four character array units into an integer array int char64_to_word32 (int n) {int i; for (I = 0; I)
< n; i++){ word_32[i] = (block[4 * i + 0] str; counter = str.length();//计算输入消息的长度 counter_update = counter; block_pos = 0; //对输入消息进行分组,每组64bytes while (counter_update / 64>0) {str.copy (block, 64,64 * block_pos); / / copy the next 64 characters starting at 64Secretj to the block array char64_to_word32 (16); / / convert 64 characters to 16 words / / MD5 MD5_Transform (word_32); block_pos++; counter_update-= 64 } if (counter_update% 64 = = 0) {newblock_length (counter); / / MD5 MD5_Transform (word_32);} else {/ / A packet of remaining insufficient 64bytes to process str.copy (block, counter_update, 64 * block_pos) / / if the last packet has insufficient 4bytes space to store the original message length, fill the packet with 0, and then create a new packet to store the message length if (counter_update > 60) {/ / convert the first 4k characters of the block array into k integers word_pos = char64_to_word32 (counter_update / 4) / / Update the last remaining characters of block counter_update-= 4 * word_pos; / / handle switch (counter_update) {case 0: {break differently depending on the results of the remaining character model 4. } / / if there is one character left, move it left to the highest 8 bits, followed by 24 bits to add 0 case 1: {word_32 [word_pos] = (block [4 * word_pos])
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.