Sha256: 5f4d8ccfb0cdafaec073abc032bb63015fbb4b106be5583802d85086e6a395ce
Contents?: true
Size: 689 Bytes
Versions: 396
Compression:
Stored size: 689 Bytes
Contents
object Atbash { private val GROUP_SIZE = 5 fun encode(s: String): String = cipherSubstitution(s).mapIndexed { index, char -> char + groupFinalizer(index) }.joinToString("").trimEnd() fun decode(s: String): String = cipherSubstitution(s) private fun cipherSubstitution(s: String): String = s.fold("", { accum, char -> accum + substitute(char) }) private fun substitute(c: Char): String { return when { c.isDigit() -> c.toString() c.isLetter() -> ('a' + ('z' - c.toLowerCase())).toString() else -> "" } } private fun groupFinalizer(index: Int): String = if ((index + 1) % GROUP_SIZE == 0) " " else "" }
Version data entries
396 entries across 396 versions & 1 rubygems