1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package ldp

import (
	fr "github.com/consensys/gnark-crypto/ecc/bn254/fr"
	"math/big"
)

func GetCoinsFromRho(rho fr.Element) (c0, c1 int) {

	rhoB := rho.Text(2)
	l := len(rhoB)
	c0 = int(rhoB[l-1] - '0')
	c1 = int(rhoB[l-2] - '0')
	return
}

func RandomResponse(rho fr.Element, msg *big.Int) (res big.Int, c0, c1 int) {
	c0, c1 = GetCoinsFromRho(rho)

	if c0 == 0 {
		res = *msg
	} else {
		if c1 == 0 {
			res.SetInt64(int64(1))
		} else {
			res.SetInt64(int64(0))
		}
	}
	return
}