/** * @author * @version */ public abstract class kodiereBuchst { public static char kodiereBuchst(char x, int i){ if ( ((int) x >= 97 && (int) x <= 122)|| ((int) x >= 'A' && (int) x <= 'Z') ){ if (((int) x + i <= 122) || ((int) x + i <= 'Z')){ return x= (char) ((int)x + i); }else{ return x = (char) ((int)x-(26-i)); } }else{ if( (int)x == (int) 32){ return (int) 32; } return 0; } } public static String kodiereString(String str, int schluessel) { char[]strArray = str.toCharArray(); for(int i= 0; i < str.length(); i++){ strArray[i] = kodiereBuchst(strArray[i], schluessel); } return new String (strArray); } // public static void attackVer(String str) // { // //int ergebnis = 0; // String alphabet = new String("abcdefghijklmnopqrstuvwxyz"); // char[]alpha = alphabet.toCharArray(); // char[]eingabe = str.toCharArray(); // for (int j=0; j <26; j++){ // int anzahl=0; // for (int i= 0; i < str.length(); i++) // { // if (alpha[j] == str.charAt(i)){ // anzahl = anzahl +1; // // } // } // // int[]haeufig = new int[26]; // for(int k =0; k <26; k++){ // haeufig[k] = anzahl; // }System.out.println (haeufig[1]); // // //System.out.println(alpha[j]+"="+ anzahl); // } // // } public static void attackVer(String str) { String alphabet = new String("abcdefghijklmnopqrstuvwxyz"); char[]alpha = alphabet.toCharArray(); char[]eingabe = str.toCharArray(); for (int j=0; j <26; j++){ int anzahl=0; for (int i= 0; i < str.length(); i++) { if (alpha[j] == str.charAt(i)){ anzahl = anzahl +1; } } anzahlDerBuchstaben[j] = anzahl; } double[] haeufigkeit =new double[26]; for(int k =0; k < 26; k++){ haeufigkeit[k]=anzahlDerBuchstaben[k]/str.length(); } System.out.println(anzahlDerBuchstaben[1]); } static int[] anzahlDerBuchstaben = new int[26]; }