Gridarta Editor
XteaTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.utils;
21 
22 import java.util.Arrays;
23 import org.jetbrains.annotations.NotNull;
24 import org.junit.Assert;
25 import org.junit.Test;
26 
31 public class XteaTest {
32 
36  @NotNull
37  private static final byte[] KEY = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef };
38 
42  @NotNull
43  private static final byte[] PLAINTEXT = { (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08 };
44 
49  @NotNull
50  private static final byte[] IPHERTEXT = { (byte) 0x06, (byte) 0x6a, (byte) 0xb0, (byte) 0x51, (byte) 0xf8, (byte) 0xa7, (byte) 0xa3, (byte) 0xc3 };
51 
55  @Test
56  public void test() {
57  final Xtea xtea = new Xtea(KEY);
58  final byte[][] tmp = new byte[2][8];
59  xtea.encrypt(PLAINTEXT, tmp[0]);
60  xtea.decrypt(tmp[0], tmp[1]);
61 
62  if (!Arrays.equals(tmp[0], IPHERTEXT)) {
63  Assert.fail("encrypt failure");
64  }
65 
66  if (!Arrays.equals(tmp[1], PLAINTEXT)) {
67  Assert.fail("decrypt failure");
68  }
69  }
70 
71 }
void encrypt(@NotNull final byte[] plaintext, @NotNull final byte[] ciphertext)
Encrypts a data block.
Definition: Xtea.java:66
void decrypt(@NotNull final byte[] ciphertext, @NotNull final byte[] plaintext)
Decrypts a data block.
Definition: Xtea.java:90
static final byte [] IPHERTEXT
The expected ciphertext corresponding to KEY and PLAINTEXT.
Definition: XteaTest.java:50
Implements the XTEA algorithm.
Definition: Xtea.java:28
static final byte [] KEY
The key for the test.
Definition: XteaTest.java:37
Regression tests for Xtea.
Definition: XteaTest.java:31
static final byte [] PLAINTEXT
The plaintext for the test.
Definition: XteaTest.java:43
void test()
Checks that basic encryption and decryption works.
Definition: XteaTest.java:56