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.
55 lines
886 B
55 lines
886 B
2 years ago
|
package common
|
||
|
|
||
|
import (
|
||
|
"math"
|
||
|
)
|
||
|
|
||
|
/*
|
||
|
@Auth:ShenZ
|
||
|
@Description: 用于UUID 加密算法
|
||
|
*/
|
||
|
|
||
|
func StringToArray(intput string) []int {
|
||
|
output := []int{}
|
||
|
for _, v := range intput {
|
||
|
output = append(output, int(v))
|
||
|
}
|
||
|
for i, j := 0, len(output)-1; i < j; i, j = i+1, j-1 {
|
||
|
output[i], output[j] = output[j], output[i]
|
||
|
}
|
||
|
return output
|
||
|
}
|
||
|
func GetInput(intput string) <-chan int {
|
||
|
out := make(chan int)
|
||
|
go func() {
|
||
|
for _, b := range StringToArray(intput) {
|
||
|
out <- b
|
||
|
}
|
||
|
close(out)
|
||
|
}()
|
||
|
return out
|
||
|
}
|
||
|
func SQ(in <-chan int) <-chan int {
|
||
|
out := make(chan int)
|
||
|
var base, i float64 = 2, 0
|
||
|
go func() {
|
||
|
for n := range in {
|
||
|
out <- (n - 48) * int(math.Pow(base, i))
|
||
|
i++
|
||
|
}
|
||
|
close(out)
|
||
|
}()
|
||
|
return out
|
||
|
}
|
||
|
|
||
|
func ToInt(intput string) int {
|
||
|
//intput := "101010101110110"
|
||
|
c := GetInput(intput)
|
||
|
out := SQ(c)
|
||
|
sum := 0
|
||
|
for o := range out {
|
||
|
sum += o
|
||
|
}
|
||
|
return sum
|
||
|
}
|