-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go.bak
80 lines (68 loc) · 2.02 KB
/
main.go.bak
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"skripsi/aes"
"skripsi/chaos"
"skripsi/cmd"
"skripsi/rsa"
"skripsi/util"
)
func main() {
mode, err := cmd.SelectMode()
if err != nil {
fmt.Println(err)
}
fmt.Println(mode)
algo, err := cmd.SelectType()
if err != nil {
fmt.Println(err)
}
fmt.Println(algo)
inputImage, _ := cmd.SelectInputImage()
outputImage, _ := cmd.OutputImageName()
plainImage := &util.ImageFile{Path: inputImage}
resultImage := &util.ImageFile{Path: outputImage}
bounds, inputPlainColor := plainImage.OpenImage()
if mode == "encrypt" {
if algo == "AES" {
password, _ := cmd.InputPassword()
fmt.Println(password)
key, _ := aes.NewKey(password)
encryptedColor := key.AESEncryptImage(inputPlainColor)
resultImage.WriteImage(&bounds, encryptedColor)
} else if algo == "RSA" {
pathKey, _ := cmd.InputPublicKey()
key, _ := rsa.LoadPublicKey(pathKey)
encryptedColor := key.EncryptImage(&inputPlainColor)
resultImage.WriteImage(&bounds, encryptedColor)
} else if algo == "Chaos" {
cmd.SelectSequence()
k, _ := cmd.InputK()
u, _ := cmd.InputU()
x0, _ := cmd.InputX0()
key, _ := chaos.NewChaosKey(&bounds, 200, x0, u, k, 5)
encryptedColor := key.ChaosEncrypt(&bounds, &inputPlainColor)
resultImage.WriteImage(&bounds, encryptedColor)
}
} else if mode == "decrypt" {
if algo == "AES" {
password, _ := cmd.InputPassword()
key, _ := aes.NewKey(password)
encryptedColor := key.AESDecryptImage(inputPlainColor)
resultImage.WriteImage(&bounds, encryptedColor)
} else if algo == "RSA" {
pathKey, _ := cmd.InputPrivateKey()
key, _ := rsa.LoadKey(pathKey)
encryptedColor := key.EncryptImage(&inputPlainColor)
resultImage.WriteImage(&bounds, encryptedColor)
} else if algo == "Chaos" {
cmd.SelectSequence()
k, _ := cmd.InputK()
u, _ := cmd.InputU()
x0, _ := cmd.InputX0()
key, _ := chaos.NewChaosKey(&bounds, 200, x0, u, k, 5)
encryptedColor := key.ChaosDecrypt(&bounds, &inputPlainColor)
resultImage.WriteImage(&bounds, encryptedColor)
}
}
}