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