summaryrefslogtreecommitdiff
path: root/gp-scripts/smc.gp
blob: 2b7e188754f6cad942b0b07f5a6d89d536e274cd (plain)
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
31
32
33
34
35
/* search for a random prime with the specified amount of bits */
\\ randomprime(bits:small=127)=
\\ {
\\ 	local(r:int=4);
\\ 	while(!isprime(r),
\\ 		r = bitor(2^(bits-1) + random(2^(bits-1)-1), 1);
\\ 	);
\\ 	r;
\\ }

smc_hextodec(s:str) =
{
	local(v:vecsmall = Vecsmall(s), ret:int = 0);
	for(i = 1, #v,
		ret = (ret<<4) + if(v[i]<=57 && v[i]>=48, v[i]-48, v[i]<=70 && v[i]>=65, v[i]-55, v[i]<=102 && v[i]>=97, v[i]-87, error("invalid input format"))
	);
	ret;
}

smc_genbid(k:small, bid:small, g)=
{
	vector(k,j,g^(bid==j));
}

smc_genalpha(k:small, b:vec, r:vec, y)=
{
	vector(k, j, b[j]*y^r[j]);
}

smc_genbeta(k:small, r:vec, g)=
{
	vector(k, j, g^r[j]);
}