Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
12
Task/Caesar-cipher/Scala/caesar-cipher-3.scala
Normal file
12
Task/Caesar-cipher/Scala/caesar-cipher-3.scala
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class Caeser(val key: Int) {
|
||||
@annotation.tailrec
|
||||
private def rotate(p: Int, s: IndexedSeq[Char]): IndexedSeq[Char] = if (p < 0) rotate(s.length + p, s) else s.drop(p) ++ s.take(p)
|
||||
|
||||
val uc = 'A' to 'Z'
|
||||
val lc = 'a' to 'z'
|
||||
val as = uc ++ lc
|
||||
val bs = rotate(key, uc) ++ rotate(key, lc)
|
||||
|
||||
def encode(c: Char) = if (as.contains(c)) bs(as.indexOf(c)) else c
|
||||
def decode(c: Char) = if (bs.contains(c)) as(bs.indexOf(c)) else c
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue