try { CH_m = new BigInteger(Chinese_m.getText()); CH_n = new BigInteger(Chinese_n.getText()); CH_a = new BigInteger(Chinese_a.getText()); CH_b = new BigInteger(Chinese_b.getText()); } catch(Exception ex){ if(Chinese_m.getText().isEmpty() || Chinese_n.getText().isEmpty() || Chinese_a.getText().isEmpty() || Chinese_b.getText().isEmpty()){ JOptionPane.showMessageDialog(Chinese_m, "Please fill form complete"); } else { JOptionPane.showMessageDialog(Chinese_m, "Please type number ONLY!"); //pop up a message if the user type anything expect number } } CH_d = CH_n.modInverse(CH_m); //inverse n modulo n display.setText(CH_d.toString()); CH_ab = CH_a.subtract(CH_b); //a-b CH_k = (CH_ab.multiply(CH_d)).mod(CH_m); //k=(a-b)i(mod m) CH_ans_x = CH_b.add((CH_n.multiply(CH_k))); //x=b+nk Chinese_k.setText(Chinese_k.getText()+"k: "+CH_k); Chinese_Ans_x.setText(Chinese_Ans_x.getText()+"x: "+CH_ans_x); display.setText(display.getText()+"\ninverse: "+CH_n+" modulo "+CH_m+" is "+CH_d); //d = s+t display.setText(display.getText()+"\n"); //NEXT LINE display.setText(display.getText()+"K =(a-b)i(mod m)"); display.setText(display.getText()+"\n"); //NEXT LINE display.setText(display.getText()+"Substitute i = "+CH_d); display.setText(display.getText()+"\n"); //NEXT LINE display.setText(display.getText()+"K = ("+CH_a+" - "+CH_b+") "+CH_d+" (mod "+CH_m+")"); //output ans of inverse n modulo n display.setText(display.getText()+"\n"); //NEXT LINE display.setText(display.getText()+"K = "+CH_k); //output of k=(a-b)i(mod m) display.setText(display.getText()+"\n"); //NEXT LINE display.setText(display.getText()+"x= b + nk"); display.setText(display.getText()+"\n"); //NEXT LINE display.setText(display.getText()+"Substitute k = "+CH_k); //output ans k display.setText(display.getText()+"\n"); //NEXT LINE display.setText(display.getText()+"x = "+CH_b+" + ("+CH_n+")("+CH_k+")"); //output of x=b+nk display.setText(display.getText()+"\n"); //NEXT LINE display.setText(display.getText()+"x = "+CH_ans_x+"\n"); //output ans x /* if (value1.compareTo(value2)== a)//a is either 0, 1 or -1 * ==0 value1 equal to value2 * ==1 value1 more than value2 * ==-1 value1 less than value2 */ if (CH_ans_x.mod(CH_m).compareTo(CH_a.mod(CH_m)) == 0 ) { display.setText(display.getText()+CH_ans_x+" ≡ "+CH_a+"(mod "+CH_m+")"); display.setText(display.getText()+" [True]"); } else{ display.setText(display.getText()+CH_ans_x+" ≡ "+CH_a+"(mod "+CH_m+")"); display.setText(display.getText()+" [False]"); } if (CH_ans_x.mod(CH_n).compareTo(CH_b.mod(CH_n)) == 0) { display.setText(display.getText()+"\n"+CH_ans_x+" ≡ "+CH_b+"(mod "+CH_n+")"); display.setText(display.getText()+" [True]"); } else{ display.setText(display.getText()+"\n"+CH_ans_x+" ≡ "+CH_b+"(mod "+CH_n+")"); display.setText(display.getText()+" [False]"); }
how come when i type a=2,b=2,m=2,n=2. the output did not come out.