本文整理汇总了Golang中math/big.Int.Uint64方法的典型用法代码示例。如果您正苦于以下问题:Golang Int.Uint64方法的具体用法?Golang Int.Uint64怎么用?Golang Int.Uint64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math/big.Int
的用法示例。
在下文中一共展示了Int.Uint64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var iban string
var r, s, t, st []string
u := new(big.Int)
v := new(big.Int)
w := new(big.Int)
iban = "GB82 TEST 1234 5698 7654 32"
r = strings.Split(iban, " ")
s = strings.Split(r[0], "")
t = strings.Split(r[1], "")
st = []string{strconv.Itoa(sCode[t[0]]),
strconv.Itoa(sCode[t[1]]),
strconv.Itoa(sCode[t[2]]),
strconv.Itoa(sCode[t[3]]),
strings.Join(r[2:6], ""),
strconv.Itoa(sCode[s[0]]),
strconv.Itoa(sCode[s[1]]),
strings.Join(s[2:4], ""),
}
u.SetString(strings.Join(st, ""), 10)
v.SetInt64(97)
w.Mod(u, v)
if w.Uint64() == 1 && lCode[strings.Join(s[0:2], "")] == len(strings.Join(r, "")) {
fmt.Printf("IBAN %s looks good!\n", iban)
} else {
fmt.Printf("IBAN %s looks wrong!\n", iban)
}
}
示例2: Node
func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
if L == i {
return dag.hash
}
var m *big.Int
if L == 9 {
m = big.NewInt(16)
} else {
m = big.NewInt(3)
}
sha := sha3.NewKeccak256()
sha.Reset()
d := sha3.NewKeccak256()
b := new(big.Int)
ret := new(big.Int)
for k := 0; k < int(m.Uint64()); k++ {
d.Reset()
d.Write(dag.hash.Bytes())
d.Write(dag.xn.Bytes())
d.Write(big.NewInt(int64(L)).Bytes())
d.Write(big.NewInt(int64(i)).Bytes())
d.Write(big.NewInt(int64(k)).Bytes())
b.SetBytes(Sum(d))
pk := b.Uint64() & ((1 << ((L - 1) * 3)) - 1)
sha.Write(dag.Node(L-1, pk).Bytes())
}
ret.SetBytes(Sum(sha))
return ret
}
示例3: ecrecoverFunc
func ecrecoverFunc(in []byte) []byte {
// "in" is (hash, v, r, s), each 32 bytes
// but for ecrecover we want (r, s, v)
if len(in) < ecRecoverInputLength {
return nil
}
// Treat V as a 256bit integer
v := new(big.Int).Sub(common.Bytes2Big(in[32:64]), big.NewInt(27))
// Ethereum requires V to be either 0 or 1 => (27 || 28)
if !(v.Cmp(Zero) == 0 || v.Cmp(One) == 0) {
return nil
}
// v needs to be moved to the end
rsv := append(in[64:128], byte(v.Uint64()))
pubKey, err := crypto.Ecrecover(in[:32], rsv)
// make sure the public key is a valid one
if err != nil {
glog.V(logger.Error).Infof("EC RECOVER FAIL: ", err)
return nil
}
// the first byte of pubkey is bitcoin heritage
return common.LeftPadBytes(crypto.Sha3(pubKey[1:])[12:], 32)
}
示例4: TestJWKThumbprint
func TestJWKThumbprint(t *testing.T) {
// Key example from RFC 7638
const base64N = "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAt" +
"VT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn6" +
"4tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FD" +
"W2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n9" +
"1CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINH" +
"aQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw"
const base64E = "AQAB"
const expected = "NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs"
bytes, err := base64.RawURLEncoding.DecodeString(base64N)
if err != nil {
t.Fatalf("Error parsing example key N: %v", err)
}
n := new(big.Int).SetBytes(bytes)
bytes, err = base64.RawURLEncoding.DecodeString(base64E)
if err != nil {
t.Fatalf("Error parsing example key E: %v", err)
}
e := new(big.Int).SetBytes(bytes)
pub := &rsa.PublicKey{N: n, E: int(e.Uint64())}
th := JWKThumbprint(pub)
if th != expected {
t.Errorf("th = %q; want %q", th, expected)
}
}
示例5: New
// Create a new UniformDH instance
func New() *UniformDH {
udh := &UniformDH{}
privStr := make([]byte, groupLen)
// To pick a private UniformDH key, we pick a random 1536-bit number,
// and make it even by setting its low bit to 0. Let x be that private
// key, and X = g^x (mod p).
rand.Read(privStr)
udh.priv.SetBytes(privStr)
/// XXX: is setting this bit *and* modulo 2 necessary?
udh.priv.SetBit(&udh.priv, 0, 0)
// When someone sends her public key to the other party, she randomly
// decides whether to send X or p-X. This makes the public key
// negligibly different from a uniform 1536-bit string
flip := new(big.Int).Mod(&udh.priv, big.NewInt(2))
udh.priv.Sub(&udh.priv, flip)
udh.pub.Exp(big.NewInt(g), &udh.priv, &mod)
if flip.Uint64() == 1 {
udh.pub.Sub(&mod, &udh.pub)
}
/// XXX: handle erroneous situations better
if udh.priv.BitLen() > intSize {
panic("int too large")
}
return udh
}
示例6: Eval
func (dag *Dagger) Eval(N *big.Int) *big.Int {
pow := common.BigPow(2, 26)
dag.xn = pow.Div(N, pow)
sha := sha3.NewKeccak256()
sha.Reset()
ret := new(big.Int)
for k := 0; k < 4; k++ {
d := sha3.NewKeccak256()
b := new(big.Int)
d.Reset()
d.Write(dag.hash.Bytes())
d.Write(dag.xn.Bytes())
d.Write(N.Bytes())
d.Write(big.NewInt(int64(k)).Bytes())
b.SetBytes(Sum(d))
pk := (b.Uint64() & 0x1ffffff)
sha.Write(dag.Node(9, pk).Bytes())
}
return ret.SetBytes(Sum(sha))
}
示例7: encodeBlock
// encodeBlock fills the dst buffer with the encoding of src.
// It is assumed the buffers are appropriately sized, and no
// bounds checks are performed. In particular, the dst buffer will
// be zero-padded from right to left in all remaining bytes.
func (enc *Encoding) encodeBlock(dst, src []byte) {
// Interpret the block as a big-endian number (Go's default)
num := new(big.Int).SetBytes(src)
rem := new(big.Int)
quo := new(big.Int)
encodedLen := enc.EncodedLen(len(src))
// Shift over the given number of extra Bits, so that all of our
// wasted bits are on the right.
num = num.Lsh(num, enc.extraBits(len(src), encodedLen))
p := encodedLen - 1
for num.Sign() != 0 {
num, rem = quo.QuoRem(num, enc.baseBig, rem)
dst[p] = enc.encode[rem.Uint64()]
p--
}
// Pad the remainder of the buffer with 0s
for p >= 0 {
dst[p] = enc.encode[0]
p--
}
}
示例8: TestModAdc
func TestModAdc(t *testing.T) {
A := new(big.Int)
B := new(big.Int)
C := new(big.Int)
Carry := new(big.Int)
Mask := new(big.Int)
for _, a := range numbers {
A.SetUint64(a)
for _, b := range numbers {
B.SetUint64(b)
for width := uint8(1); width < 64; width++ {
carry := b
c := mod_adc(a, width, &carry)
C.Add(A, B)
Carry.Rsh(C, uint(width))
expectedCarry := Carry.Uint64()
Mask.SetUint64(uint64(1)<<width - 1)
C.And(C, Mask)
expected := C.Uint64()
if c != expected || expectedCarry != carry {
t.Fatalf("adc(%d,%d,%d): Expecting %d carry %d but got %d carry %d", a, b, width, expected, expectedCarry, c, carry)
}
}
}
}
}
示例9: ecrecoverFunc
func ecrecoverFunc(in []byte) []byte {
in = common.RightPadBytes(in, 128)
// "in" is (hash, v, r, s), each 32 bytes
// but for ecrecover we want (r, s, v)
r := common.BytesToBig(in[64:96])
s := common.BytesToBig(in[96:128])
// Treat V as a 256bit integer
vbig := common.Bytes2Big(in[32:64])
v := byte(vbig.Uint64())
if !crypto.ValidateSignatureValues(v, r, s) {
glog.V(logger.Error).Infof("EC RECOVER FAIL: v, r or s value invalid")
return nil
}
// v needs to be at the end and normalized for libsecp256k1
vbignormal := new(big.Int).Sub(vbig, big.NewInt(27))
vnormal := byte(vbignormal.Uint64())
rsv := append(in[64:128], vnormal)
pubKey, err := crypto.Ecrecover(in[:32], rsv)
// make sure the public key is a valid one
if err != nil {
glog.V(logger.Error).Infof("EC RECOVER FAIL: ", err)
return nil
}
// the first byte of pubkey is bitcoin heritage
return common.LeftPadBytes(crypto.Sha3(pubKey[1:])[12:], 32)
}
示例10: getData
func getData(data []byte, start, size *big.Int) []byte {
dlen := big.NewInt(int64(len(data)))
s := common.BigMin(start, dlen)
e := common.BigMin(new(big.Int).Add(s, size), dlen)
return common.RightPadBytes(data[s.Uint64():e.Uint64()], int(size.Uint64()))
}
示例11: CalculatePdpPrep
func (d *DatasourceDerive) CalculatePdpPrep(newValue string, interval float64) (float64, error) {
if float64(d.Heartbeat) < interval {
d.LastValue = Undefined
}
rate := math.NaN()
newPdp := math.NaN()
if newValue != Undefined && float64(d.Heartbeat) >= interval {
newInt := new(big.Int)
_, err := fmt.Sscan(newValue, newInt)
if err != nil {
return math.NaN(), errors.Errorf("not a simple signed integer: %s", newValue)
}
if d.LastValue != "U" {
prevInt := new(big.Int)
_, err := fmt.Sscan(d.LastValue, prevInt)
if err != nil {
return math.NaN(), errors.Wrap(err, 0)
}
diff := new(big.Int)
diff.Sub(newInt, prevInt)
newPdp = float64(diff.Uint64())
rate = newPdp / interval
}
}
if !d.checkRateBounds(rate) {
newPdp = math.NaN()
}
d.LastValue = newValue
return newPdp, nil
}
示例12: Encode58
// Encode58 base58 encodes the input.
func Encode58(inp []byte) string {
num := new(big.Int).SetBytes(inp)
buf := make([]byte, 0, len(inp))
base := big.NewInt(int64(58))
rem := new(big.Int)
quo := new(big.Int)
for num.Sign() != 0 {
num, rem = quo.QuoRem(num, base, rem)
c := alphabet[rem.Uint64()]
buf = append(buf, c)
}
// Pad leading zeros...
for _, c := range inp {
if c == 0x0 {
buf = append(buf, alphabet[0])
} else {
// Stop adding padding after the first nonzero byte.
break
}
}
reverseBuf(buf)
return string(buf)
}
示例13: SmallPrimeTest
// SmallPrimeTest determins if N is a small prime
// or divisible by a small prime.
func SmallPrimeTest(N *big.Int) int {
if N.Sign() <= 0 {
panic("SmallPrimeTest for positive integers only")
}
if N.BitLen() <= 10 {
n := uint16(N.Uint64())
i := sort.Search(len(primes10), func(i int) bool {
return primes10[i] >= n
})
if i >= len(primes10) || n != primes10[i] {
return IsComposite
}
return IsPrime
}
// quick test for N even
if N.Bits()[0]&1 == 0 {
return IsComposite
}
// compare several small gcds for efficency
z := new(big.Int)
if z.GCD(nil, nil, N, prodPrimes10A).Cmp(one) == 1 {
return IsComposite
}
if z.GCD(nil, nil, N, prodPrimes10B).Cmp(one) == 1 {
return IsComposite
}
if z.GCD(nil, nil, N, prodPrimes10C).Cmp(one) == 1 {
return IsComposite
}
if z.GCD(nil, nil, N, prodPrimes10D).Cmp(one) == 1 {
return IsComposite
}
return Undetermined
}
示例14: jump
func jump(mapping map[uint64]uint64, destinations map[uint64]struct{}, contract *Contract, to *big.Int) (uint64, error) {
if !validDest(destinations, to) {
nop := contract.GetOp(to.Uint64())
return 0, fmt.Errorf("invalid jump destination (%v) %v", nop, to)
}
return mapping[to.Uint64()], nil
}
示例15: Euler015
/* solution:
Will rapresent the moves as R=right, D=Down....
In any grid of size N, we need N moves of each (R,D) (total 2N moves)
ex for the 2x2 grid we have RRDD,RDRD,RDDR,DRRD,DRDR,DDRR (6 moves)
If we arbitrary choose N of one direction first and fill the rest
with other direction,
the problem becomes a combination problem for N choices out of 2N
so we could use the C(n,k) = n!/(k!(n-k)!) for the answer
where n = 2N and k=N
*/
func Euler015(N int) uint64 {
n, k := (2 * N), N
num := utils.Fact(n)
den := new(big.Int).Mul(utils.Fact(k), utils.Fact(n-k))
res := new(big.Int).Div(num, den)
return res.Uint64()
}