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