-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfenam_cipher_test.go
123 lines (118 loc) · 2.33 KB
/
fenam_cipher_test.go
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package fenam_cipher
import "testing"
func Test_asciiToBinary(t *testing.T) {
type args struct {
number int
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
{
args: args{
number: 'A',
},
want: "1000001",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := intToBinaryString(tt.args.number); got != tt.want {
t.Errorf("intToBinaryString() = %v, want %v", got, tt.want)
}
})
}
}
func Test_fromBinaryString(t *testing.T) {
type args struct {
binaryString string
}
tests := []struct {
name string
args args
want int
}{
// TODO: Add test cases.
{
args: args{
binaryString: "1010000",
},
want: 'P',
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := fromBinaryString(tt.args.binaryString); got != tt.want {
t.Errorf("fromBinaryString() = %v, want %v", got, tt.want)
}
})
}
}
func TestEncrypt(t *testing.T) {
type args struct {
asciiText string
security []string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
// TODO: Add test cases.
{
args: args{
asciiText: "HELLO",
security: []string{"STUDY"},
},
want: "00110110010001001100100010000010110",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Encrypt(tt.args.asciiText, tt.args.security...)
if (err != nil) != tt.wantErr {
t.Errorf("Encrypt() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Encrypt() got = %v, want %v", got, tt.want)
}
})
}
}
func TestDecrypt(t *testing.T) {
type args struct {
encryptBinaryText string
securityKey []string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
// TODO: Add test cases.
{
args: args{
encryptBinaryText: "00110110010001001100100010000010110",
securityKey: []string{"STUDY"},
},
want: "HELLO",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Decrypt(tt.args.encryptBinaryText, tt.args.securityKey...)
if (err != nil) != tt.wantErr {
t.Errorf("Decrypt() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Decrypt() got = %v, want %v", got, tt.want)
}
})
}
}