You are on page 1of 4

CS508 – Modern Programming Languages

Total Marks: 20
Assignment No. 03
Due Date: Feb 11, 2022
Semester: Fall 2021

Please read the following instructions carefully before solving & submitting assignment, otherwise no email
regarding deduction of marks will be entertained.

Uploading Instructions:
 You can use simple Notepad or any other text editor (like Sublime Text, Atom, VS Code etc.) for coding.
 For compilation purpose, you can either use the online compiler (i.e., https://bit.ly/3swaRoT) or download
the Java Development Kit (JDK) from https://bit.ly/3sjJ9vs, install it in your Laptop/PC and then use it for
compilation purpose.
 Following files must be submitted in a single Zip or RAR file.
 Java code file, having extension .java (e.g., Main.java)
 An animated .gif file (e.g., Animation.gif) which should show only "execution" of your code.
DO NOT waste time on showing your source code in the GIF file. Furthermore, viewing area
should be maximum in GIF file. (For Recording .gif, a software named ScreenToGif is uploaded
at VU-LMS; https://bit.ly/3edPzFX, or you can use any other gif recording tool as well)
 First record must be with your own VU Student Id in .gif file.
 After finalizing, put both files in a single folder, rename it to your own VU Student Id, compress it with Zip
or RAR format and submit at VU-LMS within due date.
 No assignment will be accepted through email.

Rules for Marking:


It should be cleared that your assignment will not get any credit if:
 The assignment is submitted after due date.
 The assignment is not submitted in .zip or .rar format.
 The submitted assignment does not open or file is corrupt.
 The assignment is fully or partially copied from other student or ditto copy from handouts or Internet;
strict disciplinary action will be taken in this case.
 You do not submit any of the above-mentioned files or use some other VU Student Id; Zero Marks will be
awarded, and no excuse will be accepted in any case.
Note: Do not put any query on MDB regarding this assignment, if you have any query then email at
cs508@vu.edu.pk

Lectures Covered: This assignment covers Lectures 23 to 30.

1
CS508 – Modern Programming Languages
Total Marks: 20
Assignment No. 03
Due Date: Feb 11, 2022
Semester: Fall 2021

Problem Statement:
Encryption is the process of encoding data in such a way that only authorized person can read it. Encoding
means conversion of data to an unreadable format which is called cipher text. A secret code (called key) is
required to read the data.

You can devise any technique to encrypt a text. Like you can write letters of each word in reverse order. For
example, the text "I like it" becomes "I ekil ti". Another way is to put next letter in place of each letter, i.e. 'a'
becomes 'b', 'b' becomes 'c' and 'z' becomes 'a'. So, in this way, "I like it" becomes "J mjlf ju".

Keeping in view the above discussion, you are required to write an Encryption System in Java language which
encrypts and decrypts a message.

For encryption part, consider the following points:


1) Program takes your student Id, full name and a text message as inputs.
2) It extracts the numeric part of your student ID and also counts the number of characters in your full
name (excluding spaces).
3) It then divides the numeric part of your student ID with the number of characters in your full name and
finds the remainder. This remainder will be called as Key.
4) Now, it performs XOR operation on each character in text message with the key and store the result as
an encrypted text.
5) It will then display the encrypted text and key on the screen.

Example:
Let's suppose that your student Id is bs123456789, full name is Muhammad Bilal Khan and you want to
encrypt I Love Pakistan. Then, the numeric part of your student Id is 123456789 and number of characters in
your name (excluding space) are 17. After dividing 123456789 with 17 the remainder is 1 (which is key). Now
perform XOR on each character of "I Love Pakistan." with 1 and store the result in the form of char data type.
Combine all as a single encrypted text (i.e., H!Mnwd!Q`jhru`o/) and display it on screen.

For decryption part, consider the following points:


1) Program takes the encrypted text and key as inputs from user.
2) It then performs XOR operation on each character of encrypted text with key, store the result in the
form of char data type and combine all as a single decrypted message.
3) Finally, it displays the decrypted message on the screen.

2
CS508 – Modern Programming Languages
Total Marks: 20
Assignment No. 03
Due Date: Feb 11, 2022
Semester: Fall 2021

Example:
Let's suppose, you want to decrypt the text "H!Mnwd!Q`jhru`o/" and your key is "1". So, perform XOR on
each character of encrypted text with 1 and store the result in the form of char data type. Combine all as a
single plaintext message i.e., “I Love Pakistan.” and display it on screen.

Important Points to Remember:

1) At the start of execution, program should ask the user that whether s/he wants to encrypt or decrypt a
message or exit the program. If the user chooses any other option (aside from these three) then
program should display the error message.
2) Program should repeatedly display the options to the user that whether s/he wants to encrypt, decrypt
or exit the program. Without choosing exit option, program should not be terminated.
3) At exit, the program should display Student Id as a developer of this program.
4) Write three separate functions named as doEncryption(), doDecryption() and developedBy() to
implement the functionality.
5) Your program should only accept those student Ids which are exactly equal to eleven (11) characters
i.e., bs123456789. If Id is less than or greater than eleven characters then program should display the
message "Provided Student Id is wrong".
6) Your program should not accept those full names which are less than six (6) characters.
7) It is required to make sure that key value should not be less than 1.
8) Program should be able to encrypt full length text messages (i.e., long sentences including alphabets,
numbers, punctuation marks and spaces etc.). However, minimum length for text message should be
of 10 characters.
9) For decryption, if entered message is less than 1 character then program should display the error
message "Provided message is wrong."
10) NumberFormatException should be handled properly at appropriate places in the program.
11) For demonstration purpose, you must use your own student ID and name. Otherwise, your solution
would not get any credit.
12) You are required to show the working of both encryption and decryption part. Run the program and
encrypt a message (note down the encrypted text and key). Now, go for decrypt option and provide
the same encrypted text and key to verify that it generates the original plaintext message.

Sample Output:
For better understating and sample output, please see the animation (i.e., Animation.gif), attached to this
assignment.

3
CS508 – Modern Programming Languages
Total Marks: 20
Assignment No. 03
Due Date: Feb 11, 2022
Semester: Fall 2021

Note:
DO REMEMBER that you must use your own VU Student ID as an input in this program.

Good Luck

You might also like