mhw (1) [Avatar] Offline
#1
Here is another solution using strings.Repeat:

package main

import "fmt"
import "strings"

func main() {
	cipherText := "CSOITEUIWUIZNSROCNKFD"
	keyword := "GOLANG"
	s := len(cipherText)
	k := len(keyword)
	key := strings.Repeat(keyword, s/k) + keyword[:s%k] // key = "GOLANGGOLANGGOLANGGOL"
	message := ""

	for i, _ := range cipherText {
		if cipherText[i] >= key[i] {
			message += string('A' + (cipherText[i] - key[i]))
		} else {
			message += string('Z' + 1 + (cipherText[i] - key[i]))
		}
	}

	fmt.Println(message)
}


Link to the solution in Go's Playground: https://play.golang.org/p/Em-lUGjRjL