Java-код Additive Cipher, алфавит, пробел, точка - PullRequest
0 голосов
/ 23 сентября 2019

У меня есть код Additive Cipher, который шифрует алфавит, я хочу зашифровать точку и пробел, я не знаю, что с ним не так

static int a[] = new int[28];
static char c[] = new char[]{'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', ' ','.'};
//static char c[] = new char[28];
static String str1 = "", s = "";

public static void main(String[] args) throws IOException {
    for (int i = 0; i < 28; i++) {
        a[i] = i;
    }
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);
    System.out.println("ENTER PLAINTEXT: ");
    s = br.readLine();
    System.out.println("ENTER KEY VALUE: ");
    int k = Integer.parseInt(br.readLine());
    for (int i = 0; i < s.length(); i++) {
        int j;
        if (s.charAt(i) == ' ') {
            i++;
            str1 = str1.concat(" ");
        }

        for (j = 0; j < 28; j++) {
            if (s.charAt(i) == c[j]) {
                break;
            }
        }
        j = (a[j] + k) % 28;
        str1 = str1.concat(c[j] + "");
    }
    System.out.println("AFTER ENCRYPTION: ");
    System.out.println(str1);
    s = "";
    for (int i = 0; i < str1.length(); i++) {
        int j;
        if (str1.charAt(i) == ' ') {
            i++;
            s = s.concat(" ");
        }
        for (j = 0; j < 28; j++) {
            if (str1.charAt(i) == c[j]) {
                break;
            }
        }
        j = (a[j] - k) % 28;
        if (j < 0) {
            j = 26 + j;
        }
        s = s.concat(c[j] + "");
    }
    System.out.println("AFTER DECRYPTION: ");
    System.out.println(s);

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...