I’m attempting to implement the TEA algorithm in assembly language (8086 TASM). However, I’m encountering difficulties in two areas
-
String Input: I need assistance in implementing a mechanism to input strings from the user within my assembly program.
-
Hexadecimal Conversion: After obtaining user input, I aim to convert each letter of the input string into its corresponding hexadecimal representation to prepare it for TEA encryption. I’m seeking guidance on how to accomplish this conversion efficiently.
-
Encrypted Message Decryption: Following encryption using the TEA algorithm, I’m encountering difficulty in converting the resulting encrypted message back into readable string letters. I require assistance in decrypting and converting the encrypted message into its original form.
I’ve successfully implemented the encrypt and decrypt functions for the TEA algorithm. These functions seem to perform encryption and decryption operations correctly. However, I’m stuck at handling string input and converting them into a format suitable for encryption. Additionally, after encryption, the output contains unknown symbols, and I need assistance in converting it into readable encrypted strings.
Here is my encrypt / decrypt functions:
proc encrypt
pusha
mov cx, 32
encryptLoop:
; sum += delta
mov ax, [delta]
add [sum], ax
xor eax,eax
; ((p2 << 4) + k0)
mov dx, [p2]
shl dx, 4
add dx, [k0]
; (p2 + sum)
mov bx, [p2]
add bx, [sum]
; ((p2 << 4) + k0) ^ (p2 + sum)
xor dx, bx
xor bx, bx
; ((p2 >> 5) + k1)
mov bx, [p2]
shr bx, 5
add bx, [k1]
; ((p2 << 4) + k0) ^ (p2 + sum) ^ ((p2 >> 5) + k1)
xor dx, bx
add [pe1], dx
; ((p1 << 4) + k2)
mov dx, [p1]
shl dx, 4
add dx, [k2]
; (p1 + sum)
mov bx, [p1]
add bx, [sum]
; ((p0 << 4) + k2) ^ (p0 + sum)
xor dx, bx
xor bx, bx
; ((p1 >> 5 ) + k3)
mov bx,[p1]
shr bx, 5
add bx, [k3]
; ((p0 << 4) + k2) ^ (p0 + sum) ^ ((p1 >> 5 ) + k3)
xor dx, bx
add [pe2], dx
loop encryptLoop
popa
ret
endp encrypt
proc decrypt
pusha
mov cx, 32
decryptLoop:
; ((p1 << 4) + k2)
mov dx, [p1]
shl dx, 4
add dx, [k2]
; (p1 + sum)
mov bx, [p1]
add bx, [sum]
; ((p0 << 4) + k2) ^ (p0 + sum)
xor dx, bx
xor bx, bx
; ((p1 >> 5 ) + k3)
mov bx,[p1]
shr bx, 5
add bx, [k3]
; ((p0 << 4) + k2) ^ (p0 + sum) ^ ((p1 >> 5 ) + k3)
xor dx, bx
sub [pe2], dx
xor ax,ax
; ((p2 << 4) + k0)
mov dx, [p2]
shl dx, 4
add dx, [k0]
; (p2 + sum)
mov bx, [p2]
add bx, [sum]
; ((p1 << 4) + k0) ^ (p1 + sum)
xor dx, bx
xor bx, bx
; ((p2 >> 5) + k1)
mov bx, [p2]
shr bx, 5
add bx, [k1]
; ((p2 << 4) + k0) ^ (p2 + sum) ^ ((p2 >> 5) + k1)
xor dx, bx
sub [pe1], dx
; sum -= delta
mov ax, [delta]
sub [sum], ax
loop decryptLoop
popa
ret
endp decrypt
DS section:
delta dw 79b9h ; 79b9h for 16 bits, 9e3779b9h for 32 bits
sum dw 0
p1 dw 0
p2 dw 0
k0 dw 0
k1 dw 0
k2 dw 0
k3 dw 0
; Two part of the plaintext after encryption
pe1 dw 0
pe2 dw 0