Частина тексту файла (без зображень, графіків і формул):
Міністерство освіти і науки України
ІФНТУНГ
Кафедра КСМ
Лабораторна робота №7
ДОСЛІДЖЕННЯ ЕЛЕКТРОННОГО ЦИФРОВОГО ПІДПИСУ (ЕЦП) RSA
2011 р.
Мета роботи: дослідження структури алгоритму і методики практичної реалізації (ЕЦП) RSA.
ПОРЯДОК ВИКОНАННЯ РОБОТИ
Код програми:
package lab_ziks;
import java.math.BigInteger;
import java.util.Random;
import javax.swing.JOptionPane;
/**
*/
public class MainFrame extends javax.swing.JFrame {
private int p;
private int q;
private int x;
private int a;
private int k;
private int [] signature = new int[2];//signature [0]=r; signature [1] =s
int K=10;
/** Creates new form MainFrame */
public MainFrame() {
initComponents();
Random r = new Random();
p =BigInteger.probablePrime(K, r).intValue();
q =BigInteger.probablePrime(K, r).intValue();
x = r.nextInt(q-1);
BigInteger f = BigInteger.valueOf(q);
f = (f.pow(x)).mod(BigInteger.valueOf(p));
a = f.intValue();
k=3;
jLabel1.setText("p="+p);
jLabel2.setText("q="+q);
jLabel3.setText("x="+x);
jLabel4.setText("y="+a); }
public int getHash(String Message)
{
int hash=0;
for(int i=0; i<Message.length();i++)
{
hash+=(int)Message.charAt(i);
}
return hash;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String M = jTextField1.getText();
int Hash = getHash(M);
Hash = (Hash %(p - 2)) + 1;
BigInteger G = BigInteger.valueOf(q);
G = (G.pow(k)).mod(BigInteger.valueOf(p));
signature[0] = G.intValue();
signature[1] = 1;
BigInteger X = BigInteger.valueOf(x);
BigInteger R = BigInteger.valueOf(signature[0]);
BigInteger K = BigInteger.valueOf(k);
BigInteger S = BigInteger.valueOf(0);
BigInteger P = BigInteger.valueOf(p);
int d = 0;
//s=(x*r1+k*h(M)) mod q
while((((X.multiply(R)).add(K.multiply(S))).mod(P.subtract(BigInteger.valueOf(1)))).intValue() != Hash)
{
S = S.add(BigInteger.valueOf(1));
}
signature[1] = S.intValue();
jLabel5.setText(signature[0]+"II"+signature[1]);
jTextField2.setText(M);
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String M = jTextField2.getText();
int Hash = getHash(M);
Hash = (Hash %(p - 2)) + 1;
BigInteger Y = BigInteger.valueOf(a);
BigInteger R = BigInteger.valueOf(signature[0]);
Y = (Y.pow(signature[0])).multiply(R.pow(signature[1]));
Y = Y.mod(BigInteger.valueOf(p));
int C1 = Y.intValue();
BigInteger G = BigInteger.valueOf(q);
G = (G.pow(Hash)).mod(BigInteger.valueOf(p));
int C2 = G.intValue();
jLabel6.setText("С1="+C1);
jLabel7.setText("С2="+C2);
if(C1 == C2){
jLabel8.setText("Підпис верний. Повідомлення коректне");
}
else
{
jLabel8.setText("Підпис неверний. Повідомлення змінено ");
}
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
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.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
Результат:
Висновок: на даній лабораторній роботі, я дослідження структури алгоритму і методики практичної реалізації (ЕЦП) RSA.