Tabel Bitword 506c6169 00000000 34b8e161 bb331fa9 5f8dfa00 3e7ae6f0 8dbc231d 4bb1f141
6e746578 00000000 7d1a8298 e3e45510 67feed17 285710af 49396196 a7c82bdc
74800000 00000000 e11192f3 fd0f9dc6 c27d4203 23326c02 6e790232 cd2815be
00000000 00000000 1100778e 9b325d69 9f6efe16 94d701e9 e1921ddf e3d6da9e
00000000 00000000 fb1fc8ce 72976d7e 6573dfcb 37a136cc 6b1b3a42 6c2ff9f3
00000000 00000000 35328abd 827f97ce e0c782a1 a4f16e64 a5e3e7c7 fcc095ea
00000000 00000000 1d406566 33dba4c9 44567a3f 8f224a04 172fa143 1115f4bc
00000000 00000048 48bd51fe f1174f46 5d82b49f 4038e44a d880dcfd 06cd86b2
64 Universitas Sumatera Utara
Tabel Perubahan Nilai Variabel A, B, C, D, E, F, G, H Variabel Round
B
C
D
E
F
G
H
4c74e9b6 fea04e51 9d7950f0 2be9cf5c eb88a2d6 03e96f38 7f3dc119 3aa76855 4a81244f db4b02a5 97d0698a 6fa7a9e7 dd464123 b616547e 799421ff 725108cd c19bf059 70db9dcb 9b607c8f 334c6c9b ca6f70d6 23886117 54eda66a a4cde19d 98450675 84624a92
6a09e667 4c74e9b6 fea04e51 9d7950f0 2be9cf5c eb88a2d6 03e96f38 7f3dc119 3aa76855 4a81244f db4b02a5 97d0698a 6fa7a9e7 dd464123 b616547e 799421ff 725108cd c19bf059 70db9dcb 9b607c8f 334c6c9b ca6f70d6 23886117 54eda66a a4cde19d 98450675
bb67ae85 6a09e667 4c74e9b6 fea04e51 9d7950f0 2be9cf5c eb88a2d6 03e96f38 7f3dc119 3aa76855 4a81244f db4b02a5 97d0698a 6fa7a9e7 dd464123 b616547e 799421ff 725108cd c19bf059 70db9dcb 9b607c8f 334c6c9b ca6f70d6 23886117 54eda66a a4cde19d
3c6ef372 bb67ae85 6a09e667 4c74e9b6 fea04e51 9d7950f0 2be9cf5c eb88a2d6 03e96f38 7f3dc119 3aa76855 4a81244f db4b02a5 97d0698a 6fa7a9e7 dd464123 b616547e 799421ff 725108cd c19bf059 70db9dcb 9b607c8f 334c6c9b ca6f70d6 23886117 54eda66a
e934440b c39fd221 5ea16f92 73e9ef50 a0ede206 c7c1cb57 14467e23 5ae66845 68bb0248 7043f150 6c947cc2 268762ef 3d8f30d1 ca4ef871 bb3c6aad 63c937fd cdf14b0b 17f7399d 47feb958 506a7e50 bf09f71c 6f08addc eb2269da 843c863e eb8e6d91 d178af58
510e527f e934440b c39fd221 5ea16f92 73e9ef50 a0ede206 c7c1cb57 14467e23 5ae66845 68bb0248 7043f150 6c947cc2 268762ef 3d8f30d1 ca4ef871 bb3c6aad 63c937fd cdf14b0b 17f7399d 47feb958 506a7e50 bf09f71c 6f08addc eb2269da 843c863e eb8e6d91
9b05688c 510e527f e934440b c39fd221 5ea16f92 73e9ef50 a0ede206 c7c1cb57 14467e23 5ae66845 68bb0248 7043f150 6c947cc2 268762ef 3d8f30d1 ca4ef871 bb3c6aad 63c937fd cdf14b0b 17f7399d 47feb958 506a7e50 bf09f71c 6f08addc eb2269da 843c863e
1f83d9ab 9b05688c 510e527f e934440b c39fd221 5ea16f92 73e9ef50 a0ede206 c7c1cb57 14467e23 5ae66845 68bb0248 7043f150 6c947cc2 268762ef 3d8f30d1 ca4ef871 bb3c6aad 63c937fd cdf14b0b 17f7399d 47feb958 506a7e50 bf09f71c 6f08addc eb2269da
Universitas Sumatera Utara
65
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
A
Tabel Perubahan Nilai Variabel A, B, C, D, E, F, G, H Variabel Round 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43
B
C
D
E
F
G
H
9235fc9a 71c7e326 f798aa39 75e29ecf 8d2ebc3e 265c3357 f71baf27 70f5104d f721d82d 7d77ab41 5e384c3c 8a6dc700 8f52791a 74536e0a acdae1d3 211c00b0 9fe24ab4 a02c0e72 31ecd4de 238e0028 e30f84ab 67404e5f b97aa0a1 a0c51ba3 e16529d3 e57c6214
84624a92 9235fc9a 71c7e326 f798aa39 75e29ecf 8d2ebc3e 265c3357 f71baf27 70f5104d f721d82d 7d77ab41 5e384c3c 8a6dc700 8f52791a 74536e0a acdae1d3 211c00b0 9fe24ab4 a02c0e72 31ecd4de 238e0028 e30f84ab 67404e5f b97aa0a1 a0c51ba3 e16529d3
98450675 84624a92 9235fc9a 71c7e326 f798aa39 75e29ecf 8d2ebc3e 265c3357 f71baf27 70f5104d f721d82d 7d77ab41 5e384c3c 8a6dc700 8f52791a 74536e0a acdae1d3 211c00b0 9fe24ab4 a02c0e72 31ecd4de 238e0028 e30f84ab 67404e5f b97aa0a1 a0c51ba3
a4cde19d 98450675 84624a92 9235fc9a 71c7e326 f798aa39 75e29ecf 8d2ebc3e 265c3357 f71baf27 70f5104d f721d82d 7d77ab41 5e384c3c 8a6dc700 8f52791a 74536e0a acdae1d3 211c00b0 9fe24ab4 a02c0e72 31ecd4de 238e0028 e30f84ab 67404e5f b97aa0a1
e63764c8 ee84f170 64a6d6eb b82d8d92 0829d939 aa2a1bf0 a5623854 5573231d 03db6aac 70dacd92 03e35e7e e4d4fb6b 7a7361c0 406e3d4b dbc06e3d 710ace86 8d159af4 6b2e7c0c d1f3e385 f8e3ef4c 2fa38df1 004f814d de471d4c 5f36b208 01f1d598 88f677f8
d178af58 e63764c8 ee84f170 64a6d6eb b82d8d92 0829d939 aa2a1bf0 a5623854 5573231d 03db6aac 70dacd92 03e35e7e e4d4fb6b 7a7361c0 406e3d4b dbc06e3d 710ace86 8d159af4 6b2e7c0c d1f3e385 f8e3ef4c 2fa38df1 004f814d de471d4c 5f36b208 01f1d598
eb8e6d91 d178af58 e63764c8 ee84f170 64a6d6eb b82d8d92 0829d939 aa2a1bf0 a5623854 5573231d 03db6aac 70dacd92 03e35e7e e4d4fb6b 7a7361c0 406e3d4b dbc06e3d 710ace86 8d159af4 6b2e7c0c d1f3e385 f8e3ef4c 2fa38df1 004f814d de471d4c 5f36b208
843c863e eb8e6d91 d178af58 e63764c8 ee84f170 64a6d6eb b82d8d92 0829d939 aa2a1bf0 a5623854 5573231d 03db6aac 70dacd92 03e35e7e e4d4fb6b 7a7361c0 406e3d4b dbc06e3d 710ace86 8d159af4 6b2e7c0c d1f3e385 f8e3ef4c 2fa38df1 004f814d de471d4c
Universitas Sumatera Utara
66
44 45 46 47 48 49 50 51
A
Tabel Perubahan Nilai Variabel A, B, C, D, E, F, G, H Variabel Round 52 53 54 55 56 57 58 59 60 61 62
63
A
B
C
D
E
F
G
H
fa4e01b4 4916d342 2e19abe7 dce49dd8 8b0e251e 71c5ecbf ec2549c3 3fa846c7 ed18d6e3 da2800ea b73f5418 9cfddf72
e57c6214 fa4e01b4 4916d342 2e19abe7 dce49dd8 8b0e251e 71c5ecbf ec2549c3 3fa846c7 ed18d6e3 da2800ea b73f5418
e16529d3 e57c6214 fa4e01b4 4916d342 2e19abe7 dce49dd8 8b0e251e 71c5ecbf ec2549c3 3fa846c7 ed18d6e3 da2800ea
a0c51ba3 e16529d3 e57c6214 fa4e01b4 4916d342 2e19abe7 dce49dd8 8b0e251e 71c5ecbf ec2549c3 3fa846c7 ed18d6e3
f9f315cf fd3d4b5d d3059d64 6631f57a edbee7ef 7a2c6709 92423f45 13563a16 a1b8bf2d 2fc2d41c 925cdce6 6d13c32f
88f677f8 f9f315cf fd3d4b5d d3059d64 6631f57a edbee7ef 7a2c6709 92423f45 13563a16 a1b8bf2d 2fc2d41c 925cdce6
01f1d598 88f677f8 f9f315cf fd3d4b5d d3059d64 6631f57a edbee7ef 7a2c6709 92423f45 13563a16 a1b8bf2d 2fc2d41c
5f36b208 01f1d598 88f677f8 f9f315cf fd3d4b5d d3059d64 6631f57a edbee7ef 7a2c6709 92423f45 13563a16 a1b8bf2d
67 Universitas Sumatera Utara
Tabel Enkripsi
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
8
56
33950
9
57
52427
5
53
57119
d
100
28261
Universitas Sumatera Utara
68
Karakter
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 c c
55 99 99
52959 53687 53687
5 a b
53 97 98
57119 45171 39457
8 1 4
56 49 52
33950 24890 52371
b
98
39457
9
57
52427
8
56
33950
c
99
53687
f
102
41585
0
48
41314
e
101
33829
4
52
52371
3
51
56706
69 Universitas Sumatera Utara
70
Ciphertext = “YjU0NAozZTJlCmIwNzMKZTg5NQoyYjhmCmI3YWIKODQyNQo4Mjg2CmI3Y
WIKZDFiNwo5YTIxCmNjOTMKODQ5ZQphMjcxCjI4ZTYKMjhlNgo4NDllCjg0O WUKOWEyMQo4NDI1Cjg0OWUKYTI3MQo2MTNhCjg0MjUKNjEzYQoxMzRiC mQxYjcKYjA3MwpiMDczCjg0MjUKODQ5ZQphMTYyCjEzNGIKZGQ4Mgo5YTI xCmNjY2IKNjEzYQoyOGU2CmExNjIKMjhlNgo2ZTY1CmRkODIKZDFiNwo4N DllCjlhMjEKZGYxZgpkMWI3CjI4ZTYKZDFiNwoyOGU2CmEyNzEKMjhlNgpjY 2NiCmRmMWYKY2NjYgpkZDgyCjg0OWUKMTM0Ygo4NDI1CmQxYjcKOWEy MQpkZDgyCjEzNGIKODQyNQphMTYyCjg0OWUKY2M5MwpkZDgyCmQxYjcK MjhlNgphMTYyCjZlNjUKY2VkZgpjZWRmCjI4ZTYKNjEzYQo4NDllCmQxYjcK ZGQ4MgphMTYyCmNjOTMKZDFiNwpiMDczCjg0MjUKY2VkZgpkMWI3CmQx YjcKOWEyMQpkMWI3Cjg0MjUKY2NjYgo2ZTY1Cjg0MjUKY2NjYgpjZWRmC mExNjIKY2NjYgo4NDllCmNjOTMKY2NjYgoyOGU2Cjg0MjUKZGYxZgpiMDcz CjlhMjEKY2NjYgphMjcxCmNjOTMKNjEzYQphMjcxCmExNjIKODQyNQoyOGU 2CmQxYjcKZGYxZgpjZWRmCjg0MjUKY2M5MwphMjcxCmNjOTMKODQ5ZQo 2MTNhCmNjOTMKODQ5ZQphMTYyCmRkODIKY2M5MwpjY2NiCmNlZGYKY jA3MwpkMWI3CmIwNzMKOWEyMQpjZWRmCjI4ZTYKZGQ4MgphMTYyCg== ”
Universitas Sumatera Utara
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
33950
56
8
52427
57
9
57119
53
5
28261
100
d
71 Universitas Sumatera Utara
Tabel Dekripsi tim 52959
ASCII 55
Karakter
C
ASCII
Karakter
C
ASCII
Karakter
C
ASCII
Karakter
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
33829
101
e
52371
52
4
56706
51
3
72 Universitas Sumatera Utara
73
Listing Program
Main. java package controller; import import import import import import
java.io.File; java.io.FileInputStream; java.io.FileReader; java.io.FileWriter; java.math.BigInteger; java.util.Base64;
import javax.swing.text.Document; import javax.swing.text.rtf.RTFEditorKit; import import import import
org.apache.poi.hwpf.HWPFDocument; org.apache.poi.hwpf.extractor.WordExtractor; org.apache.poi.xwpf.extractor.XWPFWordExtractor; org.apache.poi.xwpf.usermodel.XWPFDocument;
import import import import import import import import import import import import import import
view.RootLayoutController; javafx.application.Application; javafx.fxml.FXMLLoader; javafx.scene.Node; javafx.scene.Scene; javafx.scene.control.ButtonType; javafx.scene.control.Dialog; javafx.scene.control.TextArea; javafx.scene.control.TextField; javafx.scene.layout.AnchorPane; javafx.stage.FileChooser; javafx.stage.FileChooser.ExtensionFilter; javafx.stage.Stage; 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; public void setXY(double screenX, double screenY) {
Universitas Sumatera Utara
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) refresh("rRSA", ne);
Universitas Sumatera Utara
75
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()) rlController.qRSATF.setText(RSA_Modified.getInstance().getQ().toString());
Universitas Sumatera Utara
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(""); rlController.QyECDSATF.setText(""); rlController.dECDSA2TF.setText(""); rlController.QxECDSA2TF.setText(""); rlController.QyECDSA2TF.setText("");
Universitas Sumatera Utara
77
} else if (var.equals("pRSA") || var.equals("qRSA") || if (var.equals("pRSA")) { flagP = 0b000; rlController.pRSATF.setText("Digit untuk kunci harus } else if (var.equals("qRSA")) { flagQ = 0b000; rlController.qRSATF.setText("Digit untuk kunci harus } else { flagR = 0b000; rlController.rRSATF.setText("Digit untuk kunci harus } rlController.nRSATF.setText(""); rlController.totientRSATF.setText(""); rlController.eRSATF.setText(""); rlController.dRSATF.setText(""); rlController.nRSA2TF.setText(""); rlController.nRSA3TF.setText(""); rlController.eRSA2TF.setText(""); rlController.dRSA2TF.setText("");
var.equals("rRSA")) {
lebih dari 1");
lebih dari 1");
lebih dari 1");
} } 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(); } else if (fileExtension.equals("rtf")) { RTFEditorKit extractrtf = new RTFEditorKit(); Document rtfD = extractrtf.createDefaultDocument(); extractrtf.read(new FileInputStream(path), rtfD, 0); result = rtfD.getText(0, rtfD.getLength());
Universitas Sumatera Utara
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) { } } String dialog = "";
Universitas Sumatera Utara
79
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); String r, s; BigInteger d;
Universitas Sumatera Utara
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 { r = revert(rlController.rECDSA2TF.getText()); s = revert(rlController.sECDSA2TF.getText()); Qx = revert(rlController.QxECDSA2TF.getText()); Qy = revert(rlController.QyECDSA2TF.getText()); }
Universitas Sumatera Utara
81
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() { boolean v = validateNode(rlController.dRSA2TF), v1 = validateNode(rlController.nRSA3TF);
Universitas Sumatera Utara
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
dialog = new Dialog(); dialog.initOwner(primaryStage); dialog.setTitle("Terjadi kesalahan"); dialog.setContentText(this.dialog); dialog.getDialogPane().getButtonTypes().add(ButtonType.OK); dialog.showAndWait(); }
Universitas Sumatera Utara
83
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(); } return Instance; }
Universitas Sumatera Utara
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) .mod(Elliptic_Curve.n)).toString().length() != digit || !Elliptic_Curve.checkPoint(
Universitas Sumatera Utara
85
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) { } }
Universitas Sumatera Utara
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; } }
Universitas Sumatera Utara
87
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]; int[] test = new int[s];
Universitas Sumatera Utara
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 */ static BigInteger generatePrime(int length) {
Universitas Sumatera Utara
89
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) { BigInteger p1;
Universitas Sumatera Utara
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 BigInteger getQ() { return q;
Universitas Sumatera Utara
91
} 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(); } } private String ciphertext = "", plaintext = "";
Universitas Sumatera Utara
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"); // private static String SEED =
Universitas Sumatera Utara
93
// "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() {} public thirdPoint(BigInteger Px, BigInteger Py) { this.lambda = lambda(Px, Py);
Universitas Sumatera Utara
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; }
Universitas Sumatera Utara
95
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; B = C.subtract(q.multiply(B));
Universitas Sumatera Utara
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 0x3956c25b, 0x12835b01, 0x9bdc06a7, 0x240ca1cc, 0x983e5152, 0xd5a79147, 0x4d2c6dfc, 0x92722c85, 0xd192e819, 0x1e376c08, 0x5b9cca4f, 0x8cc70208,
int[] { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 };
long A, B, C, D, E, F, G, H, T1, T2; ArrayList a = new ArrayList<>(); long _length; // Pengubahan pesan dengan encoding for (Byte i : message.getBytes()) { a.add(i); }
Universitas Sumatera Utara
97
_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]; B = h[1]; C = h[2]; D = h[3]; E = h[4]; F = h[5]; G = h[6]; H = h[7];
Universitas Sumatera Utara
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] h[1] h[2] h[3] h[4] h[5] h[6] h[7]
= = = = = = = =
(A (B (C (D (E (F (G (H
+ + + + + + + +
h[0]) h[1]) h[2]) h[3]) h[4]) h[5]) h[6]) h[7])
% % % % % % % %
0x100000000L; 0x100000000L; 0x100000000L; 0x100000000L; 0x100000000L; 0x100000000L; 0x100000000L; 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); } private int sigma1(int X) {
Universitas Sumatera Utara
99
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); } }
Universitas Sumatera Utara