示例#1
0
  /** Calculate the residue and the jacobi number * */
  void calculateResidueAndJacobi() {
    try {
      BigInteger n = new BigInteger(nField.getText());
      BigInteger x = new BigInteger(xField.getText());

      x2Label.setText(calc.squareMod(x, n).toString());

      resultLabel.setText("" + calc.jacobi(x, n));
    } catch (NumberFormatException e) {
      clearResidueAndJacobi();
    }
  }
示例#2
0
  /** Listen for Button events. * */
  public void actionPerformed(ActionEvent event) {
    // Make a new n - set p, q, n, and labels.
    if (event.getSource() == makeN) {
      try {
        KEYLENGTH = Integer.parseInt(kField.getText());
      } catch (NumberFormatException e) {
        KEYLENGTH = DEFAULT_KEYLENGTH;
        kField.setText(Integer.toString(KEYLENGTH));
      }
      p = calc.makeBlumInt(KEYLENGTH);
      q = calc.makeBlumInt(KEYLENGTH);
      n = p.multiply(q);

      pLabel.setText("    p = " + p);
      qLabel.setText("    q = " + q);

      nField.removeCaretListener(this);
      nField.setText(n.toString());
      nField.addCaretListener(this);

      xField.setText("");
      clearResidueAndJacobi();
    } else if (event.getSource() == xField || event.getSource() == nField)
      calculateResidueAndJacobi();
  }