示例#1
0
// moduleni 2 dlouhych cisel (opet vyuzivajici stredoskolsky algoritmus)
LNum operator%(LNum & dividend, LNum & divisor) {
  LNum quotient = dividend/divisor;
  LNum multiple = quotient*divisor;
  to_normal_form(multiple);
  LNum result = dividend-multiple;
  to_normal_form(result);
  return result;
}
示例#2
0
long_hash decode_mnemonic(const word_list& mnemonic,
    const std::string& passphrase)
{
    const auto sentence = join(mnemonic);
    const std::string prefix(passphrase_prefix);
    const auto salt = to_normal_form(prefix + passphrase);
    return pkcs5_pbkdf2_hmac_sha512(to_data_chunk(sentence),
        to_data_chunk(salt), hmac_iterations);
}
示例#3
0
// celociselne deleni 2 dlouhych cisel (stredoskolsky algoritmus)
// -- viz http://courses.cs.vt.edu/~cs1104/BuildingBlocks/divide.030.html
LNum operator/(LNum & dividend, LNum & divisor) {
  LNum quotient(1);
  quotient[0] = 0;
  to_normal_form(dividend);
  to_normal_form(divisor);

  // deleni nulou !!
  if (divisor.get_size() == 1 && divisor[0] == 0) {
    cout << "Division by zero!! Returning \"0\"!" << endl;
    return quotient;
  }

  // deleni mensiho cisla vetsim -> podil == 0
  if (dividend < divisor) {
    LNum oh(1);
    return oh;
  }

  // zarovnej delitel do leveho rohu delence
  int lock = dividend.get_size() - divisor.get_size();  // zarazka zpracovavane
                                                        // cifry v dividendu
  LNum portion = cut(dividend, lock, dividend.get_size()-1);

  do {
    if (!(portion<divisor)) {
      portion = portion - divisor;
      quotient.append(1);
    } else {
      quotient.append(0);
    }
    if (--lock >= 0) {
      portion.append(dividend[lock]);
    }
  } while (lock >= 0);

  to_normal_form(quotient);

  return quotient;
}
示例#4
0
// porovnani 2 dlouhych cisel: a<b ?
// nejprve dle #cifer; pak po cifrach od nejvyssi k nejnizsi mocnine
bool operator<(const LNum & num1, const LNum & num2) {
  // zbavime se "0" na zacatku
  LNum a = num1; to_normal_form(a);
  LNum b = num2; to_normal_form(b);

  if (a.get_size() < b.get_size()) {          // ruzne pocty cifer
    return true;
  } else if (a.get_size() > b.get_size()) {
    return false;
  } else {                                    // porovnavani po cifrach
    for (int i = a.get_size()-1; i >= 0; i--) {
      // i-ta cifra "a" mensi nez i-ta cifra "b": 0 < 1
      if (a[i] < b[i]) {
        return true;
      }
      // i-ta cifra "a" vetsi nez i-ta cifra "b": 1 > 0
      else if (a[i] > b[i]) {
        return false;
      }
    }
  }

  return false;                                // v tuhle chvili uz je a == b
}