# The values of operands in TEA algorithm will not get decrypted correctly in Assembly

I'm writing an assembly project to perform Tiny Encryption algorithm. I followed the C-Code on Wikipedia and transformed it into x86 assembly.

However when I run the algorithm the inputs v0 and v1, they get transformed into gibberish as they should, however, when I try to decrypt the ciphertext, I don't get the original back.

Here is the encryption procedure

``````encrypt PROC
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esi, esi
xor edi, edi
mov ecx, 32
LOOP1:
;sum+= delta
mov eax, sum
mov sum, eax
; (v1 << 4) + k0
mov eax, v1
SAL eax, 4
mov v1l4, eax
; (v1 + sum)
mov eax, v1
mov v1ps, eax
; (v1 >> 5) + k1
mov eax, v1
SHR eax, 5
mov v1r5, eax
;((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1)
mov eax, v1l4
xor eax, v1ps
xor eax, v1r5
; v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1)
; (v0 << 4) + k2
mov eax, v0
SAL eax, 4
mov v0l4, eax
; (v0 + sum)
mov eax, v0
mov v0ps, eax
; (v0 >> 5) + k3
mov eax, v0
SHR eax, 5
mov v0r5, eax
; ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3)
mov eax, v0l4
xor eax, v0ps
xor eax, v1r5
; v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3)

dec ecx
cmp ecx, 0
JG LOOP1
ret
encrypt ENDP
``````

Here is the decryption procedure

``````decrypt PROC
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esi, esi
xor edi, edi
mov ecx, 32
LOOP2:
; (v0 << 4) + k2
mov eax, v0
SAL eax, 4
mov v0l4, eax
; (v0 + sum)
mov eax, v0
mov v0ps, eax
; (v0 >> 5) + k3
mov eax, v0
SHR eax, 5
mov v0r5, eax
; ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3)
mov eax, v0l4
xor eax, v0ps
xor eax, v1r5
; v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3)
SUB v1, eax

; (v1 << 4) + k0
mov eax, v1
SAL eax, 4
mov v1l4, eax
; (v1 + sum)
mov eax, v1
mov v1ps, eax
; (v1 >> 5) + k1
mov eax, v1
SHR eax, 5
mov v1r5, eax
; ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1)
mov eax, v1l4
xor eax, v1ps
xor eax, v1r5
; v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1)
SUB v0, eax
; sum -= delta
mov eax, sum
SUB eax, delta
mov sum, eax

dec ecx
cmp ecx, 0
JG LOOP2
ret
decrypt ENDP
``````

Many thanks!