2017-2018-2 20165207 Experiment 3 "Agile Development and XP Practice" Experiment Report

Java experiment three experiment report

Experimental content

code specification

Irregular code may hinder reading. After pasting the code of the submission point 1 set by the teacher in the cloud class, I first used the Reformat Code function of the Code tab in IDEA to standardize the format of the code.

Then, I downloaded the alibaba plugin , to further study the specification of the code. First of all, this code does not contain the comment information about the author.

Then, add my student number as the comment information of the author, and then change the directly used number ("magic value") to the value assigned in the parentheses of the for loop. Variables

and then scan the coding specification, it is not recommended to use line comments,

so I think Generate is a very convenient function for the Code menu, which can directly generate the framework of the overriding method and the construction method. It is very convenient to use the shortcut key Alt+Insert For convenience
Finally, here's a screenshot of the first checkpoint commit:

pair

In this part, first of all, my partner Jia Puhan and I added each other as our own project...Administrator, yes, it is the administrator:
Then download his project in IDEA, find the Complex code
of the last experiment and test it Add a test case to the code:
The result of passing the test:
Below the screenshot below is the Git log of the partner's project, which contains the commit record that I submitted after adding the test case

refactor

Through the teacher's blog, I learned that refactoring refers to changing the internal structure of the software without changing the external behavior of the software, making the software easier to read, easier to maintain, and easier to change.
The content of refactoring includes renaming irregular variable names, extracting repeated functions in the code, modifying overly long methods and parameter columns, decomposing complex logical conditional expressions, and so on.
My partner's code can be said to be very standard. After several readings, I decided to refactor the CPU code that my partner tested in the sixth week of class. Of course, before the refactoring, I added @author to the program. Note :

I forgot to take a screenshot of the initial code, so I have to explain the process of refactoring my partner's program part by part.
First of all, the attribute speed of the CPU is not modified by private. The name of the speed is
the attribute of the s variable, which is friendly. You can use this variable directly with dots, just like the structure in the C language, but there are two methods: setSpeed ​​and getSpeed ​​in the program. , so it does not meet the requirements of encapsulation to set the attribute of the variable as friendly. In addition, the initial variable s should be the speed attribute of the CPU, the name is not "clear". Refactoring was carried out in these two places, the attribute of the variable was set to private, the name of s was changed to speed, and the following is the result after modification. The

next place that can be refactored is the rewritten equals and toString methods. Add @Override

on it and then there's nothing special to refactor, here's a screenshot of the third checkpoint

Pair learning Java cryptography related content

Symmetric Encryption Algorithm-DES

Triple-DES is an improvement of the DES algorithm, and its security has been improved compared to DES. The string parameter passed in to get the key generator is "DESede", so the program knows that we are using the Triple-DES algorithm. And it should also be noted that

  1. There are two ways to store keys. Or save the key in the file in the form of object serialization. In this case, the object is saved in the file. The writeObject method provided in the ObjectOutputStream class can serialize the object and process it in a stream. Here, the file output stream is passed as a parameter to the constructor of the ObjectOutputStream class, so that the created key will be saved in the file key1.data. Or write to a file in the form of bytes, first create a file output stream object to specify the destination file, that is, the file where we save the key, then call the write method of the file output stream, and specify the parameter as the key content. The key content in the byte array can be written to the destination file in the form of bytes. The former is relatively convenient to operate, and the latter can more intuitively print the contents of the key through a byte array. In the example of the teacher we studied, these two methods are linked together, and the first one uses object serialization to store the key in the file key1.dat. But although the key is stored in this way, we don't know its content. But the latter method can be used to create a file input stream, the source of the input stream is the file just generated. After the input stream is successfully created, pass it as a parameter to the newly created object input stream. The object input stream can read the key file serialized by the object just now. The readObject method of the object input stream is used to return an Object object. Then cast it to the Key class, so that the newly created object of the Key class can call the getEncode method to transfer the content of the key into the byte array, and the key can be output and viewed by outputting the byte array.

One-way hash function MD5 algorithm

At the very beginning, we forgot to use the class method getInstance to create the object when we wrote the code, and hoped to use the constructor new MessageDigest() to create the object directly. This does not meet the requirements. In order to correct the error, IDEA automatically
added an inner class to our program to override the protected method of the MessageDigest object. The problem of this picture occurs,

so be sure to remember the method of this "factory class" to create new objects .
Modify to getInstance
input 20165204and20165207 and get the following output result after MD5 algorithm calculation

learning result

Symmetric Encryption Algorithm DES


Asymmetric Encryption Algorithm RSA

One-way Hash Function Algorithm MD5

Git log Screenshots

Here are a few places after my partner and I divided the work, we forgot to pull when submitting, so there were several merge operations before submitting them. We must pay attention.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325513864&siteId=291194637