{"record":{"id":"f4fa1a300bed0e74","repo":"TheAlgorithms/Go","slug":"provided-string-q-should-only-contain-latin-chara","errorCode":null,"errorMessage":"provided string %q should only contain latin characters","messagePattern":"provided string %q should only contain latin characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cipher/polybius/polybius.go","lineNumber":35,"sourceCode":"\tsize       int\n\tcharacters string\n\tkey        string\n}\n\n// NewPolybius returns a pointer to object of Polybius.\n// If the size of \"chars\" is longer than \"size\",\n// \"chars\" are truncated to \"size\".\nfunc NewPolybius(key string, size int, chars string) (*Polybius, error) {\n\tif size < 0 {\n\t\treturn nil, fmt.Errorf(\"provided size %d cannot be negative\", size)\n\t}\n\tkey = strings.ToUpper(key)\n\tif size > len(chars) {\n\t\treturn nil, fmt.Errorf(\"provided size %d is too small to use to slice string %q of len %d\", size, chars, len(chars))\n\t}\n\tfor _, r := range chars {\n\t\tif (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') {\n\t\t\treturn nil, fmt.Errorf(\"provided string %q should only contain latin characters\", chars)\n\t\t}\n\t}\n\tchars = strings.ToUpper(chars)[:size]\n\tfor i, r := range chars {\n\t\tif strings.ContainsRune(chars[i+1:], r) {\n\t\t\treturn nil, fmt.Errorf(\"%q contains same character %q\", chars[i+1:], r)\n\t\t}\n\t}\n\n\tif len(key) != size*size {\n\t\treturn nil, fmt.Errorf(\"len(key): %d must be as long as size squared: %d\", len(key), size*size)\n\t}\n\treturn &Polybius{size, chars, key}, nil\n}\n\n// Encrypt encrypts with polybius encryption\nfunc (p *Polybius) Encrypt(text string) (string, error) {\n\tencryptedText := \"\"","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/cipher/polybius/polybius.go#L17-L53","documentation":"Constructor validation error from NewPolybius: while scanning the chars string the code found a rune outside a-z / A-Z; the Latin-square character set may only contain ASCII letters, so any other symbol in the input triggers this error.","triggerScenarios":"Thrown at cipher/polybius/polybius.go:35 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Strip non-latin characters from the input alphabet before constructing","Map non-latin letters to latin equivalents (transliteration) before encryption","Extend the cipher design if non-latin alphabets must be supported"],"exampleFix":null,"handlingStrategy":"validation","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"}