Sha256: 04d3fd3a0472ef0ec3122516ccb2f9101ad1c6ae510779c3d8e3c9ca275fbe77
Contents?: true
Size: 1.29 KB
Versions: 89
Compression:
Stored size: 1.29 KB
Contents
import org.junit.Before import org.junit.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals import kotlin.test.assertTrue class RandomKeyCipherTest { private lateinit var cipher: Cipher @Before fun setup() { cipher = Cipher() } @Test fun cipherKeyIsMadeOfLetters() { assertTrue(cipher.key.matches(Regex("[a-z]+"))) } @Test fun defaultCipherKeyIs100Characters() { assertEquals(100, cipher.key.length) } @Test fun cipherKeysAreRandomlyGenerated() { assertNotEquals(Cipher().key, cipher.key) } /** * Here we take advantage of the fact that plaintext of "aaa..." doesn't output the key. This is a critical problem * with shift ciphers, some characters will always output the key verbatim. */ @Test fun cipherCanEncode() { val expectedOutput = cipher.key.substring(0, 10) assertEquals(expectedOutput, cipher.encode("aaaaaaaaaa")) } @Test fun cipherCanDecode() { val expectedOutput = "aaaaaaaaaa" assertEquals(expectedOutput, cipher.decode(cipher.key.substring(0, 10))) } @Test fun cipherIsReversible() { val plainText = "abcdefghij" assertEquals(plainText, cipher.decode(cipher.encode(plainText))) } }
Version data entries
89 entries across 89 versions & 1 rubygems