Assignment 2

CS/ECE 354-2, Fall 1998

due Monday Oct. 12, before 5pm

Program

Purpose

This program is intended to provide experience in dealing with the array data structure.

Program Statement

Write a SASM program that encrypts a user-entered string using a user-entered key (required algorithm is given below).

A sample execution of the program looks like
Enter key: abcde
Enter plain text: coastisclear
Encrypted:
cpcvxiteoias

Encryption Algorithm

Use the encryption algorithm that was state-of-the-art in the mid 1800s. Consider each letter (of plain text, of the key, and of encrypted text) to be an integer, where a=0, b=1, and z=25. An encrypted character is defined to be the sum of a plain text character and a key character modulo 26.

Since the key can be shorter than the plain text, the key is repeated as many times as needed.

An example, with a key of great:

key (repeated)     g    r    e    a    t    g    r    e    a    t
key value          6   17    4    0   19    6   17    4    0   19

plain text         h    e    l    l    o    w    o    r    l    d
plain text value   7    4   11   11   14   22   14   17   11    3


sum               13   21   15   11   33   28   31   21   11   22

sum mod 26        13   21   15   11    7    2    5   21   11   22

encrypted text     n    v    p    l    h    c    f    v    l    w
		  

Requirements

  1. Your program must contain adequate comments (documentation). Such comments include your name and section number at the top of the program. They also include a description of the program, as well as variable descriptions and comments about the code itself.
  2. The key is to be exactly 5 lowercase letters. No error checking on the key is required.
  3. For this program, the plain text will be a maximum of 20 characters, and they will all be lower case letters. The newline character ends the plain text input. Assume that there are no errors in the plain text input.

    Handing In the Program

    Follow the guidelines in how to turn in assignments. For this program, you will need to turn in your source code (the .asm extension) and your makefile (the .mak extension). No printout will be turned in.


    Homework

    1. (12 points, 4 each)
      Show your work in doing the following 8-bit two's complement arithmetic problems. Indicate if overflow occurs for an 8-bit result.
                01001100
              + 11111110
              ----------
      
      
                11101100
              - 10010100
              ----------
      
      
                01101100
              x 10000100
              ----------
      
    2. (7 points)
      Write a SASM code fragment that will set bit 22 of a variable called xx if the corresponding bit of variable yy is cleared. Assume that bits are numbered from the right starting with 0.
    3. (6 points)
      Show all work in generating the sum of the IEEE single precision floating point values (given in hexadecimal) 0xc3a50003 and 0xc4910002. Use round to nearest for rounding, and give the final result in hexadecimal.

      Handing In the Homework

      Follow the guidelines in how to turn in assignments. For this homework, you will need to turn in a single file containing your answers to the homework questions. To make grading easier, please name your file hw2.txt. No printout will be turned in.