{"record":{"id":"9357ee7c3dcdb9c6","repo":"TheAlgorithms/Go","slug":"failed-decipher-w","errorCode":null,"errorMessage":"failed decipher: %w","messagePattern":"failed decipher: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cipher/polybius/polybius.go","lineNumber":71,"sourceCode":"\tencryptedText := \"\"\n\tfor _, char := range strings.ToUpper(text) {\n\t\tencryptedChar, err := p.encipher(char)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed encipher: %w\", err)\n\t\t}\n\t\tencryptedText += encryptedChar\n\t}\n\treturn encryptedText, nil\n}\n\n// Decrypt decrypts with polybius encryption\nfunc (p *Polybius) Decrypt(text string) (string, error) {\n\tchars := []rune(strings.ToUpper(text))\n\tdecryptedText := \"\"\n\tfor i := 0; i < len(chars); i += 2 {\n\t\tdecryptedChar, err := p.decipher(chars[i:int(math.Min(float64(i+2), float64(len(chars))))])\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed decipher: %w\", err)\n\t\t}\n\t\tdecryptedText += decryptedChar\n\t}\n\treturn decryptedText, nil\n}\n\nfunc (p *Polybius) encipher(char rune) (string, error) {\n\tindex := strings.IndexRune(p.key, char)\n\tif index < 0 {\n\t\treturn \"\", fmt.Errorf(\"%q does not exist in keys\", char)\n\t}\n\trow := index / p.size\n\tcol := index % p.size\n\tchars := []rune(p.characters)\n\treturn string([]rune{chars[row], chars[col]}), nil\n}\n\nfunc (p *Polybius) decipher(chars []rune) (string, error) {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/cipher/polybius/polybius.go#L53-L89","documentation":"Polybius.Decrypt wraps a decipher failure for a rune pair (unknown characters or odd-length remainder) with fmt.Errorf %w, returning an empty string and a wrapped error identifying the failing symbol.","triggerScenarios":"Thrown at cipher/polybius/polybius.go:71 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Unwrap the cause with errors.Is/As before deciding recovery","Validate ciphertext length is even and characters exist in the square before decrypting","Decrypt in pairs to locate the exact bad position"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}