Main step of GOST 28147-89: Difference between revisions

m
missing r32() call
m (→‎{{header|Perl 6}}: back-whack not needed)
m (missing r32() call)
Line 667:
sequence res = repeat(0,256)
for i=1 to length(res) do
res[i]integer hdx = or_bits(cbrf[k][floor((i-1)/16)+1]*16,cbrf[k-1][and_bits(i-1,#F)+1])
ldx = and_bits(i-1,#F)+1
res[i] = or_bits(cbrf[k][hdx]*#10,cbrf[k-1][ldx])
end for
return res
end function
 
constant k87 = generate(8),
k65 = generate(6),
k43 = generate(4),
k21 = generate(2)
 
function r32(atom a)
if a<0 then a+=#100000000 end if
return remainder(a,#100000000)
end function
 
function mainstep(sequence input, atom key)
atom s = r32(input[1]+key)
s = r32(or_all({k87[and_bits(floor(s/#1000000),#FF)+1]*#1000000,
k65[and_bits(floor(s/#100000010000),#FF)+1]*#100000010000,
k43[and_bits(floor(s/#1000000100),#FF)+1]*#1000000100,
k21[and_bits(floor(s/#0000001),#FF)+1]*#0000001}))
s = r32(s*power(2,11))+floor(s/power(2,32-11))
s = xor_bits(s,input[2])
return {s,input[1]}
end function
printf(1,"%08x %08x\n",mainstep({#043B0421, #04320430}, #E2C104F9))</lang>
{{out}}
<pre>
07CF801F07CF881F 043B0421
</pre>
 
7,806

edits