Main step of GOST 28147-89: Difference between revisions

m
(Add C# implementation)
 
(5 intermediate revisions by 2 users not shown)
Line 740:
for (let сч = 0; сч < 4; сч++) {
const яч = (S >>> (сч << 3)) & 0xFF;
нов_S += ТЗ[сч * 2][яч & 0x0F] + (ТЗ[сч * 2 + 1][яч >>> 4] << 4) << (сч << 3);
нов_S +=
ТЗ[сч * 2][яч & 0x0F]
+ (ТЗ[сч * 2 + 1][яч >>> 4] << 4)
<< (сч << 3);
}
нов_S = (нов_S << 11) + (нов_S >>> 21) & 0xFFFFFFFF ^ N[1];
нов_S =
(нов_S << 11)
+ (нов_S >>> 21)
& 0xFFFFFFFF
^ N[1];
N[1] = N[0]; N[0] = нов_S;
return N;
Line 787 ⟶ 780:
end
 
bytes2int(arr) = arr[1] + reinterpret(UInt32(arr[2]), << 8) + (UInt32(arr[3]) << 16) + (UInt32(arr[4begin])) << 24
int2bytes(x) = [UInt8reinterpret(x&0xff), UInt8((x&0xff00)>>8), UInt8(([x&0xff0000])>>16), UInt8(x>>24)]
 
function mainstep(inputbytes, keybytes)
Line 1,284 ⟶ 1,277:
<pre>
7CF881F 43B0421
</pre>
 
=={{header|RPL}}==
{{ trans|Nim}}
« { { 4 10 9 2 13 8 0 14 6 11 1 12 7 15 5 3 }
{ 14 11 4 12 6 13 15 10 2 3 8 1 0 7 5 9 }
{ 5 8 1 13 10 3 4 2 14 15 12 7 6 0 9 11 }
{ 7 13 10 1 0 8 9 15 14 4 6 12 11 2 5 3 }
{ 6 12 7 1 5 15 13 8 4 10 9 14 0 3 11 2 }
{ 4 11 10 0 7 2 1 13 3 6 8 5 9 12 15 14 }
{ 13 11 4 1 3 15 5 9 0 10 14 7 6 8 2 12 }
{ 1 15 13 0 5 7 10 4 9 2 3 14 6 11 8 12 } }
« R→B » DOLIST 'K' STO
{ K21 K43 K65 K87 } 1 « { } SWAP STO » DOLIST
0 255 '''FOR''' j
1 4 '''FOR''' n
'K' n 2 * GET j 16 / IP 1 + GET 16 *
'K' n 2 * 1 - GET j 16 MOD 1 + GET OR
'''NEXT'''
4 →LIST { K21 K43 K65 K87 } SWAP STO+
'''NEXT'''
» '<span style="color:blue">KBOXINIT</span>' STO
« { }
'''WHILE''' #0h ≠ '''REPEAT'''
OVER #255d AND SWAP OVER + SWAP SRB
'''END''' SWAP DROP
» '<span style="color:blue">B→LIST</span>' STO
« « SWAP SLB OR » → input key cast
« key REVLIST cast STREAM <span style="color:grey">@ convert key into a little-endian integer</span>
input 1 4 SUB REVLIST cast STREAM + <span style="color:blue">B→LIST</span> <span style="color:grey">@ same for input part 1, then add and back to list format</span>
{ K21 K43 K65 K87 } SWAP B→R 1 ADD GET <span style="color:grey">@ replace bytes according to the table</span>
REVLIST cast STREAM <span style="color:grey">@ back to little-endian format</span>
RLB RL RL RL <span style="color:blue">B→LIST</span> <span style="color:grey">@ roll 11 bits, back to list format</span>
input 5 8 SUB XOR <span style="color:grey">@ add part 2</span>
input 1 4 SUB + <span style="color:grey">@ append part 1</span>
» » '<span style="color:blue">MAINSTEP</span>' STO
« 32 STWS HEX
<span style="color:blue">KBOXINIT</span>
{ #21h #4h #3Bh #4h #30h #4h #32h #4h } { #F9h #4h #C1h #E2h } <span style="color:blue">MAINSTEP</span>
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: { # 1Fh # 88h # CFh # 7h # 21h # 4h # 3Bh # 4h }
</pre>