Sha256: 46195b9a71abdb9bf0abdea0394fb2a863390196deb616b8bb211d23c7afb27a
Contents?: true
Size: 1.66 KB
Versions: 236
Compression:
Stored size: 1.66 KB
Contents
import org.scalatest.{Matchers, FunSuite} class CipherTest extends FunSuite with Matchers { test("Random key cipher - can encode/decode") { // Here we take advantage of the fact that plaintext of "aaa..." // outputs the key. This is a critical problem with shift ciphers, some // characters will always output the key verbatim. val cipher = Cipher(None) cipher.encode("aaaaaaaaaa") should be (cipher.key.substring(0, 10)) cipher.decode(cipher.key.substring(0, 10)) should be ("aaaaaaaaaa") } test("Invalid key - contains caps") { pending intercept[IllegalArgumentException] { Cipher(Some("ABCD")) } } test("Invalid key - contains numerics") { pending intercept[IllegalArgumentException] { Cipher(Some("123")) } } test("Invalid key - is empty") { pending intercept[IllegalArgumentException] { Cipher(Some("")) } } test("Substitution cipher - can encode") { pending Cipher(Some("abcdefghij")).encode("aaaaaaaaaa") should be ("abcdefghij") } test("Substitution cipher - can decode") { pending Cipher(Some("abcdefghij")).decode("abcdefghij") should be ("aaaaaaaaaa") } test("Substitution cipher - is reversible") { pending val cipher = Cipher(Some("abcdefghij")) cipher.decode(cipher.encode("abcdefghij")) should be ("abcdefghij") } test("Substitution cipher - can double shift") { pending val cipher = Cipher(Some("iamapandabear")) cipher.encode("iamapandabear") should be ("qayaeaagaciai") } test("Substitution cipher - can wrap") { pending Cipher(Some("abcdefghij")).encode("zzzzzzzzzz") should be ("zabcdefghi") } }
Version data entries
236 entries across 236 versions & 1 rubygems