{"record":{"id":"31318eaef366ea68","repo":"TheAlgorithms/Go","slug":"q-does-not-exist-in-keys","errorCode":null,"errorMessage":"%q does not exist in keys","messagePattern":"%q does not exist in keys","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cipher/polybius/polybius.go","lineNumber":81,"sourceCode":"\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) {\n\tif len(chars) != 2 {\n\t\treturn \"\", fmt.Errorf(\"the size of \\\"chars\\\" must be even\")\n\t}\n\trow := strings.IndexRune(p.characters, chars[0])\n\tif row < 0 {\n\t\treturn \"\", fmt.Errorf(\"%c does not exist in characters\", chars[0])\n\t}\n\tcol := strings.IndexRune(p.characters, chars[1])\n\tif col < 0 {\n\t\treturn \"\", fmt.Errorf(\"%c does not exist in characters\", chars[1])","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/cipher/polybius/polybius.go#L63-L99","documentation":"encipher looks up the character with strings.IndexRune in the cipher key; index -1 means the character (e.g. a letter excluded from the square, or a digit/symbol) cannot be encoded, so it names the offending rune.","triggerScenarios":"Thrown at cipher/polybius/polybius.go:81 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove or transliterate unsupported characters before encrypting","Normalize text to uppercase and merge I/J to match the square's alphabet","Extend the key alphabet to cover needed characters"],"exampleFix":null,"handlingStrategy":"type-guard","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"}