47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func decodeBase64ToIntArray(encodedString string) ([]int, error) {
|
|
// Decode the base64 string
|
|
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decoding base64: %w", err)
|
|
}
|
|
|
|
// Convert bytes to string
|
|
decodedString := string(decodedBytes)
|
|
|
|
// Split the string by commas
|
|
stringSlice := strings.Split(decodedString, ",")
|
|
|
|
// Convert each string to an integer
|
|
intSlice := make([]int, len(stringSlice))
|
|
for i, s := range stringSlice {
|
|
num, err := strconv.Atoi(s)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error converting string to int: %w", err)
|
|
}
|
|
intSlice[i] = num
|
|
}
|
|
|
|
return intSlice, nil
|
|
}
|
|
|
|
func main2() {
|
|
encodedString := "MSwxMSwzMiw1MCw5OCw1Nyw1Myw1NywxMDIsNTAsNTQsNTIsNTYsMTAyLDEwMCwxMDAsOTksNTEsNTQsNTcsMTAwLDk3LDEwMCwxMDIsMTAxLDU0LDQ5LDUzLDk5LDQ4LDEwMCw0OSw1NCwxMDIsNTI="
|
|
|
|
intArray, err := decodeBase64ToIntArray(encodedString)
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
return
|
|
}
|
|
|
|
fmt.Println("Decoded integer array:", intArray)
|
|
}
|