| 80 | } |
| 81 | |
| 82 | func TestEncryptDecrypt(t *testing.T) { |
| 83 | text := []rune("Test text for checking the algorithm") |
| 84 | key1 := "testKey" |
| 85 | key2 := "Test Key2" |
| 86 | encrypt, errEncrypt := Encrypt(text, key1) |
| 87 | if errEncrypt != nil { |
| 88 | t.Error(errEncrypt) |
| 89 | } |
| 90 | decrypt, errDecrypt := Decrypt(encrypt, key1) |
| 91 | if errDecrypt != nil { |
| 92 | t.Error(errDecrypt) |
| 93 | } |
| 94 | if !reflect.DeepEqual(decrypt, text) { |
| 95 | t.Errorf("The string was not decrypted correctly %q %q", decrypt, text) |
| 96 | } |
| 97 | decrypt, _ = Decrypt([]rune(encrypt), key2) |
| 98 | if reflect.DeepEqual(decrypt, text) { |
| 99 | t.Errorf("The string was decrypted with a different key: %q %q", decrypt, text) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func FuzzTransposition(f *testing.F) { |
| 104 | for _, transpositionTestInput := range texts { |