Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Random;
- import java.util.Scanner;
- import java.util.concurrent.ThreadLocalRandom;
- public class main {
- private static String [] array = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0" };
- private static final Map<Integer,String> tableHeader;
- private static String encryptedText;
- static {
- tableHeader = new HashMap<Integer,String>();
- tableHeader.put(1,"AA");
- tableHeader.put(2,"DA");
- tableHeader.put(3,"FA");
- tableHeader.put(4,"GA");
- tableHeader.put(5,"VA");
- tableHeader.put(6,"XA");
- tableHeader.put(7,"AD");
- tableHeader.put(8,"DD");
- tableHeader.put(9,"FD");
- tableHeader.put(10,"GD");
- tableHeader.put(11,"VD");
- tableHeader.put(12,"XD");
- tableHeader.put(13,"AF");
- tableHeader.put(14,"DF");
- tableHeader.put(15,"FF");
- tableHeader.put(16,"GF");
- tableHeader.put(17,"VF");
- tableHeader.put(18,"XF");
- tableHeader.put(19,"AG");
- tableHeader.put(20,"DG");
- tableHeader.put(21,"FG");
- tableHeader.put(22,"GG");
- tableHeader.put(23,"VG");
- tableHeader.put(24,"XG");
- tableHeader.put(25,"AV");
- tableHeader.put(26,"DV");
- tableHeader.put(27,"FV");
- tableHeader.put(28,"GV");
- tableHeader.put(29,"VV");
- tableHeader.put(30,"XV");
- tableHeader.put(31,"AX");
- tableHeader.put(32,"DX");
- tableHeader.put(33,"FX");
- tableHeader.put(34,"GX");
- tableHeader.put(35,"VX");
- tableHeader.put(36,"XX");
- //////////////////////////
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- shuffleArray(array);
- print6x6Array(array);
- System.out.println("Podaj tekst do zaszyfrowania ");
- String text = scanner.nextLine();
- text = text.toLowerCase();
- String result = text.replaceAll("[^A-Za-z0-9]", "");
- text = result;
- System.out.println(text);
- encryptedText = "";
- final int len = text.length();
- for (int i = 0; i < len; i++) {
- Integer index = -1; // -1 = false
- System.out.print(text.charAt(i));
- Character a, b;
- for (int j = 1; j < array.length; j++) {
- a = array[j].charAt(0);
- b = text.charAt(i);
- if(a.equals(b)) {
- index = j;
- encryptedText += tableHeader.get(j+1)+ " ";
- System.out.print(" " + tableHeader.get(j+1));
- }
- }
- System.out.println("");
- }
- System.out.print(encryptedText);
- }
- static void print6x6Array(String[] ar){
- Integer z = 0;
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 6; j++) {
- try {
- System.out.print("[ " + ar[z] + " ] ");
- }catch (Exception e){e.toString();}
- z++;
- }
- System.out.println("");
- }
- System.out.println("");
- }
- // Implementing Fisher–Yates shuffle
- static void shuffleArray(String[] ar){
- // If running on Java 6 or older, use `new Random()` on RHS here
- Random rnd = ThreadLocalRandom.current();
- for (int i = ar.length - 1; i > 0; i--) {
- int index = rnd.nextInt(i + 1);
- // Simple swap
- String a = ar[index];
- ar[index] = ar[i];
- ar[i] = a;
- }
- }
- }
- // //to dziala a ie wiem dlaczego nie zamienia tego co podam z konsoli :o
- // String aaa = "â";
- // String bbb = aaa.replace("â", "a");
- // System.out.println(bbb);
- //text = scanner.
- // //text = text.toString();
- //
- // BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
- // try {
- // text = bufferRead.readLine();
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
- //
- //
- // System.out.println(text);
- // aaa = text;
- // String xxx = aaa.replace("â", "a");
- // System.out.println(xxx);
- //
- // result = text.replaceAll("ą", "a");
- // text = result;
- //
- // result = text.replace("\341\342\343\344\345", "a");
- // text = result;
- // result = text.replace("ć", "c");
- // text = result;
- // result = text.replace("ę", "e");
- // text = result;
- // result = text.replace("ó", "o");
- // text = result;
- // result = text.replace("ź", "z");
- // text = result;
- // result = text.replace("ż", "z");
- // text = result;
- // result = text.replace("ń", "n");
- // text = result;
- // result = text.replaceAll("á", "a");
- // text = result;
- // result = text.replaceAll("â", "a");
- // text = result;
- // result = text.replaceAll("ą", "a");
- // text = result;
- // result = text.replaceAll("ä", "a");
- // text = result;
- // result = text.replaceAll("ë", "e");
- // text = result;
- // result = text.replaceAll("É", "e");
- // text = result;
- // result = text.replaceAll("ö", "o");
- // text = result;
- // result = text.replaceAll("ô", "o");
- // text = result;
- // result = text.replaceAll("ł", "l");
- // text = result;
- // System.out.println(text);
- //// System.out.println(text);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement