Метод шифрования Била для шифрования файла со значением ключа - PullRequest
1 голос
/ 29 марта 2020

Я надеюсь получить от вас помощь в решении проблемы, связанной со следующим методом. Проблема в следующем:

Bound must be positive.

Я думаю, проблема в том, что plaintextArray[] остается неизменным и не заполняет массив значениями, поэтому в случайном порядке, когда я выбираю случайное число, int index1 = rand.nextInt((tempArray.length - 1)); дает мне отрицательное число.

ps Два метода в методе:

  1. обычный текст ("Pershendetje")
  2. textBook это файл с содержимым the quick brown fox jumps over the lazy dog
      import java.util.Random;

    public class Enkriptimi {
        public final String Encrypt(String plaintext, String textBook) {
            textBook = textBook.toLowerCase();
            plaintext = plaintext.toLowerCase();

            String[] textDocument = textBook.split(" ");
            char[] plaintextArray = plaintext.toCharArray();
            String ciphertexti = "";
            String ciphertexti1 = "";
            Random rand = new Random();
            for (int i = 0; (i < plaintext.length()); i++) {
                String tempciphertexti = "";
                if (plaintext.charAt(i) == ' ') {

                }
                for (int j = 0; (j < textDocument.length); j++) {
                    String word = textDocument[j];
                    if (word.startsWith(Character.toString(plaintextArray[i]))){

                        tempciphertexti += j + 1 + " ";
                    }
                }
                String[] tempArray = tempciphertexti.split(" ");
                int index1 = rand.nextInt((tempArray.length - 1)); //0 - 1 = -1 qata
                ciphertexti1 = (ciphertexti1
                        + (tempArray[index1].toString() + ", "));
                ciphertexti = ciphertexti1.substring(0, (ciphertexti1.length() - 2));
            }
            return ciphertexti;
        }
    }

Основной метод

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.*;
public class testmain {

    public static void main(String[] args)throws IOException {

        String lineReturnPlainText = "";
        FileReader fr = new FileReader(new File("text.txt"));
        BufferedReader br = new BufferedReader(fr);
        String line = "";
        while ((line = br.readLine()) != null) {
            lineReturnPlainText += line;
        } 
        Enkriptimi e = new Enkriptimi();
        String returnMessage = e.Encrypt("Pershendetje",lineReturnPlainText);


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