Professional Documents
Culture Documents
Coursework assignment
The coursework will consist of two parts, weighing 50% of the final coursework mark each:
An Android application
A report accompanying the application development
Android application
Application part of the coursework will be marked for design (40%) and functionality (60%).
There are three main tasks of the application (Marks allocated as below):
User should be able to navigate through the app, between any two screens/activities.
Task 1
User should be able to ask for a pair of prime numbers. These numbers should be at least above the 10000th
prime number (104729), and the user should specify which primes they want by entering their orders
(10000+). This task should be run as a thread, so that application remains responsive while it searches for
the prime numbers.
Task 2
The two numbers found in task 1 should be displayed as two grids of images one image for each digit. You
may use a separate activity for displaying these numbers.
Order of 1st
prime
Order of 2nd
prime
GENERATE
ENCRYP
DECRYPT
Task 3
The RSA part of the app should be realised in a separate activity (or two, one for each encryption/decryption).
The encryption should enable user to enter a message (string of characters) and encrypt it using the public
key. App should display the encrypted message and the private key which can be used to decrypt it.
Decryption part should enable user to enter an encrypted message and a private key, and display the
decrypted message. Further details are presented following the RSA example.
Enter prime values
for p and q:
GENERATE
Enter a message to
encrypt
Enter the public key
Encrypted message
Enter a message to
decrypt
Enter the private key
Decrypted message
t e x t
char to int
conversion
char to int
conversion
INT
INT
INT
INT
RSA
RSA
enc
dec
INT
INT
INT
INT
INT
INT
INT
INT
INT
INT
INT
INT
int to char
conversion
int to char
conversion
m j p m
t e x t
RSA
Following is the step by step explanation of how RSA keys are generated:
1. Choose two prime numbers p and q, n=p*q
2. Find numbers d and e such that: d*e (mod (p-1)*(q-1)) = 1
3. (e, n) is the public key; (d, n) is the private key
RSA encryption and decryption functions this way (m message, c cipher text):
1. c = m^e (mod n) encryption
2. m = c^e (mod n) decryption
RSA example:
1.
2.
3.
4.
5.
Note that the number n should be greater than the maximum value to be encrypted (the number of
different characters). When dealing with lower case letters the maximum value is 26.
Following is an example of RSA application code (both java and xml). Here, the numbers from the previous
example have been used as public and private keys, and the encryption/decryption is being performed on
integers. (This example will be available on Moodle in form of .txt files for easier copying)
import
import
import
import
android.support.v7.app.AppCompatActivity;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import java.math.BigInteger;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void encryptClick(View v) {
EditText enter = (EditText) findViewById(R.id.enter_enc);
TextView text = (TextView) findViewById(R.id.enc_view);
BigInteger result = new BigInteger(String.valueOf(enter.getText())).pow(3);
BigInteger modulus = new BigInteger("55");
result = result.mod(modulus);
text.setText(result.toString());
}
public void decryptClick(View v) {
EditText enter = (EditText) findViewById(R.id.enter_dec);
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/enc_view"
android:layout_below="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="21dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="encrypt"
android:id="@+id/button"
android:layout_marginTop="28dp"
android:onClick="encryptClick"
android:nestedScrollingEnabled="false"
android:layout_below="@+id/enter_enc"
android:layout_alignStart="@+id/decrypt" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/enter_enc"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/dec_view"
android:layout_marginBottom="47dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="decrypt"
android:id="@+id/decrypt"
android:onClick="decryptClick"
android:nestedScrollingEnabled="false"
android:layout_above="@+id/dec_view"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/enter_dec"
android:layout_above="@+id/decrypt"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Your app should enable the user to enter values for p and q, and then find appropriate values for n, e and
d, resulting in working public and private key pairs (e, n) and (d, n). User can use the prime generating part
of the app to choose a value for n. Remember n should be greater than the number of different characters
to be encrypted but doesnt need to be as big as the numbers generated in task 1. Specify in the report why
it would be impractical to use such big numbers for RSA algorithm on a phone.
Report
The format of the report describing the application development is as follows:
Abstract [100 words] 5%
Introduction [1000 words] 10%
1. One to two pages describing the importance of such an app.
2. Where it could be applicable within a real-time embedded system environment?
Application [1500 words] 20%
1. The market study.
2. Statistics of prime number generators across different mobile OS.
Methodology & Challenges [2000 words] 40%
1.
2.
3.
4.
5.
6.
Difficulties
How did you solve the problem
Explain the architecture
Java
XML
How they are linked
Results 20%
1. Screenshots and examples
Conclusions [500 words] 5%
Tips:
Consider using BigInteger for the numbers involved in RSA calculation (as in the example code).
Design of the application is entirely up to you (multiple screens/activities) but a clear and nice
looking application means a higher mark.
Consider using Android 4.4 (KitKat) for application development (the example RSA code is compatible
with it).
Consider using threads for time consuming tasks, so that your app stays responsive at all times.