コード例 #1
0
ファイル: Encrypt.java プロジェクト: IMdmp/HillCypherProgram
  public String processWord(Matrix key, int keySize) {
    String encrypted = "";
    int[][] handle = new int[keySize][1];
    for (int row = 0; row < keySize; row++) {
      handle[row][0] = 0;
    }
    //        for(int i=0;i<keySize;i++)
    //            System.out.println(toEncrypt.size());
    for (Matrix vector : toEncrypt) {
      for (int row = 0; row < keySize; row++) {
        for (int column = 0; column < keySize; column++) {
          handle[row][0] =
              handle[row][0] + (key.getData()[row][column] * vector.getData()[column][0]);
        }
        if (handle[row][0] > 25) {
          handle[row][0] = handle[row][0] % 26;
        }
        encrypted = encrypted + ((char) (handle[row][0] + 97));
      }
      vector.setData(handle);
      for (int row = 0; row < keySize; row++) {
        handle[row][0] = 0;
      }
    }

    System.out.println("Encrypted text: " + encrypted);

    return encrypted;
  }
コード例 #2
0
ファイル: Encrypt.java プロジェクト: IMdmp/HillCypherProgram
 public boolean isKeyUsable(Matrix key, int keySize) {
   int determinant = getDeterminant(key.getData(), keySize);
   int alphabetSize = 26, t;
   if (determinant != 0) {
     while (alphabetSize != 0) {
       t = determinant;
       determinant = alphabetSize;
       alphabetSize = t % alphabetSize;
     }
     if (determinant == 1) return true;
     else return false;
   } else return false;
 }