3.MD5 algorithm has the following characteristics: 3. 1 compressibility: for data with any length, the length of the calculated MD5 value is fixed.
3.2 Simple calculation: It is easy to calculate the MD5 value from the original data.
3.3 Anti-modification: If any modification is made to the original data, even if only 1 byte is modified, the MD5 values obtained are quite different.
3.4 Strong collision resistance: Knowing the original data and its MD5 value, it is difficult to find a data with the same MD5 value (that is, forged data).
The generated MD5 result itself is a hexadecimal number, which can be converted into the corresponding 10 decimal number. The following code is MD5 generated by C++:
# include & ltiostream & gt
# include & lt string & gt
Use? Namespace? std
# Definition? shift(x,? n)? (((x)? & lt& lt? (n))? |? ((x)? & gt& gt? (32-(n))// When moving to the right, the high bits must be filled with zeros instead of sign bits.
# Definition? F(x,? y,? z)? (((x)? & amp? (y))? |? ((~x)? & amp? (z)))
# Definition? G(x,? y,? z)? (((x)? & amp? (z))? |? ((y)? & amp? (~z)))
# Definition? H(x,? y,? z)? ((x)? ? (y)? ? (z))
# Definition? I (x,? y,? z)? ((y)? ? ((x)? |? (~z)))
# Definition? Answer? 0x6745230 1
# Definition? b? 0xefcdab89
# Definition? c? 0x98badcfe
# Definition? d? 0x 10325476
//the length of the //strBaye
Not signed? int? strlength
//temporary variables of a, b, c and d
Not signed? int? atemp
Not signed? int? btemp
Not signed? int? ctemp
Not signed? int? dtemp
//constant ti? Not signed? int(ABS(sin(I+ 1))*(2pow 32))
const? Not signed? int? k[]={
0xd 76 a478,0xe8c7b756,0x242070db,0xc 1bdceee,
0xf57c0faf,0x4787c62a,0xa83046 13,0xfd46950 1,0x698098d8,
0x8b44f7af,0xffff5bb 1,0x895cd7be,0x6b90 1 122,0xfd987 193,
0xa679438e,0x49b4082 1,0xf6 1e2562,0xc040b340,0x265e5a5 1,
0xe9b6c7aa,0xd62f 105d,0x0244 1453,0xd8a 1e68 1,0xe7d3fbc8,
0x2 1e 1cde6,0xc33707d6,0xf4d50d87,0x455a 14ed,0xa9e3e905,
0xfcefa3f8,0x676f02d9,0x8d2a4c8a,0xfffa3942,0x877 1f68 1,
0x6d9d6 122,0xfde5380c,0xa4beea44,0x4bdecfa9,0xf6bb4b60,
0x befbc 70,0x289b7ec6,0xeaa 127fa,0xd4ef3085,0x0488 1d05,
0xd9d4d039,0xe6db99e5,0x 1fa27cf8,0 C4 AC 5665,0xf4292244,
0x432aff97,0xab9423a7,0xfc93a039,0x655b59c3,0x8f0ccc92,
0xffeff47d,0x85845dd 1,0x6fa87e4f,0xfe2ce6e0,0xa30 143 14,
0x4e08 1 1a 1,0xf7537e82,0xbd3af235,0x2ad7d2bb,0 xeb 86d 39 1 };
//Number of shifts to the left
const? Not signed? int? s[]= { 7 12 17,22,7 12 17,22,7 12 17,22,7,
12, 17,22,5,9, 14,20,5,9, 14,20,5,9, 14,20,5,9, 14,20,
4, 1 1, 16,23,4, 1 1, 16,23,4, 1 1, 16,23,4, 1 1, 16,23,6, 10,
15,2 1,6, 10, 15,2 1,6, 10, 15,2 1,6, 10, 15,2 1};
const? Charles? str 16[]= " 0 123456789 abcdef ";
Invalid? Main loop (unsigned? int? M[])
{
Not signed? int? f,g;
Not signed? int? a = atemp
Not signed? int? b = btemp
Not signed? int? c = ctemp
Not signed? int? d = dtemp
For what? (unsigned? int? Me? =? 0; ? Me? & lt? 64; ? i++)
{
If (I <16) {
f=F(b,c,d);
g = I;
} something else? What if? (I & lt32)
{
f=G(b,c,d);
g =(5 * I+ 1)% 16;
} something else? If (I & lt48){
f=H(b,c,d);
g =(3 * I+5)% 16;
} Otherwise {
f=I(b,c,d);
g =(7 * I)% 16;
}
Not signed? int? tmp = d;
d = c;
c = b;
b=b+shift((a+f+k[i]+M[g]),shift
a = tmp
}
atemp = a+atemp;
b temp = b+ b temp;
ctemp = c+ctemp;
dt EMP = d+dt EMP;
}
/*
* Filling function
* after processing, bits≡448(mod5 12) and bytes≡56(mode64) shall be bytes.
* The filling method is to add a 1 first, and other bits are filled with zeros.
* Finally, add the original 64-bit length.
*/
Not signed? int*? Add (string? str)
{
Not signed? int? num =((str . length()+8)/64)+ 1; //Take 5 12 bits and 64 bytes as a group.
Not signed? int? *strByte=new? Not signed? int[num * 16]; //64/4= 16, so there are 16 integers.
strlength = num * 16;
For what? (unsigned? int? Me? =? 0; ? Me? & lt? num * 16; ? i++)
strByte[I]= 0;
For what? (unsigned? int? I = 0; ? Me? & ltstr . length(); ? i++)
{
strByte[I & gt; & gt2]| =(str[I])& lt; & lt((I % 4)* 8); //An integer stores four bytes, I >;; & gt2 stands for i/4? Unsigned Int corresponds to 4 bytes and stores 4 characters of information.
}
strByte[str . length()& gt; & gt2]| = 0x 80 & lt; & lt((((str . length()% 4))* 8); //Finally, add 1? Unsigned Int stores four characters of information, so use 128 to move left.
/*
* Plus the original length, the length refers to the length of bits, so you have to multiply it by 8, and then the small end, so you put it in the penultimate one, where the length is only 32 bits.
*/
strByte[num * 16-2]= str . length()* 8;
Return? strByte
}
String? changeHex(int? answer
{
int? b;
String? str 1;
String? str =
for(int? I = 0; I<4; i++)
{
str 1 = " ";
b =((a & gt; & gtI * 8)%( 1 & lt; & lt8))& amp; 0xff// Process each byte in reverse order.
For what? (int? j? =? 0; ? j? & lt? 2; ? j++)
{
str 1.insert(0, 1,str 16[b % 16]);
b = b/ 16;
}
str+= str 1;
}
Return? str
}
String? GetMD5 (string? Source)
{
atemp = A; //initialization
Bt EMP = B;
ctemp = C;
dt EMP = D;
Not signed? int? * strByte = add(source);
For (unsigned? int? I = 0; I< strlength/16; i++)
{
Not signed? int? No. [16];
For (unsigned? int? j = 0; j & lt 16; j++)
num[j]= strByte[I * 16+j];
Main loop (num);
}
Return? changeHex(atemp)。 append(changeHex(btemp))。 append(changeHex(ctemp))。 append(change hex(dt EMP));
}
int? Master ()
{
String? ss,t;
CIN & gt; & gtss; ? //Enter the string
t = ss+“ABC”; //Merge the input string with "abc"
Cou<& ltt<& ltendl// output the merged string.
String? s = get MD5(t); //Get the merged string md5
Cout & lt& lts<& ltendl// output results.
Return? 0;
}