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

Version Path
trackler-2.0.6.33 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.32 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.31 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.30 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.29 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.28 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.27 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.26 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.25 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.24 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.23 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.22 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.21 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.20 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.19 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.18 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.17 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.16 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.15 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt
trackler-2.0.6.14 tracks/kotlin/exercises/simple-cipher/src/test/kotlin/RandomKeyCipherTest.kt