From fbb6d8f3874490678e28c9de27752d7c95120cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Hern=C3=A1ndez?= Date: Tue, 13 Jun 2023 18:14:06 +0200 Subject: [PATCH] Reto #24 - Kotlin --- .../kotlin/marchdz.kt" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "Retos/Reto #24 - CIFRADO C\303\211SAR [F\303\241cil]/kotlin/marchdz.kt" diff --git "a/Retos/Reto #24 - CIFRADO C\303\211SAR [F\303\241cil]/kotlin/marchdz.kt" "b/Retos/Reto #24 - CIFRADO C\303\211SAR [F\303\241cil]/kotlin/marchdz.kt" new file mode 100644 index 0000000000..d3a896b47e --- /dev/null +++ "b/Retos/Reto #24 - CIFRADO C\303\211SAR [F\303\241cil]/kotlin/marchdz.kt" @@ -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") +} \ No newline at end of file