Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa89220

Browse files
labe2301J-manLans
authored andcommitted
[feature] Add tests to PlayfairCipher
1 parentfaae7b2 commitfa89220

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
packagecom.thealgorithms.ciphers;
2+
3+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
4+
importstaticorg.junit.jupiter.api.Assertions.assertNotEquals;
5+
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
6+
7+
importjava.lang.reflect.Method;
8+
importjava.util.Arrays;
9+
10+
importorg.junit.jupiter.api.BeforeEach;
11+
importorg.junit.jupiter.api.Test;
12+
13+
publicclassMyPlayfairCipherTest {
14+
privatePlayfairCipherplayfair;
15+
privatefinalStringkeyword ="KEYWORD";
16+
17+
@BeforeEach
18+
publicvoidsetup() {
19+
playfair =newPlayfairCipher(keyword);
20+
}
21+
22+
@Test
23+
voidshouldEncryptAndDecryptDuringSameRowDigraph() {
24+
Stringplaintext =keyword.substring(0,2);
25+
26+
Stringencrypted =playfair.encrypt(plaintext);
27+
Stringdecrypted =playfair.decrypt(encrypted);
28+
29+
assertEquals(plaintext,decrypted,"Should not decrypt to the same letters");
30+
}
31+
32+
@Test
33+
voidshouldPadOddLengthplaintext() {
34+
Stringplaintext ="cat";
35+
36+
Stringencrypted =playfair.encrypt(plaintext);
37+
38+
assertTrue(encrypted.length() %2 ==0,"Should be even length");
39+
}
40+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp