Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication3;
- /**
- *
- * @author dita
- */
- public class JavaApplication3 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- java.util.Scanner s = new java.util.Scanner(System.in);
- String code = "TZTAWUXWAAMENWWDMGKT"
- + "QHRCJTKQVEILTMQPRLEQ"
- + "ZUYHALQLMGZWPQVHSREJ"
- + "ZVRIWMUQRRUKKEZAVRAM";
- code = code.toLowerCase();
- //char[] charcode = code.toCharArray();
- String key2 = "rokcjvbndwexmpaslhyftgzqiu";
- String key1 = "rykqcpmxfsaltnzbeodujhviwg";
- //int rotation;
- String result;
- /*
- for (rotation = 0; rotation < 26; rotation++) {
- result = code;
- int shift = 0;
- for (char ch : charcode) {
- result = result.replace(ch, (char) (key2.charAt((key1.indexOf(ch) + rotation + shift) % 26) - 32));
- shift++;
- }
- System.out.println(result);
- }
- System.out.println(" ");
- for (rotation = 0; rotation < 26; rotation++) {
- result = code;
- for (char ch : charcode) {
- result = result.replace(ch, (char) (key1.charAt((key2.indexOf(ch) + rotation + shift) % 26) - 32));
- }
- System.out.println(result);
- }*/
- /*
- result = code;
- int i; // kde jsme ve vstupu
- int rotation; //aktualni pootoceni
- int rotationBase;
- //int oKolik = 2; //o kolik
- int jakCasto; //jak casto
- for (rotationBase = 0; rotationBase < 26; rotationBase++) {
- for (jakCasto = 1; jakCasto < result.length(); jakCasto++) {
- i = 0;
- rotation = rotationBase;
- int XQWcount = 0;
- for (char ch : result.toCharArray()) {
- if (i % jakCasto == 0 && i != 0) {
- rotation = (rotation + oKolik) % result.length();
- }
- char goal = (char) (key2.charAt((key1.indexOf(ch) + rotation) % 26) - 32);
- if (goal == (char) 'W' || goal == (char) 'Q' || goal == (char) 'X' || goal == (char) 'G') {
- XQWcount++;
- }
- result = result.replace(ch, goal);
- i++;
- }
- /*
- System.out.print(XQWcount);
- if(XQWcount < 5){
- System.out.println(result);
- }
- System.out.println(result);
- result = code;
- }
- }*/
- System.out.println("Zadejte heslo: ");
- String key = s.nextLine().toLowerCase();
- while (!key.equals("0")) {
- int i = 0;
- for (char ch : code.toCharArray()) {
- //System.out.println("Hledame hodnotu " + ch + " s klicovou abecedou " + key.charAt(i%key.length()) + ", vysledek je " +decode(key.charAt(i%key.length()), ch) );
- System.out.print(decode(key.charAt(i % key.length()), ch));
- i++;
- }
- System.out.println();
- System.out.println("Zadejte heslo: ");
- key = s.nextLine().toLowerCase();
- /*for (int j = 0; j < 4; j++) {
- for(int k = 0; k < 26; k++){
- }
- }*/
- }
- }
- public static char decode(char keyChar, char codeChar) {
- String key1 = "rykqcpmxfsaltnzbeodujhviwg";
- String key2 = "aslhyftgzqiurokcjvbndwexmp";
- char goal;
- int rotate = key2.indexOf(keyChar);
- int b = key1.indexOf(codeChar);
- goal = key2.charAt((b + rotate) % 26);
- /*
- int shift = key1.lastIndexOf(keyChar);
- int index = key2.lastIndexOf(codeChar);
- //char tmp = key2.charAt(index + 26 - shift) % 26;
- //System.out.println("Shift: " + shift + ", index: " + index + ", tmp: " );
- char goal = (char) (key2.charAt((key1.indexOf(codeChar) + 26 - shift) % 26) - 32);*/
- return goal;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement