Programming lesson
Building SDPEncryptor: An Android Affine Cipher App for CS6601 Assignment 4 (Fall 2025)
Learn to develop the SDPEncryptor Android app for CS6601 Assignment 4. This tutorial covers affine cipher encryption, error handling with setError, and Android Studio setup with Java and API 34.
Introduction to SDPEncryptor and the Affine Cipher
In CS6601 Assignment 4 (Fall 2025), you are tasked with building SDPEncryptor, an Android app that encrypts messages using a simple affine cipher. This assignment is a cornerstone for understanding Android development, setting up your environment, and implementing cryptographic logic. The affine cipher is a type of substitution cipher where each letter is transformed using the formula: E(x) = (ax + b) mod m, where a and b are keys, and m is the alphabet size (26 for English). This tutorial will guide you through the key concepts without giving away the complete solution, ensuring you meet the assignment's learning objectives.
Setting Up Your Android Studio Environment
As emphasized in the assignment, spending 70-90% of your time on setup is normal. You must use Android Studio Ladybug Feature Drop | 2024.2.2 (or compatible) with the following configuration:
- Package name:
edu.gatech.seclass.sdpencryptor - Language: Java (Kotlin allowed but limited support)
- Minimum SDK: API 34 (Android 14)
- Build configuration language: Groovy DSL (build.gradle)
Ensure your build.gradle (Module: app) includes these dependencies:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.11.1'Also, enable unit test support with Android resources:
android {
testOptions {
unitTests {
includeAndroidResources = true
}
}
}Disable lint to avoid build interruptions:
android {
lintOptions {
tasks.lint.enabled = false
abortOnError false
}
}This setup mirrors real-world app development, similar to how AI apps like ChatGPT or finance apps like Robinhood require precise SDK configurations. Think of it as tuning a gaming PC for optimal performance—getting the right components (SDK, dependencies) ensures smooth gameplay (development).
Understanding the Affine Cipher Logic
The affine cipher is a classic encryption algorithm. For this app, you'll implement encryption in Java. The core formula is:
int encrypted = (a * (plainChar - 'A') + b) % 26;
char cipherChar = (char) (encrypted + 'A');Your function should handle both uppercase and lowercase letters, leaving non-alphabetic characters unchanged. This is similar to how social media algorithms transform raw data (user posts) into personalized feeds (encrypted messages). Just as TikTok's algorithm uses keys (user preferences) to modify content, your app uses a and b to transform text.
Designing the User Interface
The assignment provides mockups, but you have freedom in UI design as long as you use the exact widget identifiers. You'll need at least:
- EditText for input message (id:
editTextInput) - EditText for key 'a' (id:
editTextKeyA) - EditText for key 'b' (id:
editTextKeyB) - Button to trigger encryption (id:
buttonEncrypt) - TextView to display output (id:
textViewOutput)
Use a ConstraintLayout to arrange these elements. For example, place the input EditText at the top, keys below, button below keys, and output at the bottom. This layout is intuitive for users, similar to how mobile banking apps arrange login fields (account number, password) in a clear sequence.
Implementing Error Handling with setError
The assignment requires error messages using EditText.setError(). There are three error situations:
- Empty input message: If the user presses encrypt without entering text, set error on the input EditText.
- Invalid key 'a': Key 'a' must be a positive integer coprime with 26 (i.e., gcd(a, 26) = 1). If not, set error on the key 'a' EditText.
- Invalid key 'b': Key 'b' must be a non-negative integer. If not, set error on the key 'b' EditText.
Example code snippet for validation:
String input = editTextInput.getText().toString().trim();
if (input.isEmpty()) {
editTextInput.setError("Message cannot be empty");
return;
}
int a = Integer.parseInt(editTextKeyA.getText().toString());
if (a <= 0 || gcd(a, 26) != 1) {
editTextKeyA.setError("Key 'a' must be positive and coprime with 26");
}
int b = Integer.parseInt(editTextKeyB.getText().toString());
if (b < 0) {
editTextKeyB.setError("Key 'b' must be non-negative");
}This error handling is reminiscent of form validation in web apps like Google Forms, where red highlights guide users to correct input. In the context of school life, it's like a teacher marking incorrect answers—specific feedback helps students improve.
Testing with Unit Tests
The assignment includes unit tests using JUnit and Robolectric. You'll write tests to verify encryption logic and error handling. For example:
@Test
public void testEncryption() {
SDPEncryptor encryptor = new SDPEncryptor();
String result = encryptor.encrypt("HELLO", 5, 8);
assertEquals("RCJJA", result);
}
@Test
public void testEmptyInputError() {
// Simulate button press with empty input
// Verify that setError was called on editTextInput
}Testing is crucial in AI development—just as you test a chatbot's responses to ensure accuracy, you test your app's encryption to guarantee correctness.
Common Pitfalls and How to Avoid Them
- Package name mismatch: Double-check that your package is exactly
edu.gatech.seclass.sdpencryptor. A typo will break auto-grading. - SDK version: Use API 34 only. Using API 35 or 33 may cause compatibility issues.
- Widget IDs: Use the exact IDs provided. The auto-grader looks for these.
- Affine cipher implementation: Remember that key 'a' must be coprime with 26. Valid values are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25.
These pitfalls are analogous to gaming glitches in popular titles like Fortnite—a small oversight can ruin the experience. By paying attention to details, you ensure a smooth run.
Conclusion
Building SDPEncryptor is a rewarding challenge that blends Android development with classical cryptography. By following this guide, you'll be well-prepared to tackle the assignment. Remember to test thoroughly and adhere to the specifications. Good luck, and happy coding!