{"record":{"id":"e2125b418c23b132","repo":"TheAlgorithms/Go","slug":"errnotexttoencrypt","errorCode":"ErrNoTextToEncrypt","errorMessage":"%w: cannot encrypt a text, %q, ending with the placeholder char %q","messagePattern":"%w: cannot encrypt a text, %q, ending with the placeholder char %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cipher/transposition/transposition.go","lineNumber":64,"sourceCode":"\t\tif wordSet[i] == subString {\n\t\t\treturn i\n\t\t}\n\t}\n\treturn 0\n}\n\nfunc Encrypt(text []rune, keyWord string) ([]rune, error) {\n\tkey := getKey(keyWord)\n\tkeyLength := len(key)\n\ttextLength := len(text)\n\tif keyLength <= 0 {\n\t\treturn nil, ErrKeyMissing\n\t}\n\tif textLength <= 0 {\n\t\treturn nil, ErrNoTextToEncrypt\n\t}\n\tif text[len(text)-1] == placeholder {\n\t\treturn nil, fmt.Errorf(\"%w: cannot encrypt a text, %q, ending with the placeholder char %q\", ErrNoTextToEncrypt, text, placeholder)\n\t}\n\tn := textLength % keyLength\n\n\tfor i := 0; i < keyLength-n; i++ {\n\t\ttext = append(text, placeholder)\n\t}\n\ttextLength = len(text)\n\tvar result []rune\n\tfor i := 0; i < textLength; i += keyLength {\n\t\ttransposition := make([]rune, keyLength)\n\t\tfor j := 0; j < keyLength; j++ {\n\t\t\ttransposition[key[j]-1] = text[i+j]\n\t\t}\n\t\tresult = append(result, transposition...)\n\t}\n\treturn result, nil\n}\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/cipher/transposition/transposition.go#L46-L82","documentation":"Encrypt pads text with a placeholder rune; input that already ends with that placeholder would make correct unpadding ambiguous on decrypt, so Encrypt refuses it, wrapping ErrNoTextToEncrypt with the text and placeholder shown.","triggerScenarios":"Thrown at cipher/transposition/transposition.go:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Strip or escape the placeholder character from the plaintext before encrypting","Choose a placeholder guaranteed absent from your plaintext alphabet","Detect via errors.Is(err, ErrNoTextToEncrypt) and sanitize then retry"],"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"}