RosettaCodeData/Task/OpenWebNet-password/11l/openwebnet-password.11l

45 lines
1.3 KiB
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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
2024-03-06 22:25:12 -08:00
result = ~result
2023-07-01 11:58:00 -04:00
E
2024-04-19 16:56:29 -07:00
X.throw ValueError(non-digit in nonce.)
2023-07-01 11:58:00 -04:00
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)