caesartest.java

来自「用JAVA编写的小的JAVA程序,是有关密码转换的.有2种算法.」· Java 代码 · 共 49 行

JAVA
49
字号
import junit.framework.TestCase;

/**
 * Class for testing Caesar class
 */
public class CaesarTest extends TestCase {
	
	private Cipher cipher = new Caesar();
	
	/**
	 * Testing the encryption function
	 */
	public void testEncrypt() {
		String plaintext = "geronimo";
		String ciphertext = "igtqpkoq";
		int key = 2;
		
		cipher.setIntKey(key);
		assertEquals(ciphertext, cipher.encrypt(plaintext));
	}
	
	/**
	 * Testing the decryption function
	 */
	public void testDecrypt() {
		String plaintext = "springbreak";
		String ciphertext = "hegxcvqgtpz";
		int key = 15;
		
		cipher.setIntKey(key);
		assertEquals(plaintext, cipher.decrypt(ciphertext));
	}
	
	/**
	 * Verifying encryption
	 */
	public void testEncryptDecrypt() {
		String plaintext = "karelj";
		int key = 12;
		
		cipher.setIntKey(key);
		assertEquals(plaintext, cipher.decrypt(cipher.encrypt(plaintext)));
	}

}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?