wust校园网web认证
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trailblazer2/app/cmd/main.go

41 lines
701 B

package main
import (
"fmt"
)
func main() {
a := "123456"
b := true
fmt.Println(s(a, b))
}
func s(origin string, b bool) (result []rune) {
data := []rune(origin)
dataLen := len(origin)
resultLen := (dataLen / 4) + 1
if b {
result = make([]rune, resultLen+1)
result[resultLen] = rune(resultLen)
} else {
result = make([]rune, resultLen)
}
for i := 0; i < dataLen; i += 4 {
result[i>>2] =
getCharAt(data, i, dataLen) | getCharAt(data, i+1, dataLen)<<8 | getCharAt(data, i+2, dataLen)<<16 |
getCharAt(data, i+3, dataLen)<<24
}
return result
}
func getCharAt(str []rune, index int, length int) rune {
if index >= length {
return 0
} else {
return str[index]
}
}