MD5 and Crc__algorithm

Source: Internet
Author: User

MD5 and CRC are some sort of information digest algorithms.

MD5 can generate information summaries (126bits,16bytes) of information (which can be as large as a video file, or as small as a password). This information digest is equivalent to the digital signature of this information, which prevents the information from being tampered with.

CRC generates a summary of the length of the information 4bytes, and the source information is limited in size (less than 4GBytes).

CRC (cyclic redundancy check) cyclic redundancy check code

http://blog.csdn.net/liyuanbhu/article/details/7882789

CRC calibration Core is to specify a divisor, the implementation of borrow division operations, and the remainder as a checksum code. The so-called borrow Division refers to normal division, but the addition and subtraction of modulo 2 operation (XOR or).

MD5 Library Download Address http://download.csdn.net/detail/huang_yx005/9724535

/* Md5 number length/#define SMART_MD5NUMBER_SIZE                     16//Calculate the MD5 value of a piece of information from the first address as memory, the size is memorysize, and the result is stored in md5number static int calc_md5number (const char *memory, UINT Memorysize, Uchar *md5number) {if (NULL = = Memory | | NULL = = Md5number | |
  Memorysize = = 0) return 0;
  /* Do MD5 purity versification * * Md5_ctx mdcontext;
  Md5init (&mdcontext);
  Md5update (&mdcontext, (UCHAR *) memory, memorysize);
  Md5final (&mdcontext);
  memcpy (Md5number, Mdcontext.digest, smart_md5number_size);
return 1;
  }//Compare two MD5 values equal static int Equal_md5number (Uchar *md51, Uchar *md52) {UINT i = 0; if (NULL = = Md51 | |
  NULL = = md52) return 0;
  while (I < smart_md5number_size && Md51[i] = = Md52[i]) i++;
return i = = smart_md5number_size;
}//another example int bytes;
unsigned char data[1024];
Md5_ctx Tmp_mdcontext;
Md5init (&tmp_mdcontext); while ((bytes = fread (data, 1, 1024, fp_outtmp))!= 0)//From FileRead 1024 bytes of data in fp_outtmp to {md5update (&tmp_mdcontext, data, bytes);//update MD5 value fwrite (data, sizeof (unsigned char), b Ytes, fp_out);
Writes data to Fp_out} md5final (&tmp_mdcontext);
Write check code fprintf (fp_out, "md5\n");
Fwrite (tmp_mdcontext.digest, sizeof (unsigned char), fp_out);
Write version number fprintf (Fp_out, "ver\n");
 Fwrite (&version, sizeof (unsigned int), 1, fp_out);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.