|
|
|
@ -38,12 +38,14 @@ func formatOutput(encoded []int, groupSize int, lineSize int) string {
|
|
|
|
|
output.WriteString(fmt.Sprintf("%02d", num))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply grouping
|
|
|
|
|
finalOutput := output.String()
|
|
|
|
|
var groupedOutput strings.Builder
|
|
|
|
|
counter := 0
|
|
|
|
|
groupCounter := 0
|
|
|
|
|
|
|
|
|
|
// Check if a group size is provided
|
|
|
|
|
if groupSize > 0 {
|
|
|
|
|
// Apply grouping and line size limits
|
|
|
|
|
for i := 0; i < len(finalOutput); i += groupSize {
|
|
|
|
|
if i+groupSize < len(finalOutput) {
|
|
|
|
|
groupedOutput.WriteString(finalOutput[i:i+groupSize] + " ")
|
|
|
|
@ -59,6 +61,19 @@ func formatOutput(encoded []int, groupSize int, lineSize int) string {
|
|
|
|
|
groupCounter = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// No group size specified, handle line size by number of characters
|
|
|
|
|
for i := 0; i < len(finalOutput); i++ {
|
|
|
|
|
groupedOutput.WriteByte(finalOutput[i])
|
|
|
|
|
counter++
|
|
|
|
|
|
|
|
|
|
// Check if we reached the line size
|
|
|
|
|
if lineSize > 0 && counter >= lineSize && i+1 < len(finalOutput) {
|
|
|
|
|
groupedOutput.WriteString("\n")
|
|
|
|
|
counter = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return strings.TrimSpace(groupedOutput.String())
|
|
|
|
|
}
|
|
|
|
@ -67,7 +82,7 @@ func main() {
|
|
|
|
|
// Define command-line flags
|
|
|
|
|
shift := flag.Int("s", 0, "Shift amount for the cipher")
|
|
|
|
|
groupSize := flag.Int("g", 0, "Group size for output formatting")
|
|
|
|
|
lineSize := flag.Int("l", 0, "Line size by number of groups")
|
|
|
|
|
lineSize := flag.Int("l", 0, "Line size by number of groups or characters if no group size is specified")
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
// Read input from stdin
|
|
|
|
|