EE5805 Java Network Programming
Test 1, 2019/20 Summer Term
Question 1. (30 marks)
The simple substitution cipher is a cipher that has been in use for hundreds of years. It basically consists
of substituting every plaintext character for a different ciphertext character. The alphabet set is simplified
to contain only the space character, comma, full-stop, digits (0-9), uppercase letters (A-Z) and lowercase
letters (a-z).
alphabets = { ,.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz}
key = {9fj,.6SpC57aeU VJ4Z0ybLXTx2guqI3Hwtin8GQNP1KFRklEzdrvocWsDhBAMmYO}
You can see from the given key that
• ‘ ‘ is substituted by ‘9’
• ‘,’ is substituted by ‘f’
• ‘.’ is substituted by ‘j’
• ‘0’ is substituted by ‘,’
• ‘1’ is substituted by ‘.’
• ‘2’ is substituted by ‘6’
• and so on.
a) [20 marks] Implement the methods encrypt(String key, String text) and decrypt(String key, String
cipher) in the class Q1.java.
b) [10 marks] Create a test class Q1Test.java with two test cases for the two methods in part (a) using
JUnit.
• For encryption:
key: 9fj,.6SpC57aeU VJ4Z0ybLXTx2guqI3Hwtin8GQNP1KFRklEzdrvocWsDhBAMmYO
text: Cheers, you will see this message if your program is correct.
expected result: VkKKsDf9YoB9Mldd9DKK9hklD9rKDDQRK9lF9YoBs9csoRsQr9lD9PossKPhj
• For decryption:
key: 9fj,.6SpC57aeU VJ4Z0ybLXTx2guqI3Hwtin8GQNP1KFRklEzdrvocWsDhBAMmYO
cipher: VkKKsDf9YoB9Mldd9DKK9hklD9rKDDQRK9lF9YoBs9csoRsQr9lD9PossKPhj
expected result: Cheers, you will see this message if your program is correct.
Question 2. (40 marks)
A video content provider maintains a daily log of the clients’ streaming requests. The streaming requests
are stored in a file (video_data.txt) with one request per line. Each streaming request contains the
following three fields separated by commas:
• a timestamp (represented by a long integer),
• a video ID (a string), and
• a client’s IP address.
Write a Java program to find the top 5 most active clients from the log file, i.e. the five IP addresses with
the highest view count.
Implement the methods readDataFile(String filename) and findTop5Clients(List<VideoRecord> list) in the
class Q2.java. The specification of the methods is written in the comment section.
The expected program output is as follow:
END OF PAPER
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。