コード例 #1
0
ファイル: Shamir.cpp プロジェクト: JeremyRand2/libcoin
uint256 Shamir::recover(const Shamir::Shares& shares) const {
    CBigNum accum = 0;
    for(Shares::const_iterator formula = shares.begin(); formula != shares.end(); ++formula)
    {
        CBigNum numerator = 1;
        CBigNum denominator = 1;
        for(Shares::const_iterator count = shares.begin(); count != shares.end(); ++count)
        {
            if(formula == count) continue; // If not the same value
            unsigned char startposition = formula->first;
            unsigned char nextposition = count->first;
            numerator = (-nextposition * numerator) % _order;
            denominator = ((startposition - nextposition)*denominator) % _order;
        }
        accum = (_order + accum + (CBigNum(formula->second) * numerator * ModInverse(denominator, _order))) % _order;
    }
    return accum.getuint256();
}
コード例 #2
0
ファイル: RsaLib.c プロジェクト: Constantrock/Talk-Secure
// main will return 0 and store the public and private keys into a file
int main(){
  //calculate the keys
  //get the two prime numbers we need
  long prime1 = primereturn(1);
  long prime2 = primereturn(2);
  //calculate the modulus
  long modn = prime1 * prime2;
  //claculate the phi of n
  long phiofn = ((prime1 -1) * (prime2 -1));
  //calculate the random key we will use
  long privatekey = privkeyexp(phiofn);
  //now take the inverse of the public key
  long publickey = ModInverse(privatekey, phiofn);
  //this concludes the calculations
  //time to store
  printf("%ld\n%ld\n%ld\n", privatekey, publickey, modn);
  return 0;
}