64
Tabel
Bitword
65
Tabel Perubahan Nilai Variabel A,
B
,
C
,
D
,
E
,
F
,
G, H
Variabel
Round
A
B
C
D
E
F
G
H
0
4c74e9b6 6a09e667 bb67ae85 3c6ef372 e934440b 510e527f 9b05688c 1f83d9ab
1
fea04e51 4c74e9b6 6a09e667 bb67ae85 c39fd221 e934440b 510e527f 9b05688c
2
9d7950f0 fea04e51 4c74e9b6 6a09e667 5ea16f92 c39fd221 e934440b 510e527f
3
2be9cf5c 9d7950f0 fea04e51 4c74e9b6 73e9ef50 5ea16f92 c39fd221 e934440b
4
eb88a2d6 2be9cf5c 9d7950f0 fea04e51 a0ede206 73e9ef50 5ea16f92 c39fd221
5
03e96f38 eb88a2d6 2be9cf5c 9d7950f0 c7c1cb57 a0ede206 73e9ef50 5ea16f92
6
7f3dc119 03e96f38 eb88a2d6 2be9cf5c 14467e23 c7c1cb57 a0ede206 73e9ef50
7
3aa76855 7f3dc119 03e96f38 eb88a2d6 5ae66845 14467e23 c7c1cb57 a0ede206
8
4a81244f 3aa76855 7f3dc119 03e96f38 68bb0248 5ae66845 14467e23 c7c1cb57
9
db4b02a5 4a81244f 3aa76855 7f3dc119 7043f150 68bb0248 5ae66845 14467e23
10
97d0698a db4b02a5 4a81244f 3aa76855 6c947cc2 7043f150 68bb0248 5ae66845
11
6fa7a9e7 97d0698a db4b02a5 4a81244f 268762ef 6c947cc2 7043f150 68bb0248
12
dd464123 6fa7a9e7 97d0698a db4b02a5 3d8f30d1 268762ef 6c947cc2 7043f150
13
b616547e dd464123 6fa7a9e7 97d0698a ca4ef871 3d8f30d1 268762ef 6c947cc2
14
799421ff b616547e dd464123 6fa7a9e7 bb3c6aad ca4ef871 3d8f30d1 268762ef
15
725108cd 799421ff b616547e dd464123 63c937fd bb3c6aad ca4ef871 3d8f30d1
16
c19bf059 725108cd 799421ff b616547e cdf14b0b 63c937fd bb3c6aad ca4ef871
17
70db9dcb c19bf059 725108cd 799421ff 17f7399d cdf14b0b 63c937fd bb3c6aad
18
9b607c8f 70db9dcb c19bf059 725108cd 47feb958 17f7399d cdf14b0b 63c937fd
19
334c6c9b 9b607c8f 70db9dcb c19bf059 506a7e50 47feb958 17f7399d cdf14b0b
20
ca6f70d6 334c6c9b 9b607c8f 70db9dcb bf09f71c 506a7e50 47feb958 17f7399d
21
23886117 ca6f70d6 334c6c9b 9b607c8f 6f08addc bf09f71c 506a7e50 47feb958
22
54eda66a 23886117 ca6f70d6 334c6c9b eb2269da 6f08addc bf09f71c 506a7e50
23
a4cde19d 54eda66a 23886117 ca6f70d6 843c863e eb2269da 6f08addc bf09f71c
24
98450675 a4cde19d 54eda66a 23886117 eb8e6d91 843c863e eb2269da 6f08addc
66
Tabel Perubahan Nilai Variabel A,
B
,
C
,
D
,
E
,
F
,
G, H
26
9235fc9a 84624a92 98450675 a4cde19d e63764c8 d178af58 eb8e6d91 843c863e
27
71c7e326 9235fc9a 84624a92 98450675 ee84f170 e63764c8 d178af58 eb8e6d91
28
f798aa39 71c7e326 9235fc9a 84624a92 64a6d6eb ee84f170 e63764c8 d178af58
29
75e29ecf f798aa39 71c7e326 9235fc9a b82d8d92 64a6d6eb ee84f170 e63764c8
30
8d2ebc3e 75e29ecf f798aa39 71c7e326 0829d939 b82d8d92 64a6d6eb ee84f170
31
265c3357 8d2ebc3e 75e29ecf f798aa39 aa2a1bf0 0829d939 b82d8d92 64a6d6eb
32
f71baf27 265c3357 8d2ebc3e 75e29ecf a5623854 aa2a1bf0 0829d939 b82d8d92
33
70f5104d f71baf27 265c3357 8d2ebc3e 5573231d a5623854 aa2a1bf0 0829d939
34
f721d82d 70f5104d f71baf27 265c3357 03db6aac 5573231d a5623854 aa2a1bf0
35
7d77ab41 f721d82d 70f5104d f71baf27 70dacd92 03db6aac 5573231d a5623854
36
5e384c3c 7d77ab41 f721d82d 70f5104d 03e35e7e 70dacd92 03db6aac 5573231d
37
8a6dc700 5e384c3c 7d77ab41 f721d82d e4d4fb6b 03e35e7e 70dacd92 03db6aac
38
8f52791a 8a6dc700 5e384c3c 7d77ab41 7a7361c0 e4d4fb6b 03e35e7e 70dacd92
39
74536e0a 8f52791a 8a6dc700 5e384c3c 406e3d4b 7a7361c0 e4d4fb6b 03e35e7e
40
acdae1d3 74536e0a 8f52791a 8a6dc700 dbc06e3d 406e3d4b 7a7361c0 e4d4fb6b
41
211c00b0 acdae1d3 74536e0a 8f52791a 710ace86 dbc06e3d 406e3d4b 7a7361c0
42
9fe24ab4 211c00b0 acdae1d3 74536e0a 8d159af4 710ace86 dbc06e3d 406e3d4b
43
a02c0e72 9fe24ab4 211c00b0 acdae1d3 6b2e7c0c 8d159af4 710ace86 dbc06e3d
44
31ecd4de a02c0e72 9fe24ab4 211c00b0 d1f3e385 6b2e7c0c 8d159af4 710ace86
45
238e0028 31ecd4de a02c0e72 9fe24ab4 f8e3ef4c d1f3e385 6b2e7c0c 8d159af4
46
e30f84ab 238e0028 31ecd4de a02c0e72 2fa38df1 f8e3ef4c d1f3e385 6b2e7c0c
47
67404e5f e30f84ab 238e0028 31ecd4de 004f814d 2fa38df1 f8e3ef4c d1f3e385
48
b97aa0a1 67404e5f e30f84ab 238e0028 de471d4c 004f814d 2fa38df1 f8e3ef4c
49
a0c51ba3 b97aa0a1 67404e5f e30f84ab 5f36b208 de471d4c 004f814d 2fa38df1
50
e16529d3 a0c51ba3 b97aa0a1 67404e5f 01f1d598 5f36b208 de471d4c 004f814d
51
e57c6214 e16529d3 a0c51ba3 b97aa0a1 88f677f8 01f1d598 5f36b208 de471d4c
Variabel
67
Tabel Perubahan Nilai Variabel A,
B
,
C
,
D
,
E
,
F
,
G, H
52
fa4e01b4 e57c6214 e16529d3 a0c51ba3 f9f315cf 88f677f8 01f1d598 5f36b208
53
4916d342 fa4e01b4 e57c6214 e16529d3 fd3d4b5d f9f315cf 88f677f8 01f1d598
54
2e19abe7 4916d342 fa4e01b4 e57c6214 d3059d64 fd3d4b5d f9f315cf 88f677f8
55
dce49dd8 2e19abe7 4916d342 fa4e01b4 6631f57a d3059d64 fd3d4b5d f9f315cf
56
8b0e251e dce49dd8 2e19abe7 4916d342 edbee7ef 6631f57a d3059d64 fd3d4b5d
57
71c5ecbf 8b0e251e dce49dd8 2e19abe7 7a2c6709 edbee7ef 6631f57a d3059d64
58
ec2549c3 71c5ecbf 8b0e251e dce49dd8 92423f45 7a2c6709 edbee7ef 6631f57a
59
3fa846c7 ec2549c3 71c5ecbf 8b0e251e 13563a16 92423f45 7a2c6709 edbee7ef
60
ed18d6e3 3fa846c7 ec2549c3 71c5ecbf a1b8bf2d 13563a16 92423f45 7a2c6709
61
da2800ea ed18d6e3 3fa846c7 ec2549c3 2fc2d41c a1b8bf2d 13563a16 92423f45
62
b73f5418 da2800ea ed18d6e3 3fa846c7 925cdce6 2fc2d41c a1b8bf2d 13563a16
63
9cfddf72 b73f5418 da2800ea ed18d6e3 6d13c32f 925cdce6 2fc2d41c a1b8bf2d
Variabel
68
Tabel Enkripsi
Karakter
ASCII
C
Karakter
ASCII
C
Karakter
ASCII
C
Karakter
ASCII
C
P
80
46404
b
98
39457
1
49
24890
9
57
52427
l
108
15918
e
101
33829
6
54
10470
3
51
56706
a
97
45171
8
56
33950
0
48
41314
8
56
33950
i
105
59541
f
102
41585
6
54
10470
2
50
4939
n
110
11151
1
49
24890
d
100
28261
e
101
33829
t
116
47019
e
101
33829
3
51
56706
c
99
53687
e
101
33829
1
49
24890
c
99
53687
b
98
39457
x
120
33414
2
50
4939
8
56
33950
3
51
56706
t
116
47019
c
99
53687
b
98
39457
2
50
4939
c
99
53687
a
97
45171
5
53
57119
e
101
33829
b
98
39457
a
97
45171
c
99
53687
0
48
41314
4
52
52371
e
101
33829
6
54
10470
8
56
33950
8
56
33950
8
56
33950
c
99
53687
4
52
52371
f
102
41585
0
48
41314
6
54
10470
3
51
56706
6
54
10470
2
50
4939
f
102
41585
c
99
53687
6
54
10470
3
51
56706
6
54
10470
6
54
10470
8
56
33950
b
98
39457
9
57
52427
0
48
41314
69
Tabel Enkripsi
Karakter
ASCII
C
Karakter
ASCII
C
Karakter
ASCII
C
Karakter
ASCII
C
7
55
52959
9
57
52427
1
49
24890
4
52
52371
7
55
52959
d
100
28261
f
102
41585
9
57
52427
6
54
10470
e
101
33829
0
48
41314
7
55
52959
1
49
24890
9
57
52427
e
101
33829
a
97
45171
8
56
33950
7
55
52959
6
54
10470
c
99
53687
c
99
53687
0
48
41314
c
99
53687
a
97
45171
3
51
56706
9
57
52427
5
53
57119
b
98
39457
0
48
41314
8
56
33950
7
55
52959
7
55
52959
4
52
52371
4
52
52371
e
101
33829
6
54
10470
c
99
53687
9
57
52427
4
52
52371
3
51
56706
a
97
45171
6
54
10470
f
102
41585
0
48
41314
e
101
33829
e
101
33829
4
52
52371
7
55
52959
5
53
57119
8
56
33950
c
99
53687
a
97
45171
1
49
24890
c
99
53687
b
98
39457
4
52
52371
b
98
39457
9
57
52427
8
56
33950
c
99
53687
f
102
41585
0
48
41314
70
Ciphertext
=
“YjU0NAozZTJlCmIwNzMKZTg5NQoyYjhmCmI3YWIKODQyNQo4Mjg2CmI3Y
WIKZDFiNwo5YTIxCmNjOTMKODQ5ZQphMjcxCjI4ZTYKMjhlNgo4NDllCjg0O
WUKOWEyMQo4NDI1Cjg0OWUKYTI3MQo2MTNhCjg0MjUKNjEzYQoxMzRiC
mQxYjcKYjA3MwpiMDczCjg0MjUKODQ5ZQphMTYyCjEzNGIKZGQ4Mgo5YTI
xCmNjY2IKNjEzYQoyOGU2CmExNjIKMjhlNgo2ZTY1CmRkODIKZDFiNwo4N
DllCjlhMjEKZGYxZgpkMWI3CjI4ZTYKZDFiNwoyOGU2CmEyNzEKMjhlNgpjY
2NiCmRmMWYKY2NjYgpkZDgyCjg0OWUKMTM0Ygo4NDI1CmQxYjcKOWEy
MQpkZDgyCjEzNGIKODQyNQphMTYyCjg0OWUKY2M5MwpkZDgyCmQxYjcK
MjhlNgphMTYyCjZlNjUKY2VkZgpjZWRmCjI4ZTYKNjEzYQo4NDllCmQxYjcK
ZGQ4MgphMTYyCmNjOTMKZDFiNwpiMDczCjg0MjUKY2VkZgpkMWI3CmQx
YjcKOWEyMQpkMWI3Cjg0MjUKY2NjYgo2ZTY1Cjg0MjUKY2NjYgpjZWRmC
mExNjIKY2NjYgo4NDllCmNjOTMKY2NjYgoyOGU2Cjg0MjUKZGYxZgpiMDcz
CjlhMjEKY2NjYgphMjcxCmNjOTMKNjEzYQphMjcxCmExNjIKODQyNQoyOGU
2CmQxYjcKZGYxZgpjZWRmCjg0MjUKY2M5MwphMjcxCmNjOTMKODQ5ZQo
2MTNhCmNjOTMKODQ5ZQphMTYyCmRkODIKY2M5MwpjY2NiCmNlZGYKY
jA3MwpkMWI3CmIwNzMKOWEyMQpjZWRmCjI4ZTYKZGQ4MgphMTYyCg==
71
Tabel Dekripsi
C
ASCII
Karakter
C
ASCII
Karakter
C
ASCII
Karakter
C
ASCII
Karakter
46404
80
P
39457
98
b
24890
49
1
52427
57
9
15918
108
l
33829
101
e
10470
54
6
56706
51
3
45171
97
a
33950
56
8
41314
48
0
33950
56
8
59541
105
i
41585
102
f
10470
54
6
4939
50
2
11151
110
n
24890
49
1
28261
100
d
33829
101
e
47019
116
t
33829
101
e
56706
51
3
53687
99
c
33829
101
e
24890
49
1
53687
99
c
39457
98
b
33414
120
x
4939
50
2
33950
56
8
56706
51
3
47019
116
t
53687
99
c
39457
98
b
4939
50
2
53687
99
c
45171
97
a
57119
53
5
33829
101
e
39457
98
b
45171
97
a
53687
99
c
41314
48
0
52371
52
4
33829
101
e
10470
54
6
33950
56
8
33950
56
8
33950
56
8
53687
99
c
52371
52
4
41585
102
f
41314
48
0
10470
54
6
56706
51
3
10470
54
6
4939
50
2
41585
102
f
53687
99
c
10470
54
6
56706
51
3
10470
54
6
10470
54
6
33950
56
8
39457
98
b
52427
57
9
41314
48
0
72
Tabel Dekripsi
tim
ASCII
Karakter
C
ASCII
Karakter
C
ASCII
Karakter
C
ASCII
Karakter
52959
55
7
52427
57
9
24890
49
1
52371
52
4
52959
55
7
28261
100
d
41585
102
f
52427
57
9
10470
54
6
33829
101
e
41314
48
0
52959
55
7
24890
49
1
52427
57
9
33829
101
e
45171
97
a
33950
56
8
52959
55
7
10470
54
6
53687
99
c
53687
99
c
41314
48
0
53687
99
c
45171
97
a
56706
51
3
52427
57
9
57119
53
5
39457
98
b
41314
48
0
33950
56
8
52959
55
7
52959
55
7
52371
52
4
52371
52
4
33829
101
e
10470
54
6
53687
99
c
52427
57
9
52371
52
4
56706
51
3
45171
97
a
10470
54
6
41585
102
f
41314
48
0
33829
101
e
33829
101
e
52371
52
4
52959
55
7
57119
53
5
33950
56
8
53687
99
c
45171
97
a
24890
49
1
53687
99
c
39457
98
b
52371
52
4
39457
98
b
52427
57
9
33950
56
8
53687
99
c
41585
102
f
41314
48
0
Listing Program
Main. java
package controller;
import java.io.File;
import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import java.math.BigInteger; import java.util.Base64;
import javax.swing.text.Document;
import javax.swing.text.rtf.RTFEditorKit;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import view.RootLayoutController; import javafx.application.Application; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Scene;
import javafx.scene.control.ButtonType; import javafx.scene.control.Dialog; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Main extends Application {
private Stage primaryStage; private AnchorPane rootLayout;
private RootLayoutController rlController;
@Override
public void start(Stage primaryStage) throws Exception { this.primaryStage = primaryStage;
initRootLayout(); }
private double X, Y;
74
this.X = primaryStage.getX() - screenX; this.Y = primaryStage.getY() - screenY; }
public void drag(double screenX, double screenY) { primaryStage.setX(this.X + screenX);
primaryStage.setY(this.Y + screenY); }
String plaintext = "", ciphertext = "", plaintextDS = "";
void initRootLayout() { try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/view/GUI.fxml")); rootLayout = (AnchorPane) loader.load();
rlController = loader.getController(); rlController.setMain(this);
rlController.Jendela.hide();
primaryStage.setScene(new Scene(rootLayout)); primaryStage.initStyle(StageStyle.UNDECORATED); primaryStage.show();
rlController.dECDSADigitTF.textProperty().addListener( (ov, ol, ne) -> {
if (!ne.equals("") && !ne.equals("0")) {
if (BigInteger.valueOf(10).pow(Integer.parseInt(ne) - 1)
.compareTo(ECDSA.getInstance().getN().subtract(BigInteger.ONE)) != 1 && Integer.parseInt(ne) > 0) {
refresh("dECDSA", ne); } else {
empty("dECDSAOver"); }
} else
empty("dECDSA"); });
rlController.pRSADigitTF.textProperty().addListener((ov, ol, ne) -> { if (!ne.equals("") && Integer.parseInt(ne) > 1)
refresh("pRSA", ne); else
empty("pRSA"); });
rlController.qRSADigitTF.textProperty().addListener((ov, ol, ne) -> { if (!ne.equals("") && Integer.parseInt(ne) > 1)
refresh("qRSA", ne); else
empty("qRSA"); });
rlController.rRSADigitTF.textProperty().addListener((ov, ol, ne) -> { if (!ne.equals("") && Integer.parseInt(ne) > 1)
else
empty("rRSA"); });
rlController.PRSATA.textProperty().addListener((ov, ol, ne) -> { if (!(ne.equals("") || ne.equals(null)))
plaintext = ne; else
plaintext = ""; });
} catch (Exception e) { e.printStackTrace(); }
}
private byte flagP = 0, flagQ = 0, flagR = 0;
public byte generateRSAState(byte flagP, byte flagQ, byte flagR) { return (byte) ((flagP << 2) | (flagQ << 1) | flagR);
}
public void refresh(String var, String newValue) { if (var.equals("dECDSA")) {
ECDSA.getInstance().generateKey(Integer.parseInt(newValue));
String d = showInHex(ECDSA.getInstance().getD()), Qx = showInHex(ECDSA .getInstance().getQx()), Qy = showInHex(ECDSA.getInstance().getQy()); if (rlController.mode.selectedProperty().get()) {
rlController.dECDSATF.setText(revert(d).toString()); rlController.QxECDSATF.setText(revert(Qx).toString()); rlController.QyECDSATF.setText(revert(Qy).toString()); } else {
rlController.dECDSATF.setText(d); rlController.QxECDSATF.setText(Qx); rlController.QyECDSATF.setText(Qy); }
rlController.dECDSA2TF.setText(rlController.dECDSATF.getText()); rlController.QxECDSA2TF.setText(rlController.QxECDSATF.getText()); rlController.QyECDSA2TF.setText(rlController.QyECDSATF.getText());
} else if (var.equals("pRSA") || var.equals("qRSA") || var.equals("rRSA")) { if (var.equals("pRSA")) {
flagP = 0b001;
RSA_Modified.getInstance().setP(Integer.parseInt(newValue)); if (rlController.mode.selectedProperty().get())
rlController.pRSATF.setText(RSA_Modified.getInstance().getP().toString()); else
rlController.pRSATF.setText(showInHex(RSA_Modified.getInstance().getP())); } else if (var.equals("qRSA")) {
flagQ = 0b001;
RSA_Modified.getInstance().setQ(Integer.parseInt(newValue)); if (rlController.mode.selectedProperty().get())
76
else
rlController.qRSATF.setText(showInHex(RSA_Modified.getInstance().getQ())); } else {
flagR = 0b001;
RSA_Modified.getInstance().setR(Integer.parseInt(newValue)); if (rlController.mode.selectedProperty().get())
rlController.rRSATF.setText(RSA_Modified.getInstance().getR().toString()); else
rlController.rRSATF.setText(showInHex(RSA_Modified.getInstance().getR())); }
if (generateRSAState(flagP, flagQ, flagR) == 7) { RSA_Modified.getInstance().generateKey();
String n = showInHex(RSA_Modified.getInstance().getN()), totient = showInHex(RSA_Modified
.getInstance().getTotient()), e = showInHex(RSA_Modified.getInstance() .getE()), d = showInHex(RSA_Modified.getInstance().getD());
if (rlController.mode.selectedProperty().get()) { rlController.nRSATF.setText(revert(n).toString());
rlController.totientRSATF.setText(revert(totient).toString()); rlController.eRSATF.setText(revert(e).toString());
rlController.dRSATF.setText(revert(d).toString()); } else {
rlController.nRSATF.setText(n);
rlController.totientRSATF.setText(totient); rlController.eRSATF.setText(e);
rlController.dRSATF.setText(d); }
rlController.nRSA2TF.setText(rlController.nRSATF.getText()); rlController.nRSA3TF.setText(rlController.nRSATF.getText()); rlController.eRSA2TF.setText(rlController.eRSATF.getText()); rlController.dRSA2TF.setText(rlController.dRSATF.getText()); }
} }
public void empty(String var) {
if (var.equals("dECDSA") || var.equals("dECDSAOver")) { if (var.equals("dECDSAOver"))
rlController.dECDSATF
.setText("Nilai untuk kunci harus tidak boleh melebihi nilai order kurva elips");
else
rlController.dECDSATF
.setText("Digit untuk kunci harus lebih besar atau sama dengan 1"); rlController.QxECDSATF.setText("");
} else if (var.equals("pRSA") || var.equals("qRSA") || var.equals("rRSA")) { if (var.equals("pRSA")) {
flagP = 0b000;
rlController.pRSATF.setText("Digit untuk kunci harus lebih dari 1"); } else if (var.equals("qRSA")) {
flagQ = 0b000;
rlController.qRSATF.setText("Digit untuk kunci harus lebih dari 1"); } else {
flagR = 0b000;
rlController.rRSATF.setText("Digit untuk kunci harus lebih dari 1"); }
rlController.nRSATF.setText(""); rlController.totientRSATF.setText(""); rlController.eRSATF.setText(""); rlController.dRSATF.setText(""); rlController.nRSA2TF.setText(""); rlController.nRSA3TF.setText(""); rlController.eRSA2TF.setText(""); rlController.dRSA2TF.setText("");
} }
boolean decrypt = false;
public void browse(String type) { try {
FileChooser fc = new FileChooser(); String path = "", result;
if (type.equals("plaintext") || type.equals("ciphertext")) { if (type.equals("plaintext")) {
plaintext = "";
fc.getExtensionFilters().add(
new ExtensionFilter("Text Files", "*.txt", "*.rtf", "*.doc", "*.docx"));
}
fc.setTitle("Pilih File " + type);
File file = fc.showOpenDialog(primaryStage); path = file.getCanonicalPath();
String fileName = file.getName();
String fileExtension = fileName.substring(fileName.indexOf(".") + 1, file .getName().length());
if (fileExtension.equals("txt")) {
FileReader extracttxt = new FileReader(file); char[] chars = new char[(int) file.length()]; extracttxt.read(chars);
result = new String(chars); extracttxt.close();
78
} else if (fileExtension.equals("doc")) {
WordExtractor extractdoc = new WordExtractor(new HWPFDocument( new FileInputStream(path)));
result = extractdoc.getText(); extractdoc.close();
} else if (fileExtension.equals("docx")) {
XWPFWordExtractor extractdocx = new XWPFWordExtractor(new XWPFDocument( new FileInputStream(path)));
result = extractdocx.getText(); extractdocx.close();
} else {
FileReader extractother = new FileReader(file); char[] chars = new char[(int) file.length()]; extractother.read(chars);
result = new String(chars); extractother.close(); }
if (type.equals("plaintext")) { rlController.PRSATA.setText(""); rlController.plainTF.setText(path); plaintext = result;
rlController.encryptionTF.setText("Pesan belum dienkripsi"); rlController.generateDSTF
.setText("Pembuatan tanda tangan digital pesan belum dilakukan"); } else {
rlController.cipherTF.setText(path); ciphertext = result;
rlController.decryptionTF.setText("Pesan belum didekripsi"); rlController.verifyTF
.setText("Tanda tangan digital pesan belum diverifikasi"); }
rlController.PRSATA.setText(plaintext); } else if (type.equals("saveciphertext")) { File savefile = fc.showSaveDialog(primaryStage); FileWriter fw = new FileWriter(savefile);
fw.write(ciphertext); fw.close();
rlController.encryptionTF
.setText("Proses enkripsi berhasil dan pesan telah disimpan");
savefile = fc.showSaveDialog(primaryStage); fw = new FileWriter(savefile);
fw.write(plaintextDS); fw.close();
} else { }
} catch (RuntimeException e) {
} catch (Exception e) { }
}
public boolean validateNode(Node node) { if (!this.dialog.equals(""))
dialog += "\n";
try {
if (!(((TextField) node).getText().equals(""))) return true;
else {
if (node.getId().equals("dECDSA2TF"))
dialog += "Kunci privat " + node.getId().charAt(0) + " ECDSA pengirim tidak boleh kosong";
else if (node.getId().equals("eRSA2TF") || node.getId().equals("nRSA2TF")) dialog += "Kunci publik " + node.getId().charAt(0)
+ " RSA penerima tidak boleh kosong";
else if (node.getId().equals("dRSA2TF") || node.getId().equals("nRSA3TF")) dialog += "Kunci privat " + node.getId().charAt(0)
+ " RSA penerima tidak boleh kosong"; else if (node.getId().equals("QxECDSA2TF") || node.getId().equals("QyECDSA2TF"))
dialog += "Kunci publik " + node.getId().charAt(0)
+ node.getId().charAt(1) + " ECDSA pengirim tidak boleh kosong"; else if (node.getId().equals("rECDSATF") ||
node.getId().equals("sECDSATF")
|| node.getId().equals("rECDSA2TF") || node.getId().equals("sECDSA2TF")) dialog += "Tanda tangan digital " + node.getId().charAt(0)
+ " tidak boleh kosong"; }
} catch (Exception e) { }
try {
if (!(((TextArea) node).getText().equals(""))) return true;
else {
if (node.getId().equals("PRSATA") || node.getId().equals("PRSA2TA")) { }
dialog += "Plaintext tidak boleh kosong"; }
} catch (Exception e) { }
return false; }
// k =
// revert("00000000 00000000 00000000 00000000 00000000 00000003 2fb77c21 eba4ee1c")
public void generate() {
boolean v = validateNode(rlController.dECDSA2TF), v1 = validateNode(rlController.PRSATA);
80
if (v && v1) {
if (revert(rlController.dECDSA2TF.getText()).compareTo( ECDSA.getInstance().getN()) == -1) {
if (rlController.mode.selectedProperty().getValue()) d = new BigInteger(rlController.dECDSA2TF.getText()); else
d = revert(rlController.dECDSA2TF.getText());
ECDSA.getInstance().generateDS(rlController.PRSATA.getText(), d);
if (rlController.mode.selectedProperty().getValue()) { r = "" + ECDSA.getInstance().getR();
s = "" + ECDSA.getInstance().getS();
} else {
r = showInHex(ECDSA.getInstance().getR()); s = showInHex(ECDSA.getInstance().getS()); }
rlController.rECDSATF.setText(r); rlController.sECDSATF.setText(s);
rlController.generateDSTF
.setText("Pembangkitan tanda tangan digital selesai"); } else {
dialog += "Ukuran kunci privat ECDSA terlalu besar"; rlController.generateDSTF
.setText("Pembangkitan tanda tangan digital gagal"); showErrorDialog();
} } else
showErrorDialog(); this.dialog = ""; }
public void verify() {
boolean v4 = validateNode(rlController.PRSA2TA), v = validateNode(rlController.rECDSA2TF), v1 =
validateNode(rlController.sECDSA2TF), v2 = validateNode(rlController.QxECDSA2TF), v3 = validateNode(rlController.QyECDSA2TF);
BigInteger r, s, Qx, Qy;
if (rlController.mode.selectedProperty().getValue()) { r = new BigInteger(rlController.rECDSA2TF.getText()); s = new BigInteger(rlController.sECDSA2TF.getText()); Qx = new BigInteger(rlController.QxECDSA2TF.getText()); Qy = new BigInteger(rlController.QyECDSA2TF.getText()); } else {
if (v4 && v3 && v2 && v1 && v) {
if (ECDSA.getInstance().verifyDS(plaintext, r, s, Qx, Qy)) {
rlController.verifyTF.setText("Tanda tangan digital dari pesan valid"); } else
rlController.verifyTF
.setText("Tanda tangan digital dari pesan tidak valid"); } else
showErrorDialog(); this.dialog = ""; }
public void encrypt() { String r, s;
BigInteger e, n;
r = String.format("%64s", ECDSA.getInstance().getR().toString(16)).replace( ' ', '0');
s = String.format("%64s", ECDSA.getInstance().getS().toString(16)).replace( ' ', '0');
ciphertext = ""; plaintextDS = "";
boolean v1 = validateNode(rlController.eRSA2TF), v2 =
validateNode(rlController.nRSA2TF), v3 = validateNode(rlController.dECDSA2TF), v = validateNode(rlController.PRSATA);
if (rlController.mode.selectedProperty().getValue()) { e = new BigInteger(rlController.eRSA2TF.getText()); n = new BigInteger(rlController.nRSA2TF.getText()); } else {
e = revert(rlController.eRSA2TF.getText()); n = revert(rlController.nRSA2TF.getText()); }
if (v3 && v2 && v1 && v) {
RSA_Modified.getInstance().encrypt(rlController.PRSATA.getText() + r + s, e,
n);
plaintextDS = rlController.PRSATA.getText() + r + s; ciphertext += RSA_Modified.getInstance().getCiphertext();
ciphertext = Base64.getEncoder().encodeToString(ciphertext.getBytes());
browse("saveciphertext"); } else {
rlController.encryptionTF.setText("Proses enkripsi gagal"); showErrorDialog();
}
this.dialog = ""; }
public void decrypt() {
82
BigInteger d, n; String r, s;
byte[] decode = Base64.getDecoder().decode(ciphertext);
if (rlController.mode.selectedProperty().getValue()) { d = new BigInteger(rlController.dRSA2TF.getText()); n = new BigInteger(rlController.nRSA3TF.getText()); } else {
d = revert(rlController.dRSA2TF.getText()); n = revert(rlController.nRSA3TF.getText()); }
if (v1 && v) { String file = "";
rlController.PRSA2TA.setText("");
RSA_Modified.getInstance().decrypt(new String(decode), d, n);
file = RSA_Modified.getInstance().getPlaintext(); plaintext = file.substring(0, file.length() - 128); rlController.PRSA2TA.setText(plaintext);
if (rlController.mode.selectedProperty().getValue()) { r = ""
+ new BigInteger(file.substring(file.length() - 128, file.length() - 64),
16); s = ""
+ new BigInteger(file.substring(file.length() - 64, file.length()), 16); } else {
r = showInHex(new BigInteger(file.substring(file.length() - 128, file.length() - 64), 16));
s = showInHex(new BigInteger(file.substring(file.length() - 64, file.length()), 16));
}
rlController.rECDSA2TF.setText(r); rlController.sECDSA2TF.setText(s);
rlController.decryptionTF.setText("Proses dekripsi berhasil"); } else {
rlController.decryptionTF.setText("Proses dekripsi gagal"); showErrorDialog();
}
this.dialog = ""; }
public void showErrorDialog() {
Dialog<Object> dialog = new Dialog<Object>(); dialog.initOwner(primaryStage);
dialog.setTitle("Terjadi kesalahan"); dialog.setContentText(this.dialog);
dialog.getDialogPane().getButtonTypes().add(ButtonType.OK); dialog.showAndWait();
public String showInHex(BigInteger var) { String result = "";
String varStr = String.format("%64s", var.toString(16)).replace(' ', '0'); for (int i = 0; i < varStr.length(); i++) {
result += varStr.charAt(i);
if (i % 8 == 7 && i != varStr.length() - 1) result += " ";
}
return result; }
public BigInteger revert(String var) { String varStr = "";
for (int i = 0; i < var.length(); i++) if (var.charAt(i) != ' ')
varStr += var.charAt(i);
return new BigInteger(varStr, 16); }
public static void main(String[] args) { launch(args);
} }
ECDSA.java
package controller;
import java.math.*;
import java.security.NoSuchAlgorithmException; import java.security.SecureRandom;
public class ECDSA {
private BigInteger d, Qx, Qy, r, s, hashv, k;
private static final ECDSA Instance = new ECDSA();
private ECDSA() {};
public static ECDSA getInstance() { try {
random = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); }
84
public void setK(BigInteger k) { this.k = k;
}
public BigInteger getK() { return k;
}
public BigInteger getHashv() { return hashv;
}
public BigInteger getD() { return d;
}
public BigInteger getQx() { return Qx;
}
public BigInteger getQy() { return Qy;
}
public BigInteger getR() { return r;
}
public BigInteger getS() { return s;
}
public BigInteger getN() { return Elliptic_Curve.n; }
public static SecureRandom random;
public void generateKey(int digit) {
BigInteger d = null, Qx = null, Qy = null;
if (BigInteger.valueOf(10).pow(digit - 1) .compareTo(Elliptic_Curve.n) == -1) {
while ((d = new BigInteger((int) Math.ceil((digit) * (Math.log(10) / Math.log(2))),random)
Qx = new Elliptic_Curve().new thirdPoint( new BigInteger(Elliptic_Curve.Gx, 16), new BigInteger(Elliptic_Curve.Gy, 16), d).getX(),
Qy = new Elliptic_Curve().new thirdPoint( new BigInteger(Elliptic_Curve.Gx, 16), new BigInteger(Elliptic_Curve.Gy, 16), d).getY()));
this.d = d; this.Qx = Qx; this.Qy = Qy; } else { try {
throw new Exception("Kelebihan Digit"); } catch (Exception e) {
} } }
public void generateDS(String message, BigInteger d) { SecureRandom random;
this.hashv = new SHA_256(message).getHashValue(); try {
random = SecureRandom.getInstance("SHA1PRNG"); BigInteger k, r, s;
k = new BigInteger(random.nextInt(256), random) .mod(Elliptic_Curve.n);
while (k.compareTo(BigInteger.ONE) == -1
&& new Elliptic_Curve().new thirdPoint(new BigInteger( Elliptic_Curve.Gx, 16), new BigInteger(
Elliptic_Curve.Gy, 16), k).getX().equals( BigInteger.ZERO)) {
k = k.add(BigInteger.ONE); }
r = new Elliptic_Curve().new thirdPoint(new BigInteger( Elliptic_Curve.Gx, 16), new BigInteger(Elliptic_Curve.Gy, 16), k).getX().mod(Elliptic_Curve.n);
s = new Extended_Euclidean(k, Elliptic_Curve.n).getInvers() .multiply(this.hashv.add(d.multiply(r)))
.mod(Elliptic_Curve.n); this.k = k;
this.r = r; this.s = s;
} catch (Exception e) { }
86
public void generateDS(String message, BigInteger k, BigInteger d) { this.r = new Elliptic_Curve().new thirdPoint(new BigInteger(
Elliptic_Curve.Gx, 16), new BigInteger(Elliptic_Curve.Gy, 16), k).getX().mod(Elliptic_Curve.n);
this.s = new Extended_Euclidean(k, Elliptic_Curve.n) .getInvers()
.multiply(
(this.hashv = new SHA_256(message).getHashValue()) .add(d.multiply(r))).mod(Elliptic_Curve.n); this.k = k;
}
public boolean verifyDS(String message, BigInteger r, BigInteger s, BigInteger Qx, BigInteger Qy) {
BigInteger u1, u2, lhsx, rhsx, lhsy, rhsy, Xx, w; try {
if (r.compareTo(Elliptic_Curve.n) == -1 && s.compareTo(Elliptic_Curve.n) == -1) { Elliptic_Curve.thirdPoint tP;
w = new Extended_Euclidean(s, Elliptic_Curve.n).getInvers(); u1 = w.multiply(new SHA_256(message).getHashValue()).mod( Elliptic_Curve.n);
u2 = w.multiply(r).mod(Elliptic_Curve.n);
tP = new Elliptic_Curve().new thirdPoint(new BigInteger( Elliptic_Curve.Gx, 16), new BigInteger(
Elliptic_Curve.Gy, 16), u1); lhsx = tP.getX();
lhsy = tP.getY();
tP = new Elliptic_Curve().new thirdPoint(Qx, Qy, u2); rhsx = tP.getX();
rhsy = tP.getY();
Xx = new Elliptic_Curve().new thirdPoint(lhsx, lhsy, rhsx, rhsy) .getX();
if (Xx.equals(r)) return true; }
} catch (Exception e) { e.printStackTrace(); }
return false; }
RSA_Modified.java
package controller;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException; import java.security.SecureRandom;
/**
* Kelas RSA_Modified Input : pdigit,qdigit,rdigit Output : n, totient, d, e */
public class RSA_Modified {
private BigInteger p = BigInteger.ZERO, q = BigInteger.ZERO, r = BigInteger.ZERO, n, totient, d, e;
private static final RSA_Modified Instance = new RSA_Modified();
private RSA_Modified() { }
public static RSA_Modified getInstance() { return Instance;
}
public static BigInteger modExp(int a, BigInteger u, BigInteger n) { // a^u mod n
BigInteger s = BigInteger.ONE;
BigInteger t = BigInteger.valueOf(a);
for (int i = u.toString(2).length() - 1; i >= 0; i--) { if (u.toString(2).charAt(i) == '1')
s = (s.multiply(t)).mod(n); t = (t.pow(2)).mod(n); }
return s; }
public static BigInteger modExp(BigInteger a, BigInteger u, BigInteger n) { // a^u mod n
BigInteger s = BigInteger.ONE, t = a;
for (int i = u.toString(2).length() - 1; i >= 0; i--) { if (u.toString(2).charAt(i) == '1')
s = (s.multiply(t)).mod(n); t = (t.pow(2)).mod(n);
}
return s; }
// false = bilangan prima dan true = bilangan komposit
static boolean MR(BigInteger n, int s) throws NoSuchAlgorithmException { boolean[] result = new boolean[s];
88
int a = 0, t = 0;
BigInteger u, x0, x1 = BigInteger.ZERO, temp = n .subtract(BigInteger.ONE);
for (int i = 0; i < s; i++) {
SecureRandom r = SecureRandom.getInstance("SHA1PRNG"); if (n.toString().length() < 5)
a = r.nextInt(n.intValue()); else
a = r.nextInt(100000); test[i] = a;
while (temp.mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO)) { temp = temp.divide(BigInteger.valueOf(2));
t++; }
u = (n.subtract(BigInteger.ONE)).divide(BigInteger.valueOf(2) .pow(t));
x0 = modExp(a, u, n);
for (int j = 0; j < t; j++) { x1 = (x0.pow(2)).mod(n); if (x1.equals(BigInteger.ONE)
&& !(x0.equals(BigInteger.ONE) && x0.equals(n .subtract(BigInteger.ONE)))) {
result[i] = true; break;
}
x0 = x1; }
if (!x1.equals(BigInteger.ONE)) result[i] = true;
else
result[i] = false; }
int countTrue = 0, countFalse = 0; for (int i = 0; i < s; i++) { if (result[i])
countTrue++; else
countFalse++; }
if (countTrue > countFalse) { return true;
}
return false; }
/**
* @param args */
SecureRandom r; try {
r = SecureRandom.getInstance("SHA1PRNG");
BigInteger result = new BigInteger((int) (Math.ceil((length) * (Math.log(10) / Math.log(2)))), r);
int[] list = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
boolean stop = false, cont; while (!stop) {
cont = false;
if (result.toString().length() == length) { for (int a : list) {
if (result.mod(BigInteger.valueOf(a)).equals( BigInteger.ZERO)
&& !result.equals(BigInteger.valueOf(a))) { cont = true;
break; } }
if (cont) {
result = new BigInteger((int) (Math.ceil((length) * (Math.log(10) / Math.log(2)))), r);
continue; }
if (!MR(result, 3)) return result; }
result = new BigInteger((int) (Math.ceil((length) * (Math.log(10) / Math.log(2)))), r);
}
} catch (NoSuchAlgorithmException e) { e.printStackTrace();
}
return BigInteger.ZERO; }
public BigInteger generateNotSamePrime(BigInteger p2, BigInteger p3, int digit) {
90
if (!p2.equals(BigInteger.ZERO)) { if (!p3.equals(BigInteger.ZERO)) { if (p2.toString().length() == digit) { if (p3.toString().length() == digit) {
while ((p1 = generatePrime(digit)).compareTo(p3) == 0 || p1.compareTo(p2) == 0)
; } else {
while ((p1 = generatePrime(digit)).compareTo(p2) == 0) ;
} } else {
if (p3.toString().length() == digit) {
while ((p1 = generatePrime(digit)).compareTo(p3) == 0) ;
} else {
p1 = generatePrime(digit); }
} } else {
if (p2.toString().length() == digit) {
while ((p1 = generatePrime(digit)).compareTo(p2) == 0) ;
} else {
p1 = generatePrime(digit); }
} } else {
if (!p3.equals(BigInteger.ZERO)) if (p3.toString().length() == digit)
while ((p1 = generatePrime(digit)).compareTo(p3) == 0) ;
else
p1 = generatePrime(digit); else
p1 = generatePrime(digit); }
return p1; }
public void setP(int pdigit) {
this.p = generateNotSamePrime(this.q, this.r, pdigit); }
public BigInteger getP() { return p;
}
public void setQ(int qdigit) {
this.q = generateNotSamePrime(this.p, this.r, qdigit); }
}
public void setR(int rdigit) {
this.r = generateNotSamePrime(this.p, this.q, rdigit); }
public BigInteger getR() { return r;
}
public BigInteger getN() { return n;
}
public BigInteger getTotient() { return totient;
}
public BigInteger getE() { return e;
}
public BigInteger getD() { return d;
}
SecureRandom random;
public void generateKey() { try {
random = SecureRandom.getInstance("SHA1PRNG"); this.n = this.p.multiply(this.q).multiply(this.r); this.totient = this.p.subtract(BigInteger.ONE) .multiply(this.q.subtract(BigInteger.ONE)) .multiply(this.r.subtract(BigInteger.ONE));
BigInteger temp;
while ((temp = new BigInteger(totient.bitLength(), random) .mod(this.totient)).mod(BigInteger.valueOf(2)).equals( BigInteger.ZERO)
|| temp.compareTo(BigInteger.valueOf(5)) == -1
|| !new Extended_Euclidean(temp, totient).getGcd().equals( BigInteger.ONE))
;
this.e = temp;
this.d = new Extended_Euclidean(this.e, this.totient).getInvers(); } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); }
}
92
public void encrypt(String plaintext, BigInteger e, BigInteger n) { ciphertext = "";
for (int i = 0; i < plaintext.length(); i++){
ciphertext += (RSA_Modified.modExp(BigInteger.valueOf((int) plaintext.charAt(i)), e, n)).toString(16)+"\n";
} }
public String getCiphertext(){ return this.ciphertext; }
public String getPlaintext(){ return this.plaintext; }
public void decrypt(String ciphertext, BigInteger d, BigInteger n) { String buffer="";
for (int i = 0; i < ciphertext.length(); i++){ if (ciphertext.charAt(i) != '\n') {
buffer += ciphertext.charAt(i);
} else if (ciphertext.charAt(i) == '\n') { plaintext += (char) RSA_Modified.modExp(new BigInteger(buffer,16),d,n).intValue();
buffer = ""; }
} } }
Elliptic_Curve.java
package controller;
import java.math.BigInteger;
public class Elliptic_Curve {
public Elliptic_Curve() {}
/**
* Curve y2 = x3 – 3x +b (mod p) */
public static BigInteger p = new BigInteger(
"11579208921035624876269744694940757353008614341529031419553363130886709785395 1");
public static BigInteger n = new BigInteger(
"11579208921035624876269744694940757352999695522413576034242225906106851204436 9");
// "c49d3608 86e70493 6a6678e1 139d26b7 819f7e90"; // private static String c =
// "7efba166 2985be94 03cb055c 75d4f7e0 ce8d84a9 c5114abc af317768 0104fa0d"; private static String b = "5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0
cc53b0f6 3bce3c3e 27d2604b"; public static String Gx =
"6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"; public static String Gy =
"4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5";
public static boolean checkPoint(BigInteger Px, BigInteger Py) { BigInteger rhs = Px
.pow(3)
.add(Px.multiply(BigInteger.valueOf(-3)).mod(p) .add(new BigInteger(removeSpace(b), 16))).mod(p); BigInteger lhs = Py.pow(2).mod(p);
if (rhs.equals(lhs)) return true;
else
return false; }
public static BigInteger lambda(BigInteger Px, BigInteger Py, BigInteger Qx, BigInteger Qy) {
return new Extended_Euclidean(Qx.subtract(Px), Qy.subtract(Py), Elliptic_Curve.p).getInvers();
}
public static BigInteger lambda(BigInteger Px, BigInteger Py) { return new Extended_Euclidean(Py.multiply(BigInteger.valueOf(2)), Px .pow(2).multiply(BigInteger.valueOf(3))
.add(BigInteger.valueOf(-3)), Elliptic_Curve.p).getInvers(); }
public static String removeSpace(String str) { String strBuffer = "";
for (int i = 0; i < str.length(); i++) { if (str.charAt(i) != ' ')
strBuffer += str.charAt(i); }
return strBuffer; }
/**
* Kelas untuk menentukan titik hasil penjumlahan titik lain ada kurva */
class thirdPoint {
private BigInteger x, y, lambda;
public thirdPoint() {}
94
x = lambda.pow(2).subtract(Px.add(Px)) .mod(Elliptic_Curve.p);
y = lambda.multiply(Px.subtract(x)).subtract(Py) .mod(Elliptic_Curve.p);
}
public thirdPoint(BigInteger Px, BigInteger Py, BigInteger Qx, BigInteger Qy) {
this.lambda = lambda(Px, Py, Qx, Qy);
x = lambda.pow(2).subtract(Px).subtract(Qx).mod(Elliptic_Curve.p); y = lambda.multiply(Px.subtract(x)).subtract(Py)
.mod(Elliptic_Curve.p); }
public thirdPoint(BigInteger Px, BigInteger Py, BigInteger n) { if (n.equals(Elliptic_Curve.n)) {
this.x = new BigInteger("0"); this.y = new BigInteger("0"); } else {
BigInteger z = new BigInteger("0"); String g = n.toString(2);
BigInteger Qx = new BigInteger("0"); BigInteger Qy = new BigInteger("0");
for (int i = 0; i < g.length(); i++) { this.lambda = lambda(Qx, Qy);
z = Qx;
Qx = this.lambda.pow(2).subtract(Qx.add(Qx)) .mod(Elliptic_Curve.p);
Qy = this.lambda.multiply(z.subtract(Qx)).subtract(Qy) .mod(Elliptic_Curve.p);
if (g.charAt(i) == '1') {
if (Qx.equals(BigInteger.ZERO)) { Qx = Px;
Qy = Py; } else {
this.lambda = lambda(Qx, Qy, Px, Py); z = Qx;
Qx = this.lambda.pow(2).subtract(Qx) // Q=P+Q .subtract(Px).mod(Elliptic_Curve.p);
Qy = this.lambda.multiply(z.subtract(Qx)) .subtract(Qy).mod(Elliptic_Curve.p); }
} }
this.x = Qx; this.y = Qy; }
}
public BigInteger getX() { return this.x;
public BigInteger getY() { return this.y;
}
public BigInteger getLambda() { return this.lambda;
} } }
Extended_Euclidean.java
package controller;
import java.math.BigInteger;
public class Extended_Euclidean {
private BigInteger invers, gcd;
public BigInteger getInvers(){ return invers;
}
public BigInteger getGcd(){ return gcd;
}
public Extended_Euclidean(BigInteger divisor, BigInteger k) { this(divisor, BigInteger.ONE, k);
}
public Extended_Euclidean(BigInteger divisor, BigInteger dividend, BigInteger k) {
if (divisor.compareTo(BigInteger.ZERO) == -1) { divisor = divisor.add(k);
}
BigInteger a = BigInteger.ONE, b = BigInteger.ZERO, c = b, d = a, e = b, f = b, A = divisor, B = k, C = b, q;
while (B != BigInteger.ZERO) { q = A.divide(B);
e = a; f = b; a = c; b = d;
c = e.subtract(q.multiply(c)); d = f.subtract(q.multiply(d)); C = A;
A = B;
96
}
this.invers = a.multiply(dividend).mod(k); this.gcd = A;
} }
SHA_256.java
package controller;
import java.math.BigInteger; import java.util.ArrayList;
public class SHA_256 {
private BigInteger hashv;
public SHA_256(String message) { generateHash(message);
}
public BigInteger getHashValue() { return hashv;
}
public void generateHash(String message) { String hashv = "";
long[] h = new long[] { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
int[] k = new int[] { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98,
0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 };
long A, B, C, D, E, F, G, H, T1, T2;
ArrayList<Byte> a = new ArrayList<>(); long _length;
// Pengubahan pesan dengan encoding for (Byte i : message.getBytes()) { a.add(i);
_length = (long) a.size() * 8;
// Tambahkan 10000000
a.add((byte) (0x80 & 0xFF));
int g;
// Tambahkan 00000000 if (a.size() % 64 != 56) { if ((g = a.size() % 64) < 56) { for (int i = 1; i <= 56 - g; i++) a.add((byte) 0x00);
} else {
for (int i = 1; i <= 120 - g; i++) { a.add((byte) 0x00);
} } }
// Representasi panjang pesan dalam 64 bit for (int i = 0; i < 8; i++) {
a.add((byte) ((_length >> (64 - 8 * (i + 1))))); }
long[] bitword;
// Proses per 512 bit
for (int j = 0; j < a.size() / 64; j++) { bitword = new long[64];
// Pembentukan Bitword untuk blok 512 bit menjadi 16 bitword @ // 32-bit
for (int i = 0; i < 64; i += 4) {
bitword[i / 4] = (a.get(64 * j + i) & 0xFF) << 24 | (a.get(64 * j + 1 + i) & 0xFF) << 16
| (a.get(64 * j + 2 + i) & 0xFF) << 8 | a.get(64 * j + 3 + i) & 0xFF; }
for (int i = 16; i < 64; i++) {
bitword[i] = (sigma1((int) bitword[i - 2]) + bitword[i - 7]
+ sigma0((int) bitword[i - 15]) + bitword[i - 16]) % 0x100000000L; }
// Inisialisasi A, B, C, D, E, F, G, H A = h[0];
98
// Proses kompresi
for (int i = 0; i < 64; i++) {
T1 = (H + (Sigma1((int) E) & 0xFFFFFFFFL)
+ (Ch((int) E, (int) F, (int) G) & 0xFFFFFFFFL)
+ (k[i] & 0xFFFFFFFFL) + (bitword[i] & 0xFFFFFFFFL)) % 0x100000000L; T2 = ((Sigma0((int) A) & 0xFFFFFFFFL) + (Maj((int) A, (int) B,
(int) C) & 0xFFFFFFFFL)) % 0x100000000L; H = G;
G = F; F = E;
E = (D + T1) % 0x100000000L; D = C;
C = B; B = A;
A = (T1 + T2) % 0x100000000L; }
h[0] = (A + h[0]) % 0x100000000L; h[1] = (B + h[1]) % 0x100000000L; h[2] = (C + h[2]) % 0x100000000L; h[3] = (D + h[3]) % 0x100000000L; h[4] = (E + h[4]) % 0x100000000L; h[5] = (F + h[5]) % 0x100000000L; h[6] = (G + h[6]) % 0x100000000L; h[7] = (H + h[7]) % 0x100000000L; }
for (int i = 0; i < 8; i++) {
hashv += String.format("%8s", Integer.toHexString((int) (h[i]))) .replace(' ', '0');
}
this.hashv = new BigInteger(hashv, 16); }
private int Ch(int X, int Y, int Z) { return (X & Y) ^ (~X & Z);
}
private int Maj(int X, int Y, int Z) { return (X & Y) ^ (X & Z) ^ (Y & Z); }
private int Sigma0(int X) {
return RR(X, 2) ^ RR(X, 13) ^ RR(X, 22); }
private int Sigma1(int X) {
return RR(X, 6) ^ RR(X, 11) ^ RR(X, 25); }
return (int) (RR((int) X, 17) ^ RR((int) X, 19) ^ ((X >> 10) & 0x003FFFFF)); }
private int sigma0(int X) {
return (int) (RR((int) X, 7) ^ RR((int) X, 18) ^ ((X >> 3) & 0x1FFFFFFF)); }
private int RL(int a, int n) {
return a << n ^ a >> (32 - n) & ((0x01 << n) - 1); }
private int RR(int a, int n) { return RL(a, 32 - n);