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

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

content

  • Experimental content
  • Format code with tools in IDEA
  • Download partner code and add test cases
  • Download partner code and refactor
  • Pair Programming--JAVA Cryptography Algorithm
  • Experiment impressions & PSP

1. Experimental content

1. XP Basics

Extreme Programming (Extreme Programming, XP) is a new and fast software development method. The XP team uses on-site customers, ad hoc planning methods, and continuous testing to provide rapid feedback and comprehensive communication:

  • XP is a methodology developed with the goal of developing software that meets customer needs
  • XP is a practice-based software engineering process and thought
  • XP considers code quality more important than people generally think
  • XP is especially suitable for small responsible, self-motivated teams to develop software with uncertain or rapidly changing requirements

The cornerstone of XP software development is the activities of XP , including: coding, testing, listening, and designing.

2.XP core practice
3. Related tools

2. Use tools to format code in IDEA

Experiment content: Install the alibaba plug-in to solve the specification problem in the code. Use the tools in IDEA to reformat the code below, and then study the Code menu to find a function that feels best to you. Submit a screenshot and add your student ID watermark.

public class CodeStandard {
public static void main(String [] args){
StringBuffer buffer = new StringBuffer();
buffer.append('S');
buffer.append("tringBuffer");
System.out.println(buffer.charAt(1));
System.out.println(buffer.capacity());
System.out.println(buffer.indexOf("tring"));
System.out.println("buffer = " + buffer.toString());
if(buffer.capacity()<20)
buffer.append("1234567");
for(int i=0; i<buffer.length();i++)
System.out.println(buffer.charAt(i));
}
}

Programming standards make code easier to read and understand. Programming standards include: declarative names, clear expressions, straightforward control flow, readable code and comments, and the importance of using certain rules and idioms consistently when pursuing these.

  • Settings ->Plugins -> Browse repositories...install alibaba
  • Right-click on the project name and select from the popup menu编码规约扫描

  • Where there are irregularities, there are Chinese prompts and the line is located. Alibaba classifies the problem into three levels: block/critical/major. Modified according to the error message.

  • Code->RenameOverride method
  • Code->Comment with Line CommentChange this line to a comment
  • Code->Comment with Block CommentAdd a comment to this line, which is also one of my favorite shortcut keys (Ctrl+Shift+)

3. Download the partner code and add test cases

Experiment content: Add your learning partner to your own project on the code cloud. After confirming that the partner's project has been added to your own, download the Complex code of partner experiment 2 and add no less than three JUnit unit test cases.

  • First add my partner to my project in the code cloud
  • mkdir 5312AnnaCreate a new folder to easily distinguish git clone 搭档码云链接and connect to the partner code cloud, so that you can easily find the partner code
  • Download partner Com.java, write ComTest.java

    import junit.framework.TestCase;
    import org.junit.Test;
    public class ComTest extends TestCase {
    Com c1 = new Com(1,1);
    Com c2 = new Com(0,-1);
    Com c3 = new Com(-1,1);
    @Test
    public void testgetRealPart() throws Exception {
        assertEquals(1.1, new Com().setA(1.1));
        assertEquals(0.-1, new Com().setA(0.-1));
        assertEquals(-1.1, new Com().setA(-1.1));
    }
    @Test
    public void testgetImagePart() throws Exception {
        assertEquals(1.1, new Com().setB(1.1));
        assertEquals(0.-1, new Com().setB(0.-1));
        assertEquals(-1.1, new Com().setB(-1.1));
    }
    @Test
    public void testComAdd() throws Exception {
        assertEquals("1.0", c1.ComAdd(c2).toString());
        assertEquals("0.0+2.0i", c1.ComAdd(c3).toString());
        assertEquals("-1.0", c2.ComAdd(c3).toString());
    }
    @Test
    public void testComSub() throws Exception {
        assertEquals("-1.0 -2.0i", c1.ComMinus(c2).toString());
        assertEquals("-2.0", c1.ComMinus(c3).toString());
        assertEquals("-1.0+2.0i", c2.ComMinus(c3).toString());
    }
    }

``git push -git log ComTest.java```

4. Download the partner code and refactor

Common usage:

  • refactor->RenameRename classes, packages, methods, variables
  • refactor->Encapsulate Fieldpackage
  • Source->Generate toString()toString() method
  • refactor->Extract MethodExtract duplicate code

Code after refactoring

class studentdark {
    private int num;
    private String name;
    private int java;

    public int getNum() {
        return num;
    }
    @Override
    public String toString() {
        return "studentdark{" +
                "num=" + num +
                ", name='" + name + '\'' +
                ", java=" + java +
                '}';
    }
    public void setNum(int num) {
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getJava() {
        return java;
    }

    public void setJava(int java) {
        this.java = java;
    }
}
public class studentdarkTest {

    public static void main(String[] args) {
        studentdark student = new studentdark();
        student.setName("caoge");
        student.setNum(5312);
        student.setJava(94);
        System.out.println("学号为"+ student.getNum() +",姓名为"+ student.getName() +"java成绩为"+ student.getJava());
    }



}


5. Pair programming--JAVA cryptography algorithm
-------------
Cryptography includes two branches: Cryptography and Cryptanalyst.

  • Cryptography: It mainly studies how to encode information and how to realize the concealment of information, which is the basis of cryptography theory and the basis of security system design.
  • Cryptanalysis: It mainly studies the deciphering of encrypted messages or the forgery of messages. It is the most direct means to test the security of a cryptosystem. Only a cryptosystem that has passed the actual cryptanalysis test is truly usable.

The Java security architecture is divided into 4 parts:

  • JCA (Java Cryptography Architecture, Java Cryptography Architecture): JCA provides basic encryption framework, such as certificate, digital signature, message digest and key pair generator.
  • JCE (Java Cryptography Extension, Java Encryption Extension Package): JCE is extended on the basis of JCA, and provides various encryption algorithms, message digest algorithms and key management functions. The implementation of JCE is mainly in the javax.crypto package (and its subpackages)
  • JSSE (Java Secure Sockets Extension, Java Secure Sockets Extension): JSSE provides encryption based on SSL (Secure Sockets Layer, Secure Sockets Layer). In the process of network transmission, information will pass through multiple hosts (it is very likely that one of them will be eavesdropped), and finally transmitted to the receiver, which is not safe. This service to ensure network communication security is provided by JSSE.
  • JAAS (Java Authentication and Authentication Service, Java Authentication and Security Service): JAAS provides the function of user authentication on the Java platform.

Our group combines learning the DES algorithm in "Cryptography" and carefully reading the Java Cryptography Algorithm on Mr. Lou's blog , and understands that "DES" is the most commonly used symmetric encryption algorithm, but it is less secure. Improvements to DES security have resulted in the TripleDES algorithm, "DESede", that meets current security needs. Decided to implement the TripleDES algorithm and adjusted the teacher's example code.

Programming ideas:

(1) Obtaining the key generator TheKeyGenerator kg=KeyGenerator.getInstance("DESede");
KeyGenerator class in Java provides a method for creating a symmetric key. The KeyGenerator class predefines a static method getInstance( ), the parameter of the method getInstance( ) is a string type, specifying the name of the encryption algorithm.

(2) Initialize the key generatorkg.init(168); This step generally specifies the length of the key. If we write "DESede", it can be 112 or 168 bits, of which 112 bits are valid.

(3) Generate keySecretKey k=kg.generateKey( ); The key can be used for subsequent encryption and decryption.

(4) Save the key in the file by object serialization

FileOutputStream f=new FileOutputStream("key1.dat");
ObjectOutputStream b=new ObjectOutputStream(f);
b.writeObject(k);

The writeObject method provided in the ObjectOutputStream class can serialize objects and process them 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.

(5) Get the key from the file

FileInputStream f=new FileInputStream("key1.dat");
ObjectInputStream b=new ObjectInputStream(f);
Key k=(Key)b.readObject( );

(6) Create a cipher
Cipher cp=Cipher.getInstance("DESede");
KeyGenerCipher class is a factory class, it does not create an object through the new method, but obtains the Cipher object through a predefined static method getInstance( ). The parameter of the getInstance( ) method is a string that gives what operations the Cipher object should perform.

(7) Initialize the cipher
cp.init(Cipher.ENCRYPT_MODE, k); This method includes two parameters. The first parameter specifies whether the cipher is ready to encrypt or decrypt. If Cipher.ENCRYPT_MODE is passed in, it will enter the encryption mode. The second parameter passes in the key used for encryption or decryption, that is, the key object k read from the file in step 1.

(8) Obtain the plaintext waiting to be encrypted

String s="Hello World!";
byte ptext[]=s.getBytes("UTF8");

(9) Perform encryption
byte ctext[]=cp.doFinal(ptext);

(10) Process the encrypted result

FileOutputStream f2=new FileOutputStream("SEnc.dat");
f2.write(ctext);

Here the encryption result is saved in the file Senc.dat.

Encrypted result:

The key is the same, the decryption process is similar to the encryption process, and the decryption result is:

6. Experiment impressions

Once again paired learning has increased our tacit understanding again, making it even more tacit. Combining the content of cryptography learning with java has further exercised my ability.

step time/h percentage
demand analysis 0.5 10%
design 1 20%
Code 2 40%
test 0.5 10%
analysis Summary 1 20%

Guess you like

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