Skip to content

Instantly share code, notes, and snippets.

@OpaKnoppi
Created June 6, 2017 20:53
Show Gist options
  • Save OpaKnoppi/e222fead5bf2c3ff58f82592b12d801a to your computer and use it in GitHub Desktop.
Save OpaKnoppi/e222fead5bf2c3ff58f82592b12d801a to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package morcode;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author B201
*/
class KnopperscheMorsierung {
public static String vermorsen(String input){
String output = "";
//Textformatierung
output = input;
output = output.toLowerCase();
output = output.replaceAll("ä", "ae");
output = output.replaceAll("ö", "oe");
output = output.replaceAll("ü", "ue");
output = output.replaceAll("\\.", "STOP");
//Texttransformierung
output = output.replaceAll("a", " .- ");
output = output.replaceAll("b", " -... ");
output = output.replaceAll("c", " -.-. ");
output = output.replaceAll("d", " -.. ");
output = output.replaceAll("e", " . ");
output = output.replaceAll("f", " ..-. ");
output = output.replaceAll("g", " --. ");
output = output.replaceAll("h", " .... ");
output = output.replaceAll("i", " .. ");
output = output.replaceAll("j", " .--- ");
output = output.replaceAll("k", " -.- ");
output = output.replaceAll("l", " .-.. ");
output = output.replaceAll("m", " -- ");
output = output.replaceAll("n", " -. ");
output = output.replaceAll("o", " --- ");
output = output.replaceAll("p", " .--. ");
output = output.replaceAll("q", " --.- ");
output = output.replaceAll("r", " .-. ");
output = output.replaceAll("s", " ... ");
output = output.replaceAll("t", " - ");
output = output.replaceAll("u", " ..- ");
output = output.replaceAll("v", " ...- ");
output = output.replaceAll("w", " .-- ");
output = output.replaceAll("x", " -..- ");
output = output.replaceAll("y", " -.-- ");
output = output.replaceAll("z", " --.. ");
output = output.replaceAll("0", " .---- ");
output = output.replaceAll("1", " ..--- ");
output = output.replaceAll("2", " ...-- ");
output = output.replaceAll("3", " ....- ");
output = output.replaceAll("4", " ..... ");
output = output.replaceAll("5", " -.... ");
output = output.replaceAll("6", " --... ");
output = output.replaceAll("7", " ---.. ");
output = output.replaceAll("8", " ----. ");
output = output.replaceAll("9", " ----- ");
return output;
}
public static String entmorsen(String input){
String output = "";
output = input;
output = output.replaceAll(".-", "a");
output = output.replaceAll("-...", "b");
output = output.replaceAll("-.-.", "c");
output = output.replaceAll("-..", "d");
output = output.replaceAll(".", "e");
output = output.replaceAll("..-.", "f");
output = output.replaceAll("--.", "g");
output = output.replaceAll("....", "h");
output = output.replaceAll("..", "i");
output = output.replaceAll(".---", "j");
output = output.replaceAll("-.-", "k");
output = output.replaceAll(".-..", "l");
output = output.replaceAll("--", "m");
output = output.replaceAll("-.", "n");
output = output.replaceAll("---", "o");
output = output.replaceAll(".--.", "p");
output = output.replaceAll("--.-", "q");
output = output.replaceAll(".-.", "r");
output = output.replaceAll("...", "s");
output = output.replaceAll("-", "t");
output = output.replaceAll("..-", "u");
output = output.replaceAll("...-", "v");
output = output.replaceAll(".--", "w");
output = output.replaceAll("-..-", "x");
output = output.replaceAll("-.--", "y");
output = output.replaceAll("--..", "z");
return output;
}
public static ArrayList<String> einlesen(String dateiname) {
ArrayList<String> e = new ArrayList<>();
File f = new File(dateiname);
Scanner s = null;
try {
s = new Scanner(f);
} catch (FileNotFoundException ex) {
System.err.println("Scanner spinnt!");
}
while (s.hasNext()) {
e.add(s.nextLine());
}
return e;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package morcode;
import java.util.ArrayList;
/**
*
* @author B201
*/
public class Morcode {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ArrayList<String> lists = KnopperscheMorsierung.einlesen("NeuronaleNetze.txt");
for(int i = 0;i<lists.size();i++){
System.err.println(KnopperscheMorsierung.vermorsen(lists.get(i)));
}
System.out.println(KnopperscheMorsierung.entmorsen(" --.. -.. -. . - / .. -. -. --- ...- .- - .. --- -. "));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment