MCPcopy
hub / github.com/TheAlgorithms/Go / FuzzPolybius

Function FuzzPolybius

cipher/polybius/polybius_test.go:154–190  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

152}
153
154func FuzzPolybius(f *testing.F) {
155 const (
156 size = 5
157 characters = "HogeF"
158 key = "abcdefghijklmnopqrstuvwxy"
159 )
160 f.Add(size, characters, key)
161 f.Fuzz(func(t *testing.T, size int, characters, key string) {
162 p, err := NewPolybius(key, size, characters)
163 switch {
164 case err == nil:
165 case strings.Contains(err.Error(), "cannot be negative"),
166 strings.Contains(err.Error(), "is too small"),
167 strings.Contains(err.Error(), "should only contain latin characters"),
168 strings.Contains(err.Error(), "contains same character"),
169 strings.Contains(err.Error(), "must be as long as size squared"):
170 return
171 default:
172 t.Fatalf("unexpected error when creating a new polybius variable: %v", err)
173 }
174 encrypted, err := p.Encrypt(characters)
175 switch {
176 case err == nil:
177 case strings.Contains(err.Error(), "does not exist in keys"):
178 return
179 default:
180 t.Fatalf("unexpected error during encryption: %v", err)
181 }
182 decrypted, err := p.Decrypt(encrypted)
183 if err != nil {
184 t.Fatalf("unexpected error during decryption: %v", err)
185 }
186 if decrypted != strings.ToUpper(characters) {
187 t.Errorf("Expecting output to match with %q but was %q", characters, decrypted)
188 }
189 })
190}

Callers

nothing calls this directly

Calls 5

EncryptMethod · 0.95
DecryptMethod · 0.95
NewPolybiusFunction · 0.85
ContainsMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected