Title : Project 3 Point Value: 100 Deadline : 4/18 at 11.59pm Topics Covered: Introduction to NASM, x86-64 instructions and architecture, Loops, System calls, ASCII Setting Things Up: For this...

1 answer below »
nasm assembly x86-64


Title: Project 3 Point Value: 100 Deadline: 4/18 at 11.59pm Topics Covered:  Introduction to NASM, x86-64 instructions and architecture, Loops, System calls, ASCII Setting Things Up: For this project you will be using the NASM assembler to write x86-64 assembly. NASM is accessible on linux.gl.umbc.edu and you need to make sure your program compiles on it before submission. You can reach it from anywhere with an internet connection · You need to use your UMBC account · ssh [email protected] · Enter your password (will not show you typing) · The first time you are in create a CMSC313 folder · mkdir cmsc313 · cd cmsc313 You can then use your favorite editor to write the program. To assemble your program: · Assemble it using: nasm –f elf64 filename.asm · Link to create executable: gcc –m64 –o filename filename.o · Execute program: ./filename or filename To transfer a file from your local computer to linux.gl.umbc.edu you can use the command below: scp myFlie [email protected]:cmsc313 This will put myFile in the cmsc313 directory on linux.gl.umbc.edu To transfer from linux.gl to your computer: scp [email protected]:cmsc313/myFile /path/to/myFile Project Description: Write and submit a NASM assembly language program “shift.asm” that: · Asks the user for a location between 0-25. · You do not have to do error correction · Asks the user for a string from the user and displays the unedited string. · And finally displays an edited string to the user edited in the following way: · Shift every letter in the message by the indicated number of positions in the alphabet. When a character gets shifted past the beginning or end of the alphabet, wrap around to the other end to continue. For example, a 6 would shift any 'e' characters to 'k'. The shift must be applied to all letters in the message. Do not change any non-alphabet characters in the message, and preserve all capitalization. Below are 2 sample runs of the program: Sample run 1: Enter shift value: 6 Enter original message: This is the original message. Current message: This is the original message. Shift encryption: Znoy oy znk uxomotgr skyygmk. Sample run 2: Enter shift value: 10 Enter original message: This is the original message. Current message: This is the original message. Shift encryption: Drsc sc dro ybsqsxkv wocckqo. Notes: · Remember characters/numbers are read in in ASCII. · You have to tackle double digit numbers · You do not need to worry about user error. General Project (Hard) Requirements: · Code that does not compile will receive 50% off · We are programming for 64 bit Intel Architecture · Code written for 32 bit Intel will receive 20 points off · You can work individually or with another person for this project. No more than 2 people can work together. · You must have a comment at the top of the code detailing what the code does. · This comment should also include your full name and user ID. · If working with 2 people both names and user IDs should be included. · You must use good coding style with respect to variable names, spacing, labels and comments. · Submit only the .asm file named firstname_lastname_shift.asm to blackboard. · Late submissions will accrue a deduction of 10 points for every 6 hours it is late. · If working with 2 people then the file should be named: lastname_lastname_shift.asm · You cannot use C/C++ function calls. You have to use system calls Grading Breakdown: (remember that code that doesn’t compile will not get full credit) · [75] Functionality · [20]Display prompts to user and read in values · [10]Display unedited string · [10]Display edited string · [20]Text edit functionality · [5]Use of system calls · [5]Program exits correctly (No Seg Faults) · [5]No extra new lines or spaces printed · [25] Style (only if it compiles) · [5]Comments where necessary · [5]Code written for 64 bit Intel Assembly · [5]Comment at top of program with name, user id and explanation of code · [5]Code easy to read · Good variable names · Indentation · [5]Submitted correctly Project 4 PROJECT 4 Title: Encryption Point Value: 100 Due Date: 5/9 at 11.59pm The Problem In this project, you will be developing a menu-driven program to encrypt text messages. There are a total of two encryption techniques that you will have to implement. DISCLAIMER: we will be using very, very simplified encryption techniques that are easy to decode and should never be used in practice! These two approaches are known as substitution cyphers where we substitute the alphabet letters of a message with different letters. We will provide you with a sample run (file "sampleRun.txt" attached to the blackboard assignment) to ensure that you understand the overall operation of the program. The overall operation of your program will be a menu-driven approach for encrypting various messages based on user-input. The program should store 10 messages for possible encryption in an array of strings. These strings will all be initialized to the string; “This is the original message.” These messages can also be changed by the user. The program should repeatedly display the menu, get user input, and execute the requested operation until the user decides to quit. The displayed menu and all input/output should match the format in the provided sample run. Users must be able to choose any of the operations, in any order that they want, as many times as they want, until they decide to quit. Here are the menu operations: ● Quit the program. ● Display Message: Show the current 10 messages to the user, un-encrypted. These messages should all initially be set to "This is the original message." ● Read Message: Get a new message from the user. Validate the message to make sure that it starts with a capital letter and ends with either a period ('.'), question mark ('?') or exclamation point ('!'). If the input is invalid, reject it with an error message to the user. Otherwise, if valid, replace the message in the next spot in the array starting with the first spot (index 0). Once all messages in the array have been replaced, the program should reset to the beginning position and start replacing from there. ● Shift Encrypt: Get user input for integer shift value, validate that it is between 0 and 25 inclusive. If invalid, display an error message. If valid, display the encrypted version of the current message by shifting every letter in the message by the indicated number of positions in the alphabet. When a character gets shifted past the beginning or end of the alphabet, wrap around to the other end to continue. For example, a positive 6 would shift any 'e' characters to 'k'. The shift must be applied to all letters in the message. Do not change any non-alphabet characters in the message, and preserve all capitalization. ● Jump Encrypt: prompt the user to enter an integer (jump value) that is between 2 and the square root of the length of the current message, inclusive. Now imagine that we are going to write the current message in a table form, using the same number of rows as the jump value. The character order in the original message would be the order of the first column, followed by the second column, etc. For example, with jump value of 5, the original message would be in table form: T i e g a h s i m g i o n e e s t r a s. h i l s To complete the encryption, display the encrypted message row by row, "Tieg ahs imgi oneestras. hils" for the above. Hint: this can be accomplished with nested loops! No arrays or actual tables are required in the solution, that's just one way to explain the jump intervals. Also note that this encryption will jumble all the characters in the original message, not just the letters. [WARNING: This part is harder than the others - make sure you leave plenty of time for algorithm development and coding. Implementation Details & Hints: There are several key features of this program solution that are required and/or will make your development job much easier. Here is a list of requirements and implementation hints: ● You must break this problem down into subroutines rather than writing everything in main. The required subroutines are; ○ a read message subroutine, ■ This should be written as a C function ■ This is called when the user wants to read in a new message ■ It should validate the user’s input using the criteria mentioned above ■ The string the user enters could be any size so you need to account for this. (Hint: dynamic memory allocation) ○ a shift encrypt subroutine, ■ Should be written in x86-64 assembly language ■ Should be in a separate file by itself ○ a jump encrypt subroutine, ■ Should be written in x86-64 assembly language ■ Should be in a separate file by itself ○ a display subroutine ■ Should be written as a C function ■ Displays the current strings in the array ○ A square root subroutine ■ Should be written as a C function ■ Used to find the square root of a number ○ The C functions can be in one .c file. ○ Feel free to add any other subroutines as needed. ● All code written must be by you and written in assembly aside from the subroutines in C mentioned above. ○ * If needed you can have the free command in it’s own subroutine in C. ● You must program for x86-64 (64 bit architecture). ● The encryptions should not change the original string being encrypted. ● Aside from the square root, *read and display C subroutines, you cannot use any other C/C++ subroutines. You can use the ret command to emulate the return 0 as shown in class and you can use printf/scanf ○ * If needed you can have the free command in it’s own subroutine in C. ● It is really important to develop this program incrementally!. Build your program from the bottom up: Have your main method display the menu and read the user's choices. For each choice, just display a brief message so that you can see that the menu works. Make sure the quit option works and that users can select various options in any order. Next, add the necessary variables for processing, including the initial value for the current message. ● One at a time, implement the various menu operations, testing each with the initial message to be sure they work correctly. Then test them with other inputs, using the menu operation to get new messages. ● You will need to submit the following files in a zipped folder labelled firstname_lastname_project4.zip: ○ main.asm ■ Main assembly file that calls the subroutines ○ validate.c ■ C file with c
Answered 4 days AfterApr 29, 2021

Answer To: Title : Project 3 Point Value: 100 Deadline : 4/18 at 11.59pm Topics Covered: Introduction to NASM,...

Gaurav answered on May 04 2021
144 Votes
Encryption.asm
    global main
    extern displayMessage
    extern readMessage
    extern shiftEncryption
    extern jumpEncryption
    extern square_root
    extern clearMemory
%define __STD_IN_ 0
%define __STD_OUT_ 1
%define __NR_read 0
%define __NR_write 1
%define __NR_open 2
%define __NR_close 3
%define __NR_exit 60
%macro    read_input 2                ; macro to read user input
    mov rbx, 0                        ; number character read
%%getLine:
    mov rax, __NR_read                ; syscall number
    mov rdi, __STD_IN_        
        
    lea rsi, [%1 + rbx]                ; buffer address + offset
    mov rdx, 1                        ; read only one character
    syscall
    
    cmp rbx, %2+1                    ; check if number of character read is greater than buffer size - 1
    ja %%invalid_option                ; if so stop incrementing the offset
    add rbx, rax
%%invalid_option:                    
    mov al, BYTE [rsi]                ; check the byte for newline character
    cmp al, 10
    jne %%getLine                    ; exit the loop if newline character is received
    mov rax, rbx                    ; total number character read
%endmacro
    section .data
initial_string db "This is the original message.", 0
initial_string_end:
menu    db 10, "Encryption menu options:", 10
        db    "d - display current messages", 10
        db    "r - read new message", 10
        db    "s - shift encrypt", 10
        db    "j - jump encrypt", 10
        db    "q - quit program", 10
        db    "enter option letter -> ", 0
menu_end:
error    db    "Invalid Option, Try again", 10, 0
error_end:
invalidMsgIdx    db "Invalid Message Index [0 - 9]", 10, 0
invalidMsgIdx_end:
easterEggFound    db "EASTER EGG FOUND", 10, 0
easterEggFound_end:
getLocStr    db    "Enter string location : ", 0
getLocStr_end:
goodbye    db    "Goodbye!", 10, 0
goodbye_end:
c_pressed dq 0
index dq 0
message times 10 dq 0
    section .bss
buffer    resb 4
    section .text
main:
    
    mov rdi, message
    mov rax, initial_string
    mov rcx, 10
fill_initial_string_address:
    mov [rdi + rcx * 8 - 8], rax
    loop fill_initial_string_address            ; fill the message array with pointer of default string
main_loop:
    mov rax, __NR_write
    mov rdi, __STD_OUT_
    mov rsi, menu
    mov rdx, menu_end - menu
    syscall                                        ; display menu
    
    read_input buffer, 1                        ; read only one character, buffer size should be number of desired character + 1
    
    cmp rax, 2                                    ; check if only desired character received, 1 + 1(newline character)
    je valid_option
    
    mov rax, __NR_write                            ; else print error
    mov rdi, __STD_OUT_
    mov rsi, error
    mov rdx, error_end - error
    syscall
    jmp main_loop
valid_option:
    mov al, BYTE [buffer]                        ; load the character
    cmp al, 'c'
    je extra_credit                                ; extra credit part
    mov QWORD[c_pressed], 0                        ; reset the counter if anything less pressed
    cmp al, 'd'                                    ; execute menu
    je display_message
    cmp al, 'r'
    je read_message
    cmp al, 's'
    je shift_message
    cmp al, 'j'
    je jump_message
    cmp al, 'q'
    je terminate    
invalid_option:                                    ; print error for other keys
    mov rax, __NR_write
    mov rdi, __STD_OUT_
    mov rsi, error
    mov rdx, error_end - error
    syscall
    jmp main_loop
display_message:
    mov rdi, message                            ; print all the string in message array
    call displayMessage
    jmp main_loop
read_message:
    call readMessage                            ; read new message
    test rax, rax                                ; if new message is valid
    je main_loop
    mov rdi, message
    mov rcx, [index]
    mov [rdi + rcx * 8], rax                    ; save th pointer in message array
    inc rcx                                        ; increment index
    mov [index], rcx                
    cmp rcx, 10                                    ; if index > 10 then index = 0
    jl main_loop
    mov QWORD[index], 0
    jmp main_loop
shift_message:
    mov rax, __NR_write
    mov rdi, __STD_OUT_
    mov rsi, getLocStr
    mov rdx, getLocStr_end - getLocStr
    syscall
    read_input buffer, 1                        ; get the string location
    cmp rax, 2
    je valid_shift_msg_idx
invalid_shift_msg_idx:                            ; print error if invalid character received
    mov rax, __NR_write
    mov rdi, __STD_OUT_
    mov rsi, invalidMsgIdx
    mov rdx, invalidMsgIdx_end - invalidMsgIdx
    syscall
    jmp main_loop
valid_shift_msg_idx:
    movzx rax, BYTE[buffer]                        ; load the byte
    sub rax, 0x30                                ; check if its digit
    cmp rax, 9
    ja invalid_shift_msg_idx
    mov rdi, [message + rax * 8]                ; load the address of string of given index
    call shiftEncryption                        
    jmp main_loop
    
jump_message:
    mov rax, __NR_write
    mov rdi, __STD_OUT_
    mov rsi, getLocStr
    mov rdx, getLocStr_end - getLocStr
    syscall
    
    read_input buffer, 1                        ; get the string location
    cmp rax, 2
    je valid_jump_msg_idx
invalid_jump_msg_idx:    
    mov rax, __NR_write                            ; print error if invalid character received
    mov rdi, __STD_OUT_
    mov rsi, invalidMsgIdx
    mov rdx, invalidMsgIdx_end - invalidMsgIdx
    syscall
valid_jump_msg_idx:        
    movzx rax, BYTE[buffer]                        ; load the byte
    sub rax, 0x30
    cmp rax, 9
    ja invalid_jump_msg_idx                        ; check if its digit
    mov rdi, [message + rax * 8]                ; load the address of string of given index
    call...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here