Created
July 15, 2020 22:55
-
-
Save parzibyte/adec9f894561a843e05505611ef74aea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String codificarMorse(String original) { | |
StringBuilder codificado = new StringBuilder(); | |
for (int i = 0; i < original.length(); i++) { | |
String charComoCadenaYEnMayusculas = String.valueOf(original.charAt(i)).toUpperCase(); | |
String equivalencia = asciiAMorse(charComoCadenaYEnMayusculas); | |
codificado | |
.append(equivalencia) | |
.append(" "); | |
} | |
return codificado.toString(); | |
} | |
public static String decodificarMorse(String codificado) { | |
StringBuilder decodificado = new StringBuilder(); | |
// Necesitamos separarlo por espacios | |
String[] morse = codificado.split(" "); | |
for (String morseActual : morse) { | |
String equivalencia = morseAAscii(morseActual); | |
decodificado.append(equivalencia); | |
} | |
return decodificado.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment