Skip to content

Commit

Permalink
Reto mouredev#24 - Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
marchdz committed Jun 13, 2023
1 parent 82a2fd0 commit fbb6d8f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Retos/Reto #24 - CIFRADO CÉSAR [Fácil]/kotlin/marchdz.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fun caesarCipher(positionsToShift: Int, text: String) {
val lowerCase = "abcdefghijklmnopqrstuvwxyz"
val upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var textToPrint = ""

for (character in text) {
textToPrint += when {
character.isLowerCase() -> lowerCase[(lowerCase.indexOf(character) + (positionsToShift % 26) + 26) % 26]
character.isUpperCase() -> upperCase[(upperCase.indexOf(character) + (positionsToShift % 26) + 26) % 26]
else -> character
}
}
println(textToPrint)
}

fun caesarDecipher(positionsToShift: Int, text: String) {
caesarCipher(-positionsToShift, text)
}

fun main() {
caesarCipher(35, "Probando el programa")
caesarDecipher(35, "Yaxkjwmx nu yaxpajvj")
}

0 comments on commit fbb6d8f

Please sign in to comment.