44 lines
1.3 KiB
Text
44 lines
1.3 KiB
Text
F ownCalcPass(password, nonce)
|
||
UInt32 result
|
||
V start = 1B
|
||
L(c) nonce
|
||
I c != ‘0’ & start
|
||
result = UInt32(Int(password))
|
||
start = 0B
|
||
S c
|
||
‘0’
|
||
{}
|
||
‘1’
|
||
result = rotr(result, 7)
|
||
‘2’
|
||
result = rotr(result, 4)
|
||
‘3’
|
||
result = rotr(result, 3)
|
||
‘4’
|
||
result = rotl(result, 1)
|
||
‘5’
|
||
result = rotl(result, 5)
|
||
‘6’
|
||
result = rotl(result, 12)
|
||
‘7’
|
||
result = (result [&] 0000'FF00) [|] result << 24 [|]
|
||
(result [&] 00FF'0000) >> 16 [|] (result [&] FF00'0000) >> 8
|
||
‘8’
|
||
result = result << 16 [|] result >> 24 [|] (result [&] 00FF'0000) >> 8
|
||
‘9’
|
||
result = ~result
|
||
E
|
||
X.throw ValueError(‘non-digit in nonce.’)
|
||
R result
|
||
|
||
F test_passwd_calc(passwd, nonce, expected)
|
||
V res = ownCalcPass(passwd, nonce)
|
||
V m = passwd‘ ’nonce‘ ’res‘ ’expected
|
||
I res == expected
|
||
print(‘PASS ’m)
|
||
E
|
||
print(‘FAIL ’m)
|
||
|
||
test_passwd_calc(‘12345’, ‘603356072’, 25280520)
|
||
test_passwd_calc(‘12345’, ‘410501656’, 119537670)
|
||
test_passwd_calc(‘12345’, ‘630292165’, 4269684735)
|