MD5/Implementation: Difference between revisions

Content added Content deleted
Line 1,177: Line 1,177:
private static int INIT_D = 0x10325476;
private static int INIT_D = 0x10325476;
private static int[] SHIFT_AMTS = new int[] {
private static int[] SHIFT_AMTS = {
7, 12, 17, 22,
7, 12, 17, 22,
5, 9, 14, 20,
5, 9, 14, 20,
Line 1,286: Line 1,286:
{
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();
String HEX_CHARS = "0123456789ABCDEF";
for (int i = 0; i < b.length; i++)
for (int i = 0; i < b.length; i++)
{
{
int n = (int)b[i] & 0xFF;
sb.append(String.format("%02X", b[i] & 0xFF));
sb.append(HEX_CHARS.charAt(n >>> 4)).append(HEX_CHARS.charAt(n & 0x0F));
}
}
return sb.toString();
return sb.toString();
Line 1,297: Line 1,295:
public static void main(String[] args)
public static void main(String[] args)
{
{
String[] testStrings = new String[] { "", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "12345678901234567890123456789012345678901234567890123456789012345678901234567890" };
String[] testStrings = { "", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "12345678901234567890123456789012345678901234567890123456789012345678901234567890" };
for (String s : testStrings)
for (String s : testStrings)
System.out.println("0x" + toHexString(computeMD5(s.getBytes())) + " <== \"" + s + "\"");
System.out.println("0x" + toHexString(computeMD5(s.getBytes())) + " <== \"" + s + "\"");
Line 1,315: Line 1,313:
0x57EDF4A22BE3C955AC49DA2E2107B67A <== "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
0x57EDF4A22BE3C955AC49DA2E2107B67A <== "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
</pre>
</pre>



=={{header|Modula-3}}==
=={{header|Modula-3}}==