Skip to content

Instantly share code, notes, and snippets.

@ruescasd
Created September 15, 2017 10:39
Show Gist options
  • Save ruescasd/5a4f473979d75a61173b9bfb266e0a49 to your computer and use it in GitHub Desktop.
Save ruescasd/5a4f473979d75a61173b9bfb266e0a49 to your computer and use it in GitHub Desktop.
// encode to m * legendre(m|p)
if (encode_m) {
// need to encode the message given that p = 2q+1
var y = m.add(BigInt.ONE);
// euler criterion to determine quadratic residuosity
var test = y.modPow(pk.q, pk.p);
if (test.equals(BigInt.ONE)) {
this.m = y;
} else {
this.m = y.negate().mod(pk.p);
}
} else {
this.m = m;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment