20 package net.sf.gridarta.utils;
22 import java.util.Arrays;
23 import org.jetbrains.annotations.NotNull;
24 import org.junit.Assert;
25 import org.junit.Test;
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 };
43 private static final byte[]
PLAINTEXT = { (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08 };
50 private static final byte[]
IPHERTEXT = { (byte) 0x06, (byte) 0x6a, (byte) 0xb0, (byte) 0x51, (byte) 0xf8, (byte) 0xa7, (byte) 0xa3, (byte) 0xc3 };
58 final byte[][] tmp =
new byte[2][8];
59 xtea.
encrypt(PLAINTEXT, tmp[0]);
62 if (!Arrays.equals(tmp[0], IPHERTEXT)) {
63 Assert.fail(
"encrypt failure");
66 if (!Arrays.equals(tmp[1], PLAINTEXT)) {
67 Assert.fail(
"decrypt failure");
void encrypt(@NotNull final byte[] plaintext, @NotNull final byte[] ciphertext)
Encrypts a data block.
void decrypt(@NotNull final byte[] ciphertext, @NotNull final byte[] plaintext)
Decrypts a data block.
static final byte [] IPHERTEXT
The expected ciphertext corresponding to KEY and PLAINTEXT.
Implements the XTEA algorithm.
static final byte [] KEY
The key for the test.
Regression tests for Xtea.
static final byte [] PLAINTEXT
The plaintext for the test.
void test()
Checks that basic encryption and decryption works.