1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//# the PYTHON way
import sys
from hashlib import md5
for arg in sys.argv[1:]:
    print md5(arg).hexdigest()

//# The Java way ...

import java.security.MessageDigest;
import java.math.BigInteger;

class MD5 {
    public String message;
    public MD5( String message ) {
        this.message = message;
    }
    public String hexdigest() throws Exception {
        String hd;
        MessageDigest md5 = MessageDigest.getInstance( "MD5" );
        md5.update( this.message.getBytes() );
        BigInteger hash = new BigInteger( 1, md5.digest() );
        hd = hash.toString(16); // BigInteger strips leading 0's
        while ( hd.length() < 32 ) { hd = "0" + hd; } // pad with leading 0's
        return hd;
    }
    public static void main( String[] args ) throws Exception {
        for ( String message: args ) {
            System.out.println( new MD5( message ).hexdigest() );
        }
    }
}