reworked sharecode return

This commit is contained in:
2022-11-28 12:48:19 +01:00
parent 43c91b694e
commit 1ac07c2f5a
4 changed files with 21 additions and 22 deletions

View File

@@ -9,7 +9,8 @@ import (
)
//goland:noinspection SpellCheckingInspection
var DICT = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789"
const Base57Chars = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789"
var sharecodeRexEx = regexp.MustCompile(`^CSGO(?:-?\w{5}){5}$`)
func DecodeSharecode(code string) (matchID, outcomeID uint64, tokenID uint16, err error) {
@@ -21,11 +22,11 @@ func DecodeSharecode(code string) (matchID, outcomeID uint64, tokenID uint16, er
chars := ReverseString(strings.Split(cleanCode, ""))
bigInt := new(big.Int)
dictLenBig := big.NewInt(int64(len(DICT)))
dictLenBig := big.NewInt(int64(len(Base57Chars)))
for _, c := range chars {
bigInt.Mul(bigInt, dictLenBig)
bigInt.Add(bigInt, big.NewInt(int64(strings.Index(DICT, c))))
bigInt.Add(bigInt, big.NewInt(int64(strings.Index(Base57Chars, c))))
}
if bigInt.BitLen() > 144 { //nolint:gomnd