这个函数如何比较十六进制数?
How does this function compare hexnumbers?
var int a0 := 0x67452301 //A
var int b0 := 0xefcdab89 //B
var int c0 := 0x98badcfe //C
var int d0 := 0x10325476 //D
for each 512-bit chunk of message
break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15
//Initialize hash value for this chunk:
var int A := a0
var int B := b0
var int C := c0
var int D := d0
//Main loop:
for i from 0 to 63
if 0 ≤ i ≤ 15 then
F := (B and C) or ((not B) and D)
g := i
else if 16 ≤ i ≤ 31
F := (D and B) or ((not D) and C)
g := (5×i + 1) mod 16
else if 32 ≤ i ≤ 47
F := B xor C xor D
g := (3×i + 5) mod 16
else if 48 ≤ i ≤ 63
F := C xor (B or (not D))
g := (7×i) mod 16
dTemp := D
D := C
C := B
B := B + leftrotate((A + F + K[i] + M[g]), s[i])
A := dTemp
end for
//Add this chunk's hash to result so far:
a0 := a0 + A
b0 := b0 + B
c0 := c0 + C
d0 := d0 + D
end for
本文摘自维基百科,具体取自here,查看完整代码。
我不明白 (B and C)
产生的是什么,因为 B
和 C
是十六进制。 (大端)
B and C
是按位(32 位)布尔 AND 运算。因此,例如 int 15 (0xf) 和 17 (0x11) 结果为 1 (0x1)。
output/input 上数字的表示(十六进制或十进制)与对它们的操作无关。实际结果是 4 个 32 位整数,它们连接在一起 - 通常打印为单个大的十六进制字符串。
var int a0 := 0x67452301 //A
var int b0 := 0xefcdab89 //B
var int c0 := 0x98badcfe //C
var int d0 := 0x10325476 //D
for each 512-bit chunk of message
break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15
//Initialize hash value for this chunk:
var int A := a0
var int B := b0
var int C := c0
var int D := d0
//Main loop:
for i from 0 to 63
if 0 ≤ i ≤ 15 then
F := (B and C) or ((not B) and D)
g := i
else if 16 ≤ i ≤ 31
F := (D and B) or ((not D) and C)
g := (5×i + 1) mod 16
else if 32 ≤ i ≤ 47
F := B xor C xor D
g := (3×i + 5) mod 16
else if 48 ≤ i ≤ 63
F := C xor (B or (not D))
g := (7×i) mod 16
dTemp := D
D := C
C := B
B := B + leftrotate((A + F + K[i] + M[g]), s[i])
A := dTemp
end for
//Add this chunk's hash to result so far:
a0 := a0 + A
b0 := b0 + B
c0 := c0 + C
d0 := d0 + D
end for
本文摘自维基百科,具体取自here,查看完整代码。
我不明白 (B and C)
产生的是什么,因为 B
和 C
是十六进制。 (大端)
B and C
是按位(32 位)布尔 AND 运算。因此,例如 int 15 (0xf) 和 17 (0x11) 结果为 1 (0x1)。
output/input 上数字的表示(十六进制或十进制)与对它们的操作无关。实际结果是 4 个 32 位整数,它们连接在一起 - 通常打印为单个大的十六进制字符串。