-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
78 lines (56 loc) · 1.36 KB
/
main.go
File metadata and controls
78 lines (56 loc) · 1.36 KB
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
package main
import (
"CSS577/functions"
"bufio"
"fmt"
"os"
)
func main() {
var executionType string
in := bufio.NewScanner(os.Stdin)
fmt.Print("1: Encryption, 2: Decryption: ")
//Read executionType input
in.Scan()
executionType = in.Text()
switch executionType {
//ENCRYPTION OPTION
case "1":
var password, inputText string
//Initialise structs
var enc helper.Parameters
var meta helper.Metadata
fmt.Println("Enter Text:")
//Read user input
in.Scan()
inputText = in.Text()
//Check if input is empty
helper.CheckEmptyString(inputText)
fmt.Print("Enter your password: ")
in.Scan()
password = in.Text()
helper.CheckEmptyString(password)
//Use the struct to store the values from the Ui function and pass them to the encryption function
enc, meta = helper.Ui()
err := helper.Encryption(password, inputText, enc, meta)
helper.CheckError(err)
break
//DECRYPTION OPTION
case "2":
var file, password string
fmt.Print("Enter full path of file: ")
in.Scan()
file = in.Text()
helper.CheckEmptyString(file)
fmt.Print("Enter the password: ")
in.Scan()
password = in.Text()
helper.CheckEmptyString(password)
plainText, err := helper.Decryption(file, password)
helper.CheckError(err)
fmt.Printf("The decrypted text is: \n%s\n", plainText)
break
default:
fmt.Println("Invalid choice")
os.Exit(1)
}
}