src/main/scala/atbash.scala

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
object Atbash {
  def apply() = this

  val GroupSize = 5
  val Alphabet = 'a' to 'z'
  val CharMap = Alphabet.zip(Alphabet.reverse).toMap.withDefault {
      _ match {
        case c if (c.isDigit) => c
        case _ => ""
      }
  }

  def encode(text: String) =
    text.toLowerCase.map(CharMap).mkString.grouped(GroupSize).mkString(" ")
}

Comments

OK... figured out how to deal with the unwanted chars and the resulting empty strings so clean is no longer needed :)

helenst commented 23 May 2016 at 10:43 UTC

for me filtering w/ isLetterOrDigit the lowercase String proved to be sufficient. :-)
(and then withDefault identity).

abo64 commented 23 May 2016 at 11:25 UTC

You're not logged in right now. Please login via GitHub to comment