Skip to content

Instantly share code, notes, and snippets.

@jbaylina
Created May 19, 2020 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbaylina/3eb9f6593b305e9c66dd87622dd9855a to your computer and use it in GitHub Desktop.
Save jbaylina/3eb9f6593b305e9c66dd87622dd9855a to your computer and use it in GitHub Desktop.
template Num2Bits5(n) {
signal input in;
signal output out[n];
signal a[n];
signal b[n];
signal c[n];
var lc = 0;
var r = in;
for (var i=0; i<n; i++) {
out[i] <-- r % 5;
lc += out[i]* 5**i;
// (x-4)(x-3)(x-2)(x-1)x === 0
a[i] <== (out[i]-4)*(out[i]-3);
b[i] <== (out[i]-2)*(out[i]-1);
c[i] <== a[i]*b[i];
c[i]*out[i] === 0;
r = r \ 5;
}
in === lc;
}
component main = Num2Bits5(6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment