GOST 28147-89 is a standard symmetric encryption based on a Feistel network.



The structure of the algorithm consists of three levels:

   encryption modes - simple replacement, application range, imposing a range of feedback and authentication code generation;
   cycles - 32-З, 32-Р and 16-З, is a repetition of the main step;
   main step, a function that takes a 64-bit block of text and one of the eight 32-bit encryption key elements, and uses the replacement table (8x16 matrix of 4-bit values), and returns encrypted block.


Task

Implement the main step of this encryption algorithm.




        .386
        .model  flat
        .code
_gost32 proc    near32
        public  _gost32
; The inner loop of a subroutine
; 1. Beginning of the cycle, and preservation of the old N1
iloop:  mov     EBP,EAX
; 2. Adding to the S key modulo 2^32
        add     EAX,[ESI] ; add the key
        add     ESI,4   ; the next element of the key.
; 3. Block-replace in the rotation of S by 8 bits to the left
REPT    3
        xlat            ; recoding byte
        ror     EAX,8   ; AL <- next byte
        add     EBX,100h; next node changes
ENDM
        xlat            ; recoding byte
        sub     EBX,300h; BX -> 1st node changes
; 4. Complete rotation of the S at 3 bits to the left
        rol     EAX,3
; 5. The calculation of the new values of N1,N2
        xor     EAX,EDX
        mov     EDX,EBP
; The completion of the inner loop
        loop    iloop
        ret
_gost32 endp
        end