Лабораторная работа №3 / docs / lab3-REPORT
.doc.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(23, Short.MAX_VALUE)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
.add(jButtonExchange, 0, 0, Short.MAX_VALUE)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jButtonGen, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.add(jButtonGen)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButtonExchange)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton3)
.addContainerGap())
);
jSplitPane1.setRightComponent(jPanel2);
jMenu1.setText("\u0424\u0430\u0439\u043b");
jMenu1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu1ActionPerformed(evt);
}
});
jMenuItem1.setText("\u0412\u044b\u0445\u043e\u0434");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("\u041f\u043e\u043c\u043e\u0449\u044c");
jMenuItem3.setText("\u041e\u0431 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem3);
jMenuItem2.setText("\u041e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
jDialog1.setVisible(false);
}//GEN-LAST:event_jButton1ActionPerformed
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
// TODO add your handling code here:
//this.add(jDialog1.setParentComponent(this);
jDialog1.setSize(400,500);
jDialog1.setVisible(true);
}//GEN-LAST:event_jMenuItem3ActionPerformed
private void jButtonExchangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExchangeActionPerformed
// TODO add your handling code here:
jButtonGenActionPerformed(evt);
}//GEN-LAST:event_jButtonExchangeActionPerformed
private void jButtonGenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGenActionPerformed
// TODO add your handling code here:
switch (count ) {
case 0:
count ++;
clear();
genSrc();
jButtonExchange.setEnabled(true);
jButtonGen.setEnabled(false);
addToLog("p: "+ip);
addToLog("q: "+iq);
addToLog("secret 1: "+is1);
addToLog("secret 2: "+is2);
break;
case 1:
addToLog("----EXCHANGE-- ");
addToLog("Y1="+y1);
addToLog("Y2="+y2);
ts = jButtonExchange.getText();
jButtonExchange.setText("GET KEYS");
count ++;
genY();
break;
case 2:
count =0;
genSecret();
addToLog("----Gen secret keys-- ");
addToLog("KEY-1="+key);
addToLog("KEY-2="+key2);
addToLog("----FINISH-- ");
JOptionPane.showMessageDialog(this,
"Obmen zavershen!", "Exchange complete",
JOptionPane.PLAIN_MESSAGE);
jButtonExchange.setEnabled(false);
jButtonGen.setEnabled(true);
jButtonExchange.setText(ts);
break;
default:
count = 0;
jButtonExchange.setEnabled(false);
jButtonGen.setEnabled(true);
clear();
}
}//GEN-LAST:event_jButtonGenActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
jMenuItem2ActionPerformed(evt);
}//GEN-LAST:event_jButton3ActionPerformed
private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jMenu1ActionPerformed
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
// TODO add your handling code here:
JOptionPane.showMessageDialog(this,
"Lab 3 in SZI\n\rFilippov K.\n\rMwenge Mulenga\n\rBubba",
"O programme:", JOptionPane.PLAIN_MESSAGE);
}//GEN-LAST:event_jMenuItem2ActionPerformed
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_jMenuItem1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
//Mclass.main(args);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DiffieHellmanW().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButtonExchange;
private javax.swing.JButton jButtonGen;
private javax.swing.JDialog jDialog1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextFieldKey1;
private javax.swing.JTextField jTextFieldKey2;
private javax.swing.JTextField jTextFieldP1;
private javax.swing.JTextField jTextFieldP2;
private javax.swing.JTextField jTextFieldQ1;
private javax.swing.JTextField jTextFieldQ2;
private javax.swing.JTextField jTextFieldS1;
private javax.swing.JTextField jTextFieldS2;
private javax.swing.JTextField jTextFieldY11;
private javax.swing.JTextField jTextFieldY12;
private javax.swing.JTextField jTextFieldY21;
private javax.swing.JTextField jTextFieldY22;
private javax.swing.JTextPane jTextPaneLog;
// End of variables declaration//GEN-END:variables
}
// Класс для проверки на простоту числа
public class Primes {
private int start; // no default
public int count = 20; // default value
Primes(int sta) { // constructor with one arg
start = sta;
}
public boolean isPrime(int p) {
int i;
for(i=2;i<(p/2);i++) {
if ( i*(p/i) == p ) return(false);
}
return(true);
}
public void Generate(int arr[]) { // make primes
int sta = start;
int cnt = count;
int idx = 0;
while ( cnt > 0 ) {
if ( isPrime(sta) ) {
arr[idx++] = sta;
cnt--;
}
sta++;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Возведение в степень по модулю
//
////////////////////////////////////////////////////////////////////////////////////////////////////
public class U {
/** Creates a new instance of U */
public U() {
}
/**
*
* return a ^ x mod n
*
*/
public static void log(String s) {
System.out.println(s);
}
public static long modexp( long a, long x, long n) {
long r;
r = 1;
while ( x > 0 )
{
if ( (x % 2) == 1 )
{
r = (r * a) % n ;
}
a = ( a * a ) % n ;
x /= 2;
}
return r ;
}
}