Implementasi Modifikasi Sistem Kriptografi RSA dan Elliptic Curve Digital Signature Algorithm (ECDSA)

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 = 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 (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) > 3) & 0x1FFFFFFF));
}
private int RL(int a, int n) {
return a > (32 - n) & ((0x01