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.


  • PMH4OWPW7JD2TDGWZKTOYL2T3E.jpg

  • Topics

  • Posts

    • Great article on all the Lil Canes attending their debutantes ball. Walt with a great breakdown of all the rookies, as always, and I'm a huge fan of his team coverage, he is truly a treasure, but as a fan of mixed metaphors and superfluous language which some might ignorantly refer to as a "run-on sentence" I never really understood what that mean or where to put the comma after a quote in the middle of a sentence, but holy poo Walt, this is a gem, "While there's a long road left in front of them left to determine whether or not they'll have that same success on the blue line again, the beginning stretch of the journey has been thrown a wrench, and the story on defense has been the emergence of up-and-comers forced into becoming lineup regulars." , bravo, take a bow, sir!
    • How do I activate said Krispy Kreme deal? I'm stoned man you can't be playing with me about this...
    • When the broadcast showed the two benches side by side during the last TV timeout, it was pretty obvious the whole operation is a shitshow. If I was the owner, I would play that clip, with commentary, on the jumbotron at MSG as I fired the coach, GM, President, the whole lot. Bring in your AHL leadership team, wholesale, to finish out the season and start from scratch next year.  Can't fire all the players and fold the season. But, hopefully decapitating the zombie will light a fire under the body and burn out the cancer of the roster. (It makes sense if you don't think about it...) There are obviously issues on the roster. But, you can't have the entire coaching staff completely tuned out with 5 minutes left in a 2 goal game this early in the season. And you can't trust the people that hired them to hire the next staff. If you trust your AHL GM/Scouts, let them run the deadline firesale.   ...     Please don't let the owner read any of this. Because, this poo is hilarous!
×
×
  • Create New...