Applications Programming --- Lab 10

Objective:

References:

Problem Description:

A very paranoid business executive, who is always afraid that a competitor might be snooping on his sensitive e-mail messages, wants to use a very simple form of encryption.

Download the file lab10-input.xlsx. The table in the file shows the schema of changing letters to other ones. Note that spaces, periods, and other nonalphabetic characters are not changed.

Your tasks:

Design a userform with at least the following controls:

Develop two VBA programs to handle the commond button click events for the two command buttons respectively.

When the Scramble button is clicked, the message entered into the textbox should be treated as the original message. Your program should encode it and display the scrambled message in the label.

When the Unscramble button is clicked, the message entered into the textbox should be treated as the encoded (secret) message. Your program should decode it and display the unscrambed (original) message in the label.

You are specifically asked to develop a function called findMatch that will be used by both Scramble and Unscramble subroutines. The function header is shown below:

Function findMatch(byVal str As String, byVal originCol as Integer, _
                   byVal destCol As Integer) As String
    ' This function takes a string (str) as one of its parameters,
    ' goes through all the strings in the first given column (originCol)
    ' from row 2 to row 53 until find an exact match
    ' and returns the string in the same row
    ' but in the second given column (destCol)
    ' If there is no match, this function returns an empty string
End Function

Below is an algorithm describing the scramble subroutine:

    codedMessage = "" ' empty string
    For index from 0 to len(message) - 1
         ' (extracted as a substring using Mid(message, index, 1))
         ' len(message) gives back the number of characters in message
        originalChar = Mid(message, index, 1)
        replacementChar = findMatch(originalChar, 1, 2)
        if replacementChar = "" Then
            codedMessage = codedMessage & originalChar
        else
            codedMessage = codedMessage & replacementChar
        end if
    next index

There is a weekly Assignment 10 following this lab.