int main() { int i, j, cnt; while(scanf("%d", &n) != EOF && n) { for(i = 0;i < PRIME;i++) hash[i].next = -1; hashl = PRIME; int x1, y1, x2, y2; for (i = 0; i < n; i++){ scanf("%d%d", &p[i].x, &p[i].y); Hash((p[i].x + 100000) * 100000 + p[i].y + 100000); } cnt = 0; for (i = 0; i < n; i++){ for (j = i + 1; j < n; j++) { point a, b; if(squares(p[i], p[j], a, b) == 0) continue; if(Hash2((a.x + 100000) * 100000 + a.y + 100000) == 0) continue; if(Hash2((b.x + 100000) * 100000 + b.y + 100000) == 0) continue; cnt++; } } printf("%d\n", cnt / 2); } return 0; }
void Test_HashBoard() { std::cout << "**** Test_HashBoard ****" << std::endl; std::cout << "Hash1:" << std::endl; TEST_HASH_BOARD(Hash1(board)); TEST_HASH_BOARD(Hash1(board)); std::cout << "Hash2:" << std::endl; TEST_HASH_BOARD(Hash2(board)); TEST_HASH_BOARD(Hash2(board)); std::cout << "Hash3:" << std::endl; TEST_HASH_BOARD(Hash3(board)); TEST_HASH_BOARD(Hash3(board)); std::cout << "----------------------------------------" << std::endl; }
void *NMultiSet(MULTI *ma, int *k, void *d) { int i, j, m = 0, h; MDATA *pt = NULL; ARRAY *a; DATA *p, *p0 = NULL; if (ma->maxelem > 0 && ma->numelem >= ma->maxelem) { NMultiFreeData(ma); ma->numelem = 0; } h = Hash2(k, ma->ndim, 0, ma->ndim); a = &(ma->array[h]); if (a->dim == 0) { a->data = (DATA *) malloc(sizeof(DATA)); a->data->dptr = malloc(a->bsize); InitMDataData(a->data->dptr, a->block); a->data->next = NULL; pt = (MDATA *) a->data->dptr; } else { p = a->data; i = a->dim; j = 0; while (p) { pt = (MDATA *) p->dptr; for (m = 0; m < a->block && j < i; j++, m++) { if (memcmp(pt->index, k, ma->isize) == 0) { if (d) { memcpy(pt->data, d, ma->esize); } return pt->data; } pt++; } p0 = p; p = p->next; } if (m == a->block) { p0->next = (DATA *) malloc(sizeof(DATA)); p = p0->next; p->dptr = malloc(a->bsize); InitMDataData(p->dptr, a->block); p->next = NULL; pt = (MDATA *) p->dptr; } } ma->numelem++; pt->index = malloc(ma->isize); memcpy(pt->index, k, ma->isize); pt->data = malloc(ma->esize); if (a && a->InitData) a->InitData(pt->data, 1); if (d) memcpy(pt->data, d, ma->esize); (a->dim)++; return pt->data; }
void SignVerifyMessageDialog::on_signMessageButton_SM_clicked() { /* Clear old signature to ensure users don't get confused on error with an old signature displayed */ ui->signatureOut_SM->clear(); CBitcoinAddress addr(ui->addressIn_SM->text().toStdString()); if (!addr.IsValid()) { ui->addressIn_SM->setValid(false); ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again.")); return; } CKeyID keyID; if (!addr.GetKeyID(keyID)) { ui->addressIn_SM->setValid(false); ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again.")); return; } WalletModel::UnlockContext ctx(model->requestUnlock()); if (!ctx.isValid()) { ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("Wallet unlock was cancelled.")); return; } CKey key; if (!pwalletMain->GetKey(keyID, key)) { ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("Private key for the entered address is not available.")); return; } CDataStream ss(SER_GETHASH, 0); ss << strMessageMagic; ss << ui->messageIn_SM->document()->toPlainText().toStdString(); std::vector<unsigned char> vchSig; if (!key.SignCompact(Hash2(ss.begin(), ss.end()), vchSig)) { ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signing failed.") + QString("</nobr>")); return; } ui->statusLabel_SM->setStyleSheet("QLabel { color: green; }"); ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signed.") + QString("</nobr>")); ui->signatureOut_SM->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size()))); }
void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked() { CBitcoinAddress addr(ui->addressIn_VM->text().toStdString()); if (!addr.IsValid()) { ui->addressIn_VM->setValid(false); ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again.")); return; } CKeyID keyID; if (!addr.GetKeyID(keyID)) { ui->addressIn_VM->setValid(false); ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again.")); return; } bool fInvalid = false; std::vector<unsigned char> vchSig = DecodeBase64(ui->signatureIn_VM->text().toStdString().c_str(), &fInvalid); if (fInvalid) { ui->signatureIn_VM->setValid(false); ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(tr("The signature could not be decoded.") + QString(" ") + tr("Please check the signature and try again.")); return; } CDataStream ss(SER_GETHASH, 0); ss << strMessageMagic; ss << ui->messageIn_VM->document()->toPlainText().toStdString(); CKey key; if (!key.SetCompactSignature(Hash2(ss.begin(), ss.end()), vchSig)) { ui->signatureIn_VM->setValid(false); ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(tr("The signature did not match the message digest.") + QString(" ") + tr("Please check the signature and try again.")); return; } if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr)) { ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>")); return; } ui->statusLabel_VM->setStyleSheet("QLabel { color: green; }"); ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>")); }
TexturePtr NullHWBufferManager::NewTexture(const String & name, int width, int height, int mipmaps, ePixelFormat format, eUsage usage) { d_assert (GetTexture(name) == NULL); NullTexture * p = new NullTexture(name, ""); p->mWidth = width; p->mHeight = height; p->mMipmaps = 1; p->mUsage = usage; p->mFormat = format; p->Load(); mTextureMap.Insert(Hash2(name.c_str()), p); return p; }
bool SetCheckpointPrivKey(std::string strPrivKey) { // Test signing a sync-checkpoint with genesis block CSyncCheckpoint checkpoint; checkpoint.hashCheckpoint = hashGenesisBlock; CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); sMsg << (CUnsignedSyncCheckpoint)checkpoint; checkpoint.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end()); CBitcoinSecret vchSecret; if (!vchSecret.SetString(strPrivKey)) return error("SendSyncCheckpoint: Checkpoint master key invalid"); CKey key; bool fCompressed; CSecret secret = vchSecret.GetSecret(fCompressed); key.SetSecret(secret, fCompressed); // if key is not correct openssl may crash if (!key.Sign(Hash2(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig)) return false; // Test signing successful, proceed CSyncCheckpoint::strMasterPrivKey = strPrivKey; return true; }
bool SendSyncCheckpoint(uint256 hashCheckpoint) { printf("SendSyncCheckpoint: hashCheckpoint=%s\n", hashCheckpoint.ToString().c_str()); CSyncCheckpoint checkpoint; checkpoint.hashCheckpoint = hashCheckpoint; CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); sMsg << (CUnsignedSyncCheckpoint)checkpoint; checkpoint.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end()); if (CSyncCheckpoint::strMasterPrivKey.empty()) return error("SendSyncCheckpoint: Checkpoint master key unavailable."); CBitcoinSecret vchSecret; if (!vchSecret.SetString(CSyncCheckpoint::strMasterPrivKey)) return error("SendSyncCheckpoint: Checkpoint master key invalid"); CKey key; bool fCompressed; CSecret secret = vchSecret.GetSecret(fCompressed); key.SetSecret(secret, fCompressed); // if key is not correct openssl may crash if (!key.Sign(Hash2(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig)) return error("SendSyncCheckpoint: Unable to sign checkpoint, check private key?"); if(!checkpoint.ProcessSyncCheckpoint(NULL)) { printf("WARNING: SendSyncCheckpoint: Failed to process checkpoint.\n"); return false; } // Relay checkpoint { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) checkpoint.RelayTo(pnode); } return true; }
void *NMultiGet(MULTI *ma, int *k) { ARRAY *a; MDATA *pt; DATA *p; int i, j, m, h; h = Hash2(k, ma->ndim, 0, ma->ndim); a = &(ma->array[h]); p = a->data; i = a->dim; j = 0; while (p) { pt = (MDATA *) p->dptr; for (m = 0; m < a->block && j < i; j++, m++) { if (memcmp(pt->index, k, ma->isize) == 0) { return pt->data; } pt++; } p = p->next; } return NULL; }
SoundSourcePtr AudioSystem::GetSource(const String & filename) { return _find(Hash2(filename.c_str()), filename); }