Subject Computer Science Assembly Language Programming

Question

You are responsible to an assembly function for an encryption library. This function will encrypt or decrypt a string of characters. It will use a simple ciphertext algorithm which do character shifting. This function will use the C function signature but everything within this function should be assembly code using the ASM block similar to the assembly example shown in class. This function should be built into a separate DLL with the p4.cpp will contain the calling functions.

Program Specification:

int s_encrypt (char *src, char* dest, int en_flag);

src – the original string

dest – the output string

en_flag – 0 for encryption and 1 for decryption

This function returns the # of characters being changed in the string. If no change, it should return zero.

Additional Information:

- We only apply the change algorithm for (‘A’..‘Z’ to ‘a’..’z’). Other characters are left unchanged.
- We will use a separate header file (key.h) for the character shifting algorithm.
- The input and output string are displayed on the screen.
- You MUST have detailed comments within the _asm block for your algorithm.
- In key.h, you have 3 global variables named
int direction = 0; /* 0 means forward, 1 means backward */
       int shiftcount = 2; /* number of character to shift */
int invertcase = 1; /* invert case of the original letter, 0 = no, 1 = yes */

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

/*
encrypt.cpp - This file contains the code to encrypt and decrypt an input string
                and output the modified string.
*/

#include "key.h" /* Okay to use the 3 symbolic names inside key.h */
#include <string.h>

__declspec(dllexport) int s_encrypt (char *src, char* dest, int en_flag);


__declspec(dllexport) int s_encrypt (char *src, char* dest, int en_flag)
{
int i;
int cnt;
int cas;
int startaddress;

__asm
{
mov eax, 0 ; zero out the result
mov esi, src ; move the source string pointer to ESI
; fill in your code here
mov edi, dest
mov i, 0
mov cnt, 0
mov startaddress, 0x41
mov cas, 0x20...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Iterative Factorial Calculation in Assembly
Homework Solution
$10.00
Computer Science
Programming
Iterative Factorial Calculation
Assembly Language
Loops
Functions
Input
Output
Procedures
Error Conditions
Assembly Language Problems With Fibonacci Numbers
Homework Solution
$30.00
Assembly Language
Computer Science
Programming
Fibonacci Numbers
Arrays
European Mathematics
Indian Mathematics
Sequences
Characters
Strings
Columns
Rows
Values
Memory
Stack
Macros
Boolean
Registers
Assembly Language Problems
Homework Solution
$25.00
Assembly Language
Programming
Computer Science
Strings
Macros
Characters
Procedures
Addresses
Numbers
Stack
Algorithms
Structures
Conversion
Registers
Binary Values
Input
Output
Get help from a qualified tutor
Live Chats