* Reto #50 * LA ENCRIPTACIÓN DE KARACA * Fecha publicación enunciado: 12/11/22 * Fecha publicación resolución: 19/12/22 * Dificultad: FÁCIL * * Enunciado: Crea una función que sea capaz de encriptar y desencriptar texto utilizando el * algoritmo de encriptación de Karaca (debes buscar información sobre él). val numbersMap = mapOf("a" to 0, "e" to 1, "i" to 2, "o" to 3, "u" to 4) fun main() { println(encrypt("apple")) println(decrypt(encrypt("apple"))) } fun encrypt(word:String):String{ val reversedWord = word.reversed() var encryptedWord:String = "" reversedWord.forEachIndexed{ i, it -> encryptedWord += if(numbersMap.contains(it.toString())) numbersMap[it.toString()] else reversedWord[i] } return encryptedWord + "aca" } fun decrypt(word:String):String{ val encriptedWord = word.removeRange(word.length-3, word.length) val reversedWord = encriptedWord.reversed() var decryptedWord:String = "" reversedWord.forEachIndexed{ i, letter -> decryptedWord += if(numbersMap.containsValue(Character.getNumericValue(letter))) numbersMap.entries.find { it.value == Character.getNumericValue(letter)}?.key else reversedWord[i] } return decryptedWord }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter