forked from Bhavya1912/Hackerrank-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaMD5.java
More file actions
25 lines (22 loc) · 775 Bytes
/
JavaMD5.java
File metadata and controls
25 lines (22 loc) · 775 Bytes
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.security.*;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
byte[] message = s.getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] hash = md.digest(message);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < hash.length; i++) {
sb.append(Integer.toString((hash[i] & 0xff) + 0x100, 16).substring(1));
}
System.out.println(sb.toString());
//String encrypted = hash.toString();
//System.out.println(encrypted);
}
}