In this assignment, you will develop a simple Android app, SDPEncryptor, that encrypts messages using a simple substitution cipher.

Inputs:

1. Dispatch: message to be encoded.

  • This input should be a non-empty string and must contain at least one letter.
  • This input should be provided to the app through an EditText widget, initially blank.

2. Argument 0: first encryption parameter.

  • This input should be an integer coprime to 26 between 0 and 26: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, or 25.
  • This input should be provided to the app through an EditText widget, initially set to '1'.

3. Argument 1: second encryption parameter.

  • This input should be an integer >= 1 and < 26.
  • This input should be provided to the app through an EditText widget, initially set to '1'.

Output:

1. Encoded Dispatch, the text resulting from applying the following cipher:

  • Each letter in the alphabet is assigned a numeric value between 0 and 25 based on its position in the alphabet (i.e., A=0, a=0, B=1, b=1, , Z=25, z=25).
  • For each letter in the alphabet, where the numeric value is x, the encoded value of the letter is defined as E(x) = (ax + b) % 26 where a and b are the values of Argument 0 and Argument 1 respectively, as in an Affine Cipher.
  • The encoded character for the input letter is calculated by taking the encoded number, which is a value between 0 and 25, and translating it back into a letter (again, where A=0, a=0, B=1, b=1, , Z=25, z=25).
  • Capitalization of alphabetic characters must be inverted (i.e., all lowercase characters are transformed into upper case characters and vice versa).
  • All non-alphabetic characters must remain unchanged.
  • The output should be shown using a non-editable TextView that is initially blank and (re)computed when the "ENCIPHER" button is pressed. If any input is invalid when the button is pressed, the output should then be set to (i.e., the empty string), and all applicable error messages should be generated (see below).

Example:

  • Inputs:
    • Dispatch = "Cat & 5 DogS"
    • Argument 0 = 5
    • Argument 1 = 3
  • Output:
    • Encoded Dispatch = "nDU & 5 sVHp"
  • Explanation:
    • "C" has value 2, (2 * 5 + 3) % 26 = 13, 13 corresponds to n. (lowercase since C is capitalized)
    • "a" has value 0, (0 * 5 + 3) % 26 = 3, 3 corresponds to D. (capitalized because a is lowercase).
    • ...
    • " ", "&, , 5, and are unchanged
    • ...

Error Messages:

The app should generate suitable error messages by calling EditText's setError method (inherited from TextView) on the appropriate EditText widget when the computation is triggered (i.e., the button is pressed). If done correctly, this will result in (1) an error mark "!" on the right-hand side of the text field and (2) a floating error message whenever the field has focus, as shown in the error screenshots below. It is possible to have more than one error active at the same time, as also shown in the screenshots below.

There are three error situations:

  • "Invalid Dispatch", related to the Dispatch field, for an empty or letterless entry.
  • "Invalid Argument 0", related to theArgument 0 field, for a blank or unacceptable value (i.e., not coprime to 26).
  • "Invalid Argument 1", related to the Parameter B field, for a blank or out-of-range value.

Note: You may either limit the input in the numerical fields to positive numbers or provide the same errors if negative numbers or non-numerical input are entered.

For illustration, we are providing several screenshots for a possible implementation of the app: see image.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.