arnaucube
arnaucube/circomPublic Self-hosted repository
circom/circuits/sha256/bitify.circom
circuits/sha256/bitify.circomRaw
 1/*
 2    Copyright 2018 0KIMS association.
 3
 4    This file is part of circom (Zero Knowledge Circuit Compiler).
 5
 6    circom is a free software: you can redistribute it and/or modify it
 7    under the terms of the GNU General Public License as published by
 8    the Free Software Foundation, either version 3 of the License, or
 9    (at your option) any later version.
10
11    circom is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14    License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with circom. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20template Num2Bits(n) {
21    signal input in;
22    signal output out[n];
23    var lc1=0;
24
25    for (var i = 0; i<n; i++) {
26        out[i] <-- (in >> i) & 1;
27        out[i] * (out[i] -1 ) === 0;
28        lc1 += out[i] * 2**i;
29    }
30
31    lc1 === in;
32
33}
34
35template Bits2Num(n) {
36    signal input in[n];
37    signal output out;
38    var lc1=0;
39
40    for (var i = 0; i<n; i++) {
41        lc1 += in[i] * 2**i;
42    }
43
44    lc1 ==> out;
45}