
          ; 2e962c52c007fd0f
Key     db '2e962c52c007fd0f'
Keylen  EQU $ - Key
TEAData db '        '
TEADLEN EQU $ - TEADATA

tea_decrypt proc far
        .386
        push    di
        mov     ebx, dword ptr [di]
        mov     ecx, dword ptr [di+4]
        mov     edx, 9e3779b9h ; sqr(5)-1 * 2^31
        mov     eax, edx
        shl     eax, 5
        mov     di, 32
DLoopR:
; 8 12 0 4

        mov     ebp, ebx
        shl     ebp, 4
        sub     ecx, ebp
        mov     ebp, dword ptr [si+8]
        xor     ebp, ebx
        sub     ecx, ebp
        mov     ebp, ebx
        shr     ebp, 5
        xor     ebp, eax
        sub     ecx, ebp
        sub     ecx, dword ptr [si+12]
        ;
        mov     ebp, ecx
        shl     ebp, 4
        sub     ebx, ebp
        mov     ebp, dword ptr [si]
        xor     ebp, ecx
        sub     ebx, ebp
        mov     ebp, ecx
        shr     ebp, 5
        xor     ebp, eax
        sub     ebx, ebp
        sub     ebx, dword ptr [si+4]
        sub     eax, edx
        dec     di
        jnz     DLoopR

        pop     di
        mov     dword ptr [di], ebx
        mov     dword ptr [di+4], ecx
        ret
tea_decrypt endp

tea_encrypt proc far
        .386
        push    di
        mov     ebx, dword ptr [di]
        mov     ecx, dword ptr [di+4]
        xor     eax, eax
        mov     edx, 9e3779b9h ; sqr(5)-1 * 2^31
        mov     di, 32
ELoopR:
        add     eax, edx
        mov     ebp, ecx
        shl     ebp, 4
        add     ebx, ebp
        mov     ebp, dword ptr [si]
        xor     ebp, ecx
        add     ebx, ebp
        mov     ebp, ecx
        shr     ebp, 5
        xor     ebp, eax
        add     ebx, ebp
        add     ebx, dword ptr [si+4]
        ;
        mov     ebp, ebx
        shl     ebp, 4
        add     ecx, ebp
        mov     ebp, dword ptr [si+8]
        xor     ebp, ebx
        add     ecx, ebp
        mov     ebp, ebx
        shr     ebp, 5
        xor     ebp, eax
        add     ecx, ebp
        add     ecx, dword ptr [si+12]
        dec     di
        jnz     ELoopR

        pop     di
        mov     dword ptr [di], ebx
        mov     dword ptr [di+4], ecx
        ret
tea_encrypt endp

