@@ -2,9 +2,40 @@ package polybius_test
2
2
3
3
import (
4
4
"TheAlgorithms/Go/ciphers/polybius"
5
+ "fmt"
6
+ "log"
5
7
"testing"
6
8
)
7
9
10
+ func ExampleNewPolybius () {
11
+ // initialize
12
+ const (
13
+ plainText = "HogeFugaPiyoSpam"
14
+ size = 5
15
+ characters = "HogeF"
16
+ key = "abcdefghijklmnopqrstuvwxy"
17
+ )
18
+ p , err := polybius .NewPolybius (key , size , characters )
19
+ if err != nil {
20
+ log .Fatalf ("failed NewPolybius: %v" , err )
21
+ }
22
+ encryptedText , err := p .Encrypt (plainText )
23
+ if err != nil {
24
+ log .Fatalf ("failed Encrypt: %v" , err )
25
+ }
26
+ fmt .Printf ("Encrypt=> plainText: %s, encryptedText: %s\n " , plainText , encryptedText )
27
+
28
+ decryptedText , err := p .Decrypt (encryptedText )
29
+ if err != nil {
30
+ log .Fatalf ("failed Decrypt: %v" , err )
31
+ }
32
+ fmt .Printf ("Decrypt=> encryptedText: %s, decryptedText: %s\n " , encryptedText , decryptedText )
33
+
34
+ // Output:
35
+ // Encrypt=> plainText: HogeFugaPiyoSpam, encryptedText: OGGFOOHFOHFHOOHHEHOEFFGFEEEHHHGG
36
+ // Decrypt=> encryptedText: OGGFOOHFOHFHOOHHEHOEFFGFEEEHHHGG, decryptedText: HOGEFUGAPIYOSPAM
37
+ }
38
+
8
39
func TestNewPolybius (t * testing.T ) {
9
40
t .Parallel ()
10
41
cases := []struct {
@@ -46,7 +77,7 @@ func TestPolybiusEncrypt(t *testing.T) {
46
77
want string
47
78
}{
48
79
{
49
- name : "correct encryption" , text : "hoge " , want : "OGGFOOHF " ,
80
+ name : "correct encryption" , text : "HogeFugaPiyoSpam " , want : "OGGFOOHFOHFHOOHHEHOEFFGFEEEHHHGG " ,
50
81
},
51
82
{
52
83
name : "invalid encryption" , text : "hogz" , want : "failed encipher: Z does not exist in keys" ,
@@ -55,7 +86,7 @@ func TestPolybiusEncrypt(t *testing.T) {
55
86
// initialize
56
87
const (
57
88
size = 5
58
- characters = "HogeFuga "
89
+ characters = "HogeF "
59
90
key = "abcdefghijklmnopqrstuvwxy"
60
91
)
61
92
p , err := polybius .NewPolybius (key , size , characters )
@@ -84,7 +115,7 @@ func TestPolybiusDecrypt(t *testing.T) {
84
115
want string
85
116
}{
86
117
{
87
- name : "correct decryption" , text : "OGGFOOHF " , want : "HOGE " ,
118
+ name : "correct decryption" , text : "OGGFOOHFOHFHOOHHEHOEFFGFEEEHHHGG " , want : "HOGEFUGAPIYOSPAM " ,
88
119
},
89
120
{
90
121
name : "invalid decryption(position of even number)" , text : "hogz" , want : "failed decipher: Z does not exist in characters" ,
0 commit comments