TutorialEdge

Challenge 17 - Decode the Secret

Welcome, everyone to the discussion thread for the 17th Go challenge posted to the site :tada:

Feel free to show us how you solved the challenge by posting your solutions below!

Solution:

package main

import (
	"encoding/base64"
	"fmt"
)

func DecodeSecret(message string) string {
	data, err := base64.StdEncoding.DecodeString(message)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(data))

	var secret []rune
	for _, char := range data {
		fmt.Println(rune(char + 1))
		secret = append(secret, rune(char-1))
	}

	fmt.Println(secret)

	return string(secret)
}

func main() {
	fmt.Println("Decode the Secret")

	message := "VEZEU0ZVVFVTSk9I"
	result := DecodeSecret(message)
	fmt.Println(result)

}

package main

import (
	"encoding/base64"
	"fmt"
)

func DecodeSecret(message string) string {
  data, err := base64.StdEncoding.DecodeString(message)
  if err != nil {
    fmt.Println("error:", err)
    return ""
  }
  decoded := make([]rune, 0, len(data))
  
  for _, c := range data {
    decoded = append(decoded, rune(int(c)-1))
  }
  
  return string(decoded)
}

func main() {
  fmt.Println("Decode the Secret")

  message := "VEZEU0ZVVFVTSk9I"
  result := DecodeSecret(message)
  fmt.Println(result)

}