MD5 ek cryptographic hash function algorithm hai jo kisi bhi length ka message input ke taur par leta hai aur usko fixed-length 16 bytes ke message me convert kar deta hai. MD5 ka full form Message-Digest Algorithm hai. Yeh algorithm 1991 me Ronald Rivest ne develop kiya tha MD4 ka improved version banane ke liye, jisme security ko aur advance kiya gaya.

MD5 ka output hamesha 128 bits ka hota hai. Aaj bhi MD5 non-cryptographic functions ke liye kaafi use hota hai, jaise ki checksum ke taur par data integrity verify karne ke liye aur bade files ko securely chhoti size me compress karne ke liye. πŸš€

Working of the MD5 Algorithm

1. Append Padding Bits (Padding Bits Add Karna)

Is step me, original message ke end me kuch extra padding bits add ki jati hain taaki total length 512 ka exact multiple – 64 bits ho jaye.

πŸ’‘ Example:
Agar message 1000 bits ka hai, toh padding bits add karni padegi 472 bits tak ki total length 1472 bits ho jaye.

    • 1472 bits = (512 Γ— 3) – 64

    • (Kyuki 512 ka multiple 1536 hota hai, aur hume 64 bits kam chahiye)

Formula:

TotalΒ Length=(512Γ—i)βˆ’64\text{Total Length} = (512 \times i) – 64

Jaha i = 1,2,3… hota hai.

2. Append Length Bits (Length Bits Add Karna) πŸ“

Ab jo output Step 1 (padding bits added message) me mila tha, usme 64-bit length value bhi add karni padti hai.

πŸ›  Kaise?

    • Output of Step 1: 512Γ—nβˆ’64512 \times n – 64 bits

    • Add Length Bits: +64+ 64 bits

    • Final Length: 512Γ—n512 \times n (Jo ek perfect multiple of 512 hai)

Iska matlab, ab jo data hai uski length exact 512 ka multiple ho gayi, jo MD5 algorithm ke processing ke liye zaroori hoti hai. βœ…


3. Initialize MD Buffer (MD Buffer Initialize Karna) πŸ”„

Ab 4 buffers initialize kiye jate hain, jinme har ek 32-bit ka hota hai.

Buffer

Initial Value

A

0x67425301

B

0xEDFCBA45

C

0x98CBADFE

D

0x13DCE476

Yeh buffers hashing process ke dauraan continuously update hote hain. πŸš€

4. Process Each 512-bit Block (Har 512-bit Block Ko Process Karna) πŸš€

Yeh MD5 ka sabse important step hai, jisme 64 operations perform kiye jate hain 4 rounds me.

πŸ›  Breakdown of 4 Rounds:

    • 1st Round: 16 operations β†’ F function

    • 2nd Round: 16 operations β†’ G function

    • 3rd Round: 16 operations β†’ H function

    • 4th Round: 16 operations β†’ I function

Functions Used in Each Round:

Round

Function

Logic Gates Used

1st

F(B, C, D)

AND, OR

2nd

G(B, C, D)

AND, NOT

3rd

H(B, C, D)

XOR

4th

I(B, C, D)

XOR, NOT

Kaise Kaam Karta Hai? πŸ€”

    • Har function me B, C, aur D buffers ka use hota hai.

    • Logical operations (AND, OR, XOR, NOT) ka istemal hota hai data ko modify karne aur hash generate karne ke liye.

    • 64 operations hone ke baad, A, B, C, D buffers update ho jate hain.

Bas ek aur step bacha hai β€” Final Output Generate Karna! 🎯 Bataun ? 😎

5. Perform Operations on Each Block

MD5 ke hashing process me har 512-bit block par kuch mathematical operations perform hote hain, jo final hash output generate karne me madad karte hain.

Operations Required:

βœ… Add Modulo 2322^{32} – Overflow handle karne ke liye.
βœ… M[i]M[i] – 32-bit message block.
βœ… K[i]K[i] – 32-bit constant value.
βœ… <<< n – Left shift operation (n bits ka shift).

Kaise Kaam Karta Hai? πŸ€”

1️⃣ B, C, D buffers ka output liya jata hai β†’ Unpar F function lagaya jata hai.
2️⃣ Us output ko AA ke saath Modulo 2322^{32} add kiya jata hai.
3️⃣ Fir M[i]M[i] (message bit) add karte hain.
4️⃣ Fir ek constant K[i]K[i] add hota hai.
5️⃣ Left shift (<<< n) operation hota hai.
6️⃣ Last me result ko BB me feed kar dete hain.

πŸ”₯ Yehi steps baaki 3 functions (G, H, I) ke liye bhi follow kiye jate hain.

6. Final Output (Message Digest) 🎯

Jab 64 operations complete ho jate hain, to buffers (A, B, C, D) final MD5 hash output dete hain:

    • Lowest bits β†’ A

    • Highest bits β†’ D


C++ Implementation (Using OpenSSL)

Agar MD5 hash generate karna hai, to C++ ka OpenSSL library use kar sakte hain:

#include <iostream>
#include <iomanip>
#include <openssl/md5.h>
#include <cstring>
int main() {
Β Β Β Β Β Β Β Β Β Β  std::string inputstring = "This is a message sent by a computer user.";

// Hash generate karna
unsigned char digest[MD5_DIGEST_LENGTH];
MD5((unsigned char*)inputstring.c_str(), inputstring.length(), digest);
// Output print karna
std::cout << "Hash of the input string:" << std::endl;
for(int i = 0; i < MD5_DIGEST_LENGTH; i++) {
std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)digest[i];
}
std::cout << std::endl;
return 0;
}

βœ… Output Example:

Hash of the input string:
922547e866c89b8f677312df0ccec8ee

πŸ“Œ Applications of MD5 Algorithm

πŸ”Ή Data Integrity Check – Files ka checksum verify karne ke liye.
πŸ”Ή Password Storage (Lekin insecure hai!) – Pehle databases me passwords store karne ke liye use hota tha.
πŸ”Ή Version Control – Alag-alag file versions manage karne ke liye.
πŸ”Ή Digital Signatures & Certificates – Pehle use hota tha, ab SHA-256 prefer kiya jata hai.


βœ… Advantages of MD5

βœ” Fast aur simple – Jaldi hash generate karta hai.
βœ” 16-byte (128-bit) strong output deta hai.
βœ” Kam memory requirement hoti hai.
βœ” Web development me passwords hashing ke liye use hota tha (lekin ab safe nahi).


❌ Disadvantages of MD5

❌ Hash Collision – Alag inputs ke liye same hash generate ho sakta hai.
❌ Poor security – SHA-256 aur SHA-3 MD5 se better hai.
❌ Insecure – Modern cryptographic use cases ke liye recommended nahi.
❌ Not Symmetric or Asymmetric – Ye sirf ek one-way hash function hai.


πŸ”„ Modern Cryptography me MD5 Alternatives

πŸ”Ή SHA-256 – 256-bit secure hash function, Blockchain, SSL, Digital Signatures me use hota hai.
πŸ”Ή SHA-3 – Naya aur secure algorithm (SHA-2 ka alternative).
πŸ”Ή RIPEMD-160 – MD5 se better security, lekin SHA-2 jitna popular nahi.
πŸ”Ή Whirlpool – 512-bit hash function, strong security ke liye use hota hai.

error: Content is protected !!