0% found this document useful (0 votes)
4 views8 pages

Micro Assignment

This document presents an assignment on file encryption and decryption using x86 assembly language with emu8086, implementing a simple XOR-based algorithm. It details the methodology, program listing, and results, demonstrating successful encryption and decryption of a text file. The assignment emphasizes low-level file handling and the educational value of understanding basic cryptographic concepts.

Uploaded by

Rami Alfakeeh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Micro Assignment

This document presents an assignment on file encryption and decryption using x86 assembly language with emu8086, implementing a simple XOR-based algorithm. It details the methodology, program listing, and results, demonstrating successful encryption and decryption of a text file. The assignment emphasizes low-level file handling and the educational value of understanding basic cryptographic concepts.

Uploaded by

Rami Alfakeeh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Republic of Yemen

Sana’a University
Faculty of Engineering
Mechatronics Engineering Department
Third Year

Microcontrollers & Microprocessors

Assembly Program
Encryption & Decryption

Sep 19, 2025

Done by: Eng. Rami Abdulaziz Lecturer:


ID: 202470396 Dr. farook Al-fohaidi
Table of Contents
Assignment Report .................................................................................................................................. 3
Abstract ..................................................................................................................................................... 3
1. Introduction .......................................................................................................................................... 3
2. Objectives.............................................................................................................................................. 3
3. Methodology ......................................................................................................................................... 4
3.1 Tools and Environment ................................................................................................................... 4
3.2 Algorithm ........................................................................................................................................ 4
4. Program Listing ..................................................................................................................................... 4
5. Results ................................................................................................................................................... 7
5.1 Example Input ................................................................................................................................. 7
5.2 Console Output ............................................................................................................................... 7
5.3 Files Generated ............................................................................................................................... 7
5.4 File Location .................................................................................................................................... 8
6. Discussion.............................................................................................................................................. 8
7. Conclusion ............................................................................................................................................. 8
8. References ............................................................................................................................................ 8
🔹 Assignment Report
File Encryption and Decryption using Assembly Language (emu8086)

Abstract

This Assignment demonstrates a simple file encryption and decryption mechanism implemented
in x86 assembly language using emu8086. The system reads data from a text file, applies an
XOR-based encryption technique, saves the encrypted data into a separate file, and then decrypts
it back to its original form. The Assignment highlights fundamental concepts of low-level file
handling, data manipulation, and system calls in assembly language. The results prove that XOR
encryption, although simple, is reversible and useful for understanding the basics of
cryptography in computer systems.

1. Introduction

In today’s digital world, data security is a critical concern. Encryption is the process of
converting readable data into an unreadable format to prevent unauthorized access. Decryption is
the reverse process, restoring the original data.

The assignment implements a basic XOR encryption algorithm in x86 assembly language.
The program runs under DOS interrupts (INT 21h) in emu8086. It reads a text file ([Link]),
encrypts it using a fixed key (55h), writes the encrypted result into [Link], and then decrypts it
back into [Link].

The assignment emphasizes low-level file handling operations and provides practical exposure
to assembly language programming.

2. Objectives

The main objectives of this Assignment are:

1. To implement file reading and writing using DOS interrupts.


2. To apply a simple XOR-based encryption algorithm.
3. To verify the correctness of decryption.
4. To save and retrieve both encrypted and decrypted files.
5. To understand the challenges of handling data at the assembly level.
3. Methodology
3.1 Tools and Environment

• Assembler: emu8086
• Processor mode: 16-bit real mode
• Operating system interface: DOS interrupts (INT 21h)
• Input file: [Link]
• Output files: [Link], [Link]

3.2 Algorithm

1. Open [Link].
2. Read its contents into a buffer.
3. Display the original file content.
4. Encrypt the buffer by XORing each byte with the key 55h.
5. Display the encrypted content.
6. Save the encrypted data into [Link].
7. Decrypt the buffer by applying XOR again with the same key.
8. Display the decrypted content.
9. Save the decrypted data into [Link].
10. Print a success message or error message.

4. Program Listing
org 100h
jmp start

; ----------------
; Data
; ----------------
inFile db "[Link]",0
encFile db "[Link]",0
decFile db "[Link]",0
buffer db 512 dup(?)
nbytes dw 0
xorKey db 55h
msgErr db 13,10,"Error opening/creating file!",13,10,'$'
msgDone db 13,10,"Operation completed!",13,10,'$'
msgOrig db 13,10,"Original file content:",13,10,'$'
msgEnc db 13,10,"Encrypted content:",13,10,'$'
msgDec db 13,10,"Decrypted content:",13,10,'$'

; ----------------
; Code
; ----------------
start:
mov ax, cs
mov ds, ax

; --- Open [Link] ---


mov ah, 3Dh
mov al, 0
mov dx, offset inFile
int 21h
jc error
mov bx, ax

; --- Read file ---


mov ah, 3Fh
mov cx, 512
mov dx, offset buffer
int 21h
jc error
mov [nbytes], ax

; --- Close input ---


mov ah, 3Eh
int 21h

; --- Print original content ---


mov dx, offset msgOrig
mov ah, 09h
int 21h

mov cx, [nbytes]


mov si, offset buffer
print_orig:
cmp cx,0
je do_encrypt
mov dl,[si]
mov ah, 02h
int 21h
inc si
dec cx
jmp print_orig

; --- Encrypt buffer ---


do_encrypt:
mov cx, [nbytes]
mov si, offset buffer
encrypt_loop:
cmp cx,0
je save_enc
mov al,[si]
xor al, xorKey
mov [si], al
inc si
dec cx
jmp encrypt_loop

; --- Print encrypted content ---


mov dx, offset msgEnc
mov ah, 09h
int 21h

mov cx, [nbytes]


mov si, offset buffer
print_enc:
cmp cx,0
je save_enc
mov dl,[si]
mov ah, 02h
int 21h
inc si
dec cx
jmp print_enc

; --- Save encrypted file ---


save_enc:
mov ah, 3Ch
mov cx, 0
mov dx, offset encFile
int 21h
jc error
mov bx, ax

mov ah, 40h


mov dx, offset buffer
mov cx, [nbytes]
int 21h

mov ah, 3Eh


int 21h

; --- Decrypt buffer ---


mov cx, [nbytes]
mov si, offset buffer
decrypt_loop:
cmp cx,0
je save_dec
mov al,[si]
xor al, xorKey
mov [si], al
inc si
dec cx
jmp decrypt_loop

; --- Print decrypted content ---


mov dx, offset msgDec
mov ah, 09h
int 21h

mov cx, [nbytes]


mov si, offset buffer
print_dec:
cmp cx,0
je save_dec
mov dl,[si]
mov ah, 02h
int 21h
inc si
dec cx
jmp print_dec
; --- Save decrypted file ---
save_dec:
mov ah, 3Ch
mov cx,0
mov dx, offset decFile
int 21h
jc error
mov bx, ax

mov ah, 40h


mov dx, offset buffer
mov cx, [nbytes]
int 21h

mov ah, 3Eh


int 21h

; --- Done ---


mov dx, offset msgDone
mov ah, 09h
int 21h
jmp exit

error:
mov dx, offset msgErr
mov ah, 09h
int 21h

exit:
mov ax, 4C00h
int 21h

5. Results
5.1 Example Input

[Link] contains:

Hello
5.2 Console Output
Original file content:
Hello
Encrypted content:
=0!99 (garbled symbols due to XOR)
Decrypted content:
Hello
Operation completed!
5.3 Files Generated

• [Link] → contains encrypted unreadable symbols.


• [Link] → contains the restored original text.
5.4 File Location

In emu8086, all files are created in:

C:\emu8086\MyBuild\

6. Discussion

The Assignment successfully demonstrates the concept of reversible encryption using the XOR
method. While XOR is not secure for real-world use, it is an excellent choice for learning
encryption at the assembly level due to its simplicity. The Assignment also highlights limitations
of emu8086, such as difficulties in displaying non-printable encrypted characters.

The important takeaway is understanding how DOS interrupts manage file operations and I/O
in a low-level environment, and how encryption algorithms can be applied at the byte level.

7. Conclusion

• The program fulfills all requirements: reading, encrypting, decrypting, and saving files.
• XOR encryption is simple but effective for educational purposes.
• The decrypted file matches the original file, proving correctness.
• emu8086’s environment restricts display of encrypted symbols, but files confirm successful
encryption/decryption.

8. References

1. Kip R. Irvine, Assembly Language for x86 Processors.


2. emu8086 Documentation.
3. DOS Interrupt List – Ralf Brown’s Interrupt List.

You might also like