I have forgotten

• https://me.yahoo.com
COST (GBP)
1.00
0.00
0

# MD5

Implements the Message-Digest algorithm 5.
Controller: CodeCogs
Contents

C++

## Overview

This module implements the MD5 (Message-Digest algorithm 5) algorithm, which is a 128-bit valued hash function designed by Ron Rivest in 1991. Its main application is to check the integrity of data, but it can also be used in conjunction with cryptosystems like RSA.

The idea of the algorithm is to encode the input message using four 32-bit registers and by going through a series of bitwise operations, based on the following four functions:

$F(x,&space;y,&space;z)&space;:=&space;(x&space;\wedge&space;y)&space;\vee&space;(\neg&space;x&space;\wedge&space;z)$

$G(x,&space;y,&space;z)&space;:=&space;(x&space;\wedge&space;z)&space;\vee&space;(y&space;\wedge&space;\neg&space;z),$

$H(x,&space;y,&space;z)&space;:=&space;x&space;\oplus&space;y&space;\oplus&space;z,$

$I(x,&space;y,&space;z)&space;:=&space;y&space;\oplus&space;(x&space;\vee&space;\neg&space;z).$

The algorithm also uses a number of 64 constants $\inline&space;c_0$, $\inline&space;c_1$, ..., $\inline&space;c_{63}$ defined through:

$c_i&space;:=&space;\left\lfloor&space;2^{32}&space;\left|&space;\sin(i&space;+&space;1)&space;\right|&space;\right\rfloor,&space;\qquad&space;0&space;\leq&space;i&space;\leq&space;63,$

where $\inline&space;\lfloor&space;\cdot&space;\rfloor$ denotes the floor function.

The following example displays the MD5 code for the string "somewhere over the rainbow".

### Example 1

#include <iostream>
#include <codecogs/computing/security/md5.h>

int main()
{
std::string data = "somewhere over the rainbow";

std::cout << "Input: " << data << std::endl;
std::cout << "  MD5: " << Computing::Security::md5(data) << std::endl;

return 0;
}

Output
Input: somewhere over the rainbow
MD5: fe6acc5bea48d66ac6baa60ff73f6d62

### Authors

Lucian Bentea (July 2009)

### References

1. The MD5 Message-Digest Algorithm (RFC1321), http://tools.ietf.org/html/rfc1321
2. The description of the MD5 algorithm on Wikipedia, http://en.wikipedia.org/wiki/MD5
3. Free online MD5 hash calculator based on PHP, http://md5-hash-online.waraxe.us

## Md5

 std::stringmd5( std::string& str )[inline]
This function generates the unique MD5 code corresponding to the given string, in the form of a 32 digits hexadecimal number.

For example, to obtain the MD5 code of the string "Hello World", you would write something similar to:

std::string md5Code = Computing::Security::Hash::md5("Hello World");

### Parameters

 str the string to be hashed

### Returns

the MD5 code corresponding to str, as a 32 digits hexadecimal number stored as a string
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.