CSC231 Simple String Encryption

From dftwiki3
Jump to: navigation, search

--D. Thiebaut (talk) 08:04, 16 September 2014 (EDT)


;;; ; encryptString.asm
;;; ; D. Thiebaut
;;; ;
;;; ; A simple encryption program that uses 
;;; ; just two instructions: mov and add.
;;; ;
;;; ; to assemble and run:
;;; ;
;;; ;     nasm -f elf -F  stabs encryptString.asm
;;; ;     ld -melf_i3896 -o encryptString encryptString.o
;;; ;     ./encryptString.asm
;;; ; -------------------------------------------------------------------

        ;; %include files here...


;;;  ------------------------------------------------------------
;;;  data areas
;;;  ------------------------------------------------------------

                section .data
amesg    db      "Hello!", 10
MSGLEN  equ     $-mesg
        


;;;  ------------------------------------------------------------
;;;  code area
;;;  ------------------------------------------------------------

                section .text
                global  _start

_start:
;;; print the original string (not encrypted)
        
                mov     eax, 4  ; O.S, write a string
                mov     ebx, 1  ; write to stdout
                mov     edx, MSGLEN ; length of message
                mov     ecx, mesg   ; string to print
                int     0x80    ; call Linux

;;; encrypt the whole string (we do not know about loops yet)
                add     byte [mesg], 1
                add     byte [mesg+1], 1
                add     byte [mesg+2], 1
                add     byte [mesg+3], 1
                add     byte [mesg+4], 1
                add     byte [mesg+5], 1

;;; print the encrypted string (not encrypted)
        
                mov     eax, 4  ; O.S, write a string
                mov     ebx, 1  ; write to stdout
                mov     edx, MSGLEN ; length of message
                mov     ecx, mesg   ; string to print
                int     0x80    ; call Linux

;;;  exit()

                mov     eax,1
                mov     ebx,0
                int     0x80    ; final system call