I implemented my first algorithm in golang - the caesar cipher. Is there something i could do more efficiently? I am quite new to go and any improvement suggestions are welcome.
package main
import "fmt"
// +1 encoding, -1 decoding
func main() {
var text string
var choice int
var shift int
fmt.Print("Text: ")
fmt.Scanf("%s", &text)
fmt.Print("+1 encoding, -1 decoding: ")
fmt.Scanf("%d", &choice)
fmt.Print("Shift: ")
fmt.Scanf("%d", &shift)
fmt.Println(cipher(text, choice, shift))
}
func cipher(text string, choice int, shift int) string{
chars := []rune(text)
var result string
for i := 0; i < len(chars); i++ {
if chars[i] >= 'a' && chars[i] <= 'z' || chars[i] >= 'A' && chars[i] <= 'Z' {
dchar := chars[i] + rune(shift*choice)
if dchar >= 'a' && dchar <= 'z' || dchar >= 'A' && dchar <= 'Z' {
result += string(dchar)
} else {
result += string(dchar + rune(-26 * choice))
}
} else {
result += string(chars[i])
}
}
return result
}