Advertisement
PomozMi

POD ADFGVX

Oct 22nd, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.74 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Random;
  4. import java.util.Scanner;
  5. import java.util.concurrent.ThreadLocalRandom;
  6.  
  7.  
  8. public class main {
  9.     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" };
  10.     private static final Map<Integer,String> tableHeader;
  11.     private static String encryptedText;
  12.     static {
  13.         tableHeader = new HashMap<Integer,String>();
  14.         tableHeader.put(1,"AA");
  15.         tableHeader.put(2,"DA");
  16.         tableHeader.put(3,"FA");
  17.         tableHeader.put(4,"GA");
  18.         tableHeader.put(5,"VA");
  19.         tableHeader.put(6,"XA");
  20.         tableHeader.put(7,"AD");
  21.         tableHeader.put(8,"DD");
  22.         tableHeader.put(9,"FD");
  23.         tableHeader.put(10,"GD");
  24.         tableHeader.put(11,"VD");
  25.         tableHeader.put(12,"XD");
  26.         tableHeader.put(13,"AF");
  27.         tableHeader.put(14,"DF");
  28.         tableHeader.put(15,"FF");
  29.         tableHeader.put(16,"GF");
  30.         tableHeader.put(17,"VF");
  31.         tableHeader.put(18,"XF");
  32.         tableHeader.put(19,"AG");
  33.         tableHeader.put(20,"DG");
  34.         tableHeader.put(21,"FG");
  35.         tableHeader.put(22,"GG");
  36.         tableHeader.put(23,"VG");
  37.         tableHeader.put(24,"XG");
  38.         tableHeader.put(25,"AV");
  39.         tableHeader.put(26,"DV");
  40.         tableHeader.put(27,"FV");
  41.         tableHeader.put(28,"GV");
  42.         tableHeader.put(29,"VV");
  43.         tableHeader.put(30,"XV");
  44.         tableHeader.put(31,"AX");
  45.         tableHeader.put(32,"DX");
  46.         tableHeader.put(33,"FX");
  47.         tableHeader.put(34,"GX");
  48.         tableHeader.put(35,"VX");
  49.         tableHeader.put(36,"XX");
  50.         //////////////////////////
  51.     }
  52.  
  53.     public static void main(String[] args) {
  54.  
  55.         Scanner scanner = new Scanner(System.in);
  56.  
  57.         shuffleArray(array);
  58.         print6x6Array(array);
  59.  
  60.  
  61.         System.out.println("Podaj tekst do zaszyfrowania ");
  62.         String text  = scanner.nextLine();
  63.         text = text.toLowerCase();
  64.  
  65.         String result = text.replaceAll("[^A-Za-z0-9]", "");
  66.         text = result;
  67.         System.out.println(text);
  68.  
  69.         encryptedText = "";
  70.  
  71.         final int len = text.length();
  72.         for (int i = 0; i < len; i++) {
  73.  
  74.             Integer index = -1; // -1   = false
  75.  
  76.             System.out.print(text.charAt(i));
  77.  
  78.             Character a, b;
  79.             for (int j = 1; j < array.length; j++) {
  80.  
  81.                 a = array[j].charAt(0);
  82.                 b = text.charAt(i);
  83.                 if(a.equals(b)) {
  84.                     index = j;
  85.                     encryptedText += tableHeader.get(j+1)+ " ";
  86.                     System.out.print(" " + tableHeader.get(j+1));
  87.  
  88.                 }
  89.             }
  90.             System.out.println("");
  91.         }
  92.  
  93.         System.out.print(encryptedText);
  94.  
  95.     }
  96.  
  97.         static  void print6x6Array(String[] ar){
  98.         Integer z = 0;
  99.  
  100.         for (int i = 0; i < 6; i++) {
  101.             for (int j = 0; j < 6; j++) {
  102.                try {
  103.                    System.out.print("[ " + ar[z] + " ] ");
  104.                }catch (Exception e){e.toString();}
  105.                 z++;
  106.             }
  107.             System.out.println("");
  108.         }
  109.             System.out.println("");
  110.     }
  111.         // Implementing Fisher–Yates shuffle
  112.         static void shuffleArray(String[] ar){
  113.             // If running on Java 6 or older, use `new Random()` on RHS here
  114.             Random rnd = ThreadLocalRandom.current();
  115.             for (int i = ar.length - 1; i > 0; i--) {
  116.                 int index = rnd.nextInt(i + 1);
  117.                 // Simple swap
  118.                 String a = ar[index];
  119.                 ar[index] = ar[i];
  120.                 ar[i] = a;
  121.             }
  122.         }
  123. }
  124.  
  125.  
  126. // //to dziala a ie wiem dlaczego nie zamienia tego co podam z konsoli :o
  127. //        String aaa = "â";
  128. //        String bbb = aaa.replace("â", "a");
  129. //        System.out.println(bbb);
  130. //text = scanner.
  131. //        //text = text.toString();
  132. //
  133. //        BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
  134. //        try {
  135. //            text = bufferRead.readLine();
  136. //        } catch (IOException e) {
  137. //            e.printStackTrace();
  138. //        }
  139. //
  140. //
  141. //        System.out.println(text);
  142. //        aaa = text;
  143. //        String xxx = aaa.replace("â", "a");
  144. //        System.out.println(xxx);
  145. //
  146. //        result = text.replaceAll("ą", "a");
  147. //        text = result;
  148. //
  149. //        result = text.replace("\341\342\343\344\345", "a");
  150. //        text = result;
  151. //        result = text.replace("ć", "c");
  152. //        text = result;
  153. //        result = text.replace("ę", "e");
  154. //        text = result;
  155. //        result = text.replace("ó", "o");
  156. //        text = result;
  157. //        result = text.replace("ź", "z");
  158. //        text = result;
  159. //        result = text.replace("ż", "z");
  160. //        text = result;
  161. //        result = text.replace("ń", "n");
  162. //        text = result;
  163. //        result = text.replaceAll("á", "a");
  164. //        text = result;
  165. //        result = text.replaceAll("â", "a");
  166. //        text = result;
  167. //        result = text.replaceAll("ą", "a");
  168. //        text = result;
  169. //        result = text.replaceAll("ä", "a");
  170. //        text = result;
  171. //        result = text.replaceAll("ë", "e");
  172. //        text = result;
  173. //        result = text.replaceAll("É", "e");
  174. //        text = result;
  175. //        result = text.replaceAll("ö", "o");
  176. //        text = result;
  177. //        result = text.replaceAll("ô", "o");
  178. //        text = result;
  179. //        result = text.replaceAll("ł", "l");
  180. //        text = result;
  181. //        System.out.println(text);
  182. ////        System.out.println(text);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement