Android代写:CS6300 SDPEncryptor

实现一个Android的消息加密App, 加密算法使用Substitution cipher.

Substitution cipher

Requirement

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

INPUTS

  1. Message: 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. Alpha Value: first encryption parameter.
    • This input should be an integer coprime to 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 ‘0’.
  3. Beta Value: 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 ‘0’.

OUTPUT

  1. Encrypted Message, 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, b=1, c=2, …).
    • For each letter in the alphabet, where the numeric value is x, the encrypted value of the letter is defined as EE(x) = (αx ​+ ​β) % 26, as in an Affine Cipher.
    • The encrypted character for the input letter is calculated by taking the encrypted number, which is a value between 0 and 25, and translating it back into a letter (again, where a=0, b=1, c=2, …).
    • All non-alphabetic characters must remain unchanged.
    • Capitalization of alphabetic characters must be inverted (i.e., all lowercase characters are transformed into upper case characters and vice versa).
    • The output should be shown using a non-editable TextView that is initially blank and (re)computed when the “ENCRYPT” 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

  • Input:
    • Message = “Cat & Dog”
    • α = 3
    • ​β = 8
  • Output:
    • Encrypted Message = “oIN & rYA”
  • Explanation:
    • “C” has value 2, 2*3+8=14, 14 corresponds to “o” (lowercase since “C” is capitalized).
    • “a” has value 0, 2*0+8=8, 8 corresponds to “I” (capitalized because “a” is lowercase).
    • “ “, “&”, 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. 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:

  1. “Invalid Message”, related to the Message field, for an empty or letterless entry.
  2. “Invalid Alpha Value”, related to the Alpha Value f ield, for a blank or unacceptable value (i.e., not coprime to 26).
  3. “Invalid Beta Value”, related to the Beta Value 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:

We suggest that you try to generate a user interface (UI) similar to the one shown above, but you don’t have to. However, you must make sure to use the exact same identifiers we provide below for your widgets. This is very important, as we will use these identifiers to check and auto-grade your app

IDENTIFIERS

  • messageID
  • alphaValueID
  • betaValueID
  • encryptButtonID
  • encryptedMessageID

PRO-TIP: The identifiers are typed here for you. Just copy and paste them to be safe!

For example, in the XML layout file for your app, the entry for the text field used to input the Message s hould have the following ID: android:id=”@+id/messageID

MANUAL FILE

In addition to developing the app, you will also have to create a manual (in a file called “manual.md” and in Github flavored MD format) that describes how to use the app. Think of this file as a very concise user manual. Feel free to add screenshots to the manual, but that is not mandatory. You can view your markdown file in Github or using an MD viewer. Put the manual.md file in your “Assignment4” folder (see below).

INSTRUCTIONS

  1. Make sure to watch the Android Studio demo (part of the lessons on Android).
  2. In the root of the assigned, private GitHub repository that we made for you, create a directory called “Assignment4”. Hereafter, we will refer to this directory in your local repo as [dir].
  3. Using Android Studio 3. or 4., create an Android app project called “SDPEncryptor” in [dir]. (Make sure that this results in a directory called SDPEncryptor in [dir], as shown in the “Configure Your Project” snapshot below.)
    • Choose “Empty Activity” as your project template
  4. Make sure that your build.gradle file for module app contains the following dependencies: testImplementation ‘junit:junit:4.12’ androidTestImplementation ‘androidx.test.ext:junit:1.1.1’ androidTestImplementation ‘androidx.test.espresso:espresso-core:3.2.0’ androidTestImplementation ‘androidx.test:rules:1.1.1’ (as shown in the figure)
    • If some dependencies are missing, make sure to add them.
    • There may be newer versions of some of the dependencies, but that should not matter.
    • You will have to rebuild the project if you added dependencies (the IDE should let you know that through a notification).
  5. Implement your solution based on the requirements provided above.
  6. To check your solution before submitting, or even while developing it, download this archive and unpack its contents in [dir],1 which should create the following files:
    • SDPEncryptor/app/src/main/java/edu/seclass/sdpencryptor/SanityCheck.java: This file prevents your app from compiling if the identifiers, activity name, or package name are incorrect.
    • SDPEncryptor/app/src/androidTest/java/edu/seclass/sdpencryptor/SmallTestExamples.java: This file contains a set of Espresso tests similar to those we will run on your code for grading, for your convenience. You can run the tests on the command line by executing “gradle connectedAndroidTest” in the project directory. You can also run the tests from within Android Studio, by selecting “Run Tests in” as shown below:
  7. For automated testing, check out Espresso and Android Studio Test Recorder. Here are some Espresso tips, based on past experience:
    • Turn off animations in your AVD, particularly if the tests fail with an AmbiguousViewMatcherException.
    • Avoid using buttons that call private methods, as Espresso will be unable to click them.
    • Avoid elements that cover your fields or buttons, even if these elements are invisible, as they may result in tests that fail to complete.
    • You may need to turn off the autofill feature or spellcheck in your AVD if your tests fail due to auto-completion of text input.
    • Do not add extra field labels or text into the designated EditText fields. Each EditText field should contain only the relevant input or output. You may use other fields for optional labels or UI elements.

SUBMISSION

  1. Add/commit/push your app to your assigned, private repo (the one we made for you). To do so, and make sure that all the necessary files are committed, do the following:
    • Copy and paste in the .gitignore file in the root of your repo the following entries.
  2. As an alternative to Item 1, and only if you know what you are doing, you could also commit and push your app from within Android Studio, which should actually give you an option to do so:
    But please use the instructions in Item 1 if you are unsure.
  3. Submit on gradescope a file, called submission.txt that contains, in two separate lines (1) your GT username and (2) the commit ID for your submission. For example, the content of file submission.txt for George P. Burdell could look something like the following.