MD5/Implementation: Difference between revisions

Content deleted Content added
No edit summary
Line 28: Line 28:


=={{header|Ada}}==
=={{header|Ada}}==
note: this could be dependant on the endianness of the machine it runs on - not tested on big endian.
note: this could be dependent on the endianness of the machine it runs on - not tested on big endian.


md5.ads:
md5.ads:
Line 974: Line 974:
}
}


var shift = []uint{7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21}
var shift = [...]uint{7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21}
var table [64]uint32
var table [64]uint32


func init() {
func init() {
for i := range table {
for i := range table {
d := math.Abs(math.Sin(float64(i + 1)))
table[i] = uint32((1 << 32) * math.Abs(math.Sin(float64(i + 1))))
table[i] = uint32((1 << 32) * d)
}
}
}
}
Line 1,282: Line 1,281:


=={{header|Java}}==
=={{header|Java}}==
{{works with|Java|1.5+}}

Based on RFC-1321.
Based on RFC-1321.
<lang java>
<lang java>
Line 1,288: Line 1,287:
{
{


private static int INIT_A = 0x67452301;
private static final int INIT_A = 0x67452301;
private static int INIT_B = (int)0xEFCDAB89L;
private static final int INIT_B = (int)0xEFCDAB89L;
private static int INIT_C = (int)0x98BADCFEL;
private static final int INIT_C = (int)0x98BADCFEL;
private static int INIT_D = 0x10325476;
private static final int INIT_D = 0x10325476;
private static int[] SHIFT_AMTS = {
private static final int[] SHIFT_AMTS = {
7, 12, 17, 22,
7, 12, 17, 22,
5, 9, 14, 20,
5, 9, 14, 20,
Line 1,300: Line 1,299:
};
};
private static int[] TABLE_T = new int[64];
private static final int[] TABLE_T = new int[64];
static
static
{
{
for (int i = 0; i < 64; i++)
for (int i = 0; i < 64; i++)
TABLE_T[i] = scaleToInt(Math.abs(Math.sin(i + 1)));
TABLE_T[i] = (int)(long)((1L << 32) * Math.abs(Math.sin(i + 1)));
}

private static int scaleToInt(double d)
{
// Converts IEEE-754 double from 0 to 1.0 to the range of an unsigned int
return (int)(long)((1L<<32) * d);
}
}