Jump to content
  • Welcome!

    Register and log in easily with Twitter or Google accounts!

    Or simply create a new Huddle account. 

    Members receive fewer ads , access our dark theme, and the ability to join the discussion!

     

Anyone here know anything about assembly language?


stankowalski

Recommended Posts

I'll give you what I got so far, if you can help that'd be great, if not I'll figure it out eventually probably but it's been a pain in the ass so far.

BTW, this "program" is taking a predefined key and a predefined message and encrypting it. I just started working on it so it's not much so far.

Here it is:

.data

key BYTE -2, 4, 1, 0, -3, 5, 2, -4, -4, 6

plainText BYTE "This is a secret message, which will be encrypted",0

encText BYTE ?

mesEnc BYTE "Message encrypted: ",0

mesDec BYTE "Message decrypted: ",0

textBuffer DWORD LENGTHOF plainText

keyBuffer DWORD LENGTHOF key

.code

main PROC

mov edi, 0 ;key pointer

mov esi, 0 ;plainText pointer

mov ecx, textBuffer ;loop counter

mov edx, OFFSET plainText

call WriteString

call crlf

mov edx, OFFSET mesEnc

call WriteString

call Encrypt

mov edx, OFFSET encText

call WriteString

call crlf

call waitmsg

exit

main ENDP

Encrypt PROC

L1: push ecx ;save loop counter

mov al, plainText [esi] ;move letter into al based on pointer

mov cl, key[edi] ;move number from key into cl based on pointer

cmp cl, 0 ;is the key positive or negative?

js L2 ;jump to L2 if negative

ror al, cl ;encrypt the character stored in al based on the key

mov encText[esi], al ;move the encrypted character into encText based on pointer

inc esi ;move to next letter in plainText

inc edi ;move to next number in key

pop ecx ;restore loop counter

loop L1

L2: rol al, cl ;encrypt the character stored in al based on the key

mov encText[esi], al ;move the encypted character into encText based on pointer

inc esi ;move to next letter in plainText

inc edi ;move to next number in key

pop ecx ;restore loop counter

loop L1

ret

Encrypt ENDP

END main

The part in bold is what is causing me problems right now.

Link to comment
Share on other sites

Alright, figured it out. I was one off on the loop counter, didn't take into account the null terminating byte. Working program:

.data

key BYTE -2, 4, 1, 0, -3, 5, 2, -4, -4, 6

plainText BYTE "This is a secret message, which will be encrypted",0

mesEnc BYTE "Message encrypted: ",0

mesDec BYTE "Message decrypted: ",0

textBuffer DWORD LENGTHOF plainText

keyBuffer DWORD LENGTHOF key

encText BYTE 128 DUP(0)

.code

main PROC

mov edi, 0 ;key pointer

mov esi, 0 ;plainText pointer

mov ecx, textBuffer ;loop counter

mov edx, OFFSET plainText

call WriteString

call crlf

mov edx, OFFSET mesEnc

call WriteString

call crlf

call Encrypt

mov edx, OFFSET encText

call WriteString

call crlf

mov edx, OFFSET mesDec

call WriteString

call crlf

mov edx, OFFSET plainText

call WriteString

call crlf

call crlf

call waitmsg

exit

main ENDP

Encrypt PROC

L1: push ecx ;save loop counter

mov al, plainText[esi] ;move letter into al based on pointer

mov cl, key[edi] ;move number from key into cl based on pointer

cmp cl, 0 ;is the key positive or negative?

js L2 ;jump to L2 if negative

ror al, cl ;encrypt the character stored in al based on the key

mov encText[esi], al ;move the encrypted character into encText based on pointer

inc esi ;move to next letter in plainText

inc edi ;move to next number in key

.IF edi == keyBuffer

mov edi, 0

.ENDIF

pop ecx ;restore loop counter

.IF ecx == 1

ret

.ENDIF

loop L1

L2: rol al, cl ;encrypt the character stored in al based on the key

mov encText[esi], al ;move the encypted character into encText based on pointer

inc esi ;move to next letter in plainText

inc edi ;move to next number in key

.IF edi == keyBuffer

mov edi, 0

.ENDIF

pop ecx ;restore loop counter

.IF ecx == 1

ret

.ENDIF

loop L1

ret

Encrypt ENDP

END main

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...