Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object caesar extends App {
- def cifrar(or: String, clave: Int):String = {
- for (c<-or) yield if (c.isLetter)((c.toUpper.toInt+clave)%26+'A'.toInt).toChar else c
- }
- def descifrar(or: String, clave:Int):String = {
- for (c<-or) yield if (c.isLetter)((c.toUpper.toInt-clave)%26+'A'.toInt).toChar else c
- }
- println("Introduzca texto a cifrar:")
- val orig = readLine()
- println("Introduzca valor clave:")
- val clave = readInt()
- val cifrado = cifrar(orig,clave)
- println("Su texto cifrado es: " + cifrado)
- println("descifrado a :" + descifrar (cifrado, clave))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement