void SpawnShell::newCoinsItem(const dropCoinsStruct *c) { #ifdef SPAWNSHELL_DIAG printf("SpawnShell::newCoinsItem(dropCoinsStruct*)\n"); #endif // if zoning, then don't do anything if (m_zoneMgr->isZoning()) return; if (!c) return; Item* item = m_coins.find(c->dropId); if (item != NULL) { Coin* coin = (Coin*)item; coin->update(c); updateFilterFlags(item); item->updateLastChanged(); emit changeItem(item, tSpawnChangedALL); } else { item = new Coin(c); updateFilterFlags(item); m_coins.insert(c->dropId, item); emit addItem(item); } if (item->filterFlags() & FILTER_FLAG_ALERT) emit handleAlert(item, tNewSpawn); }
//每一次地图重载,地图中的对象要回收 bool ObjectManager::recycleObjectOfMap(int map) { //清除金币 std::list<Coin*>::iterator it1 = m_vecCoinsList.begin(); std::list<Coin*>::iterator end1 = m_vecCoinsList.end(); #if 0 while (it1 != end1) { Coin *coin = *it1++; if (coin->_map == map) { coin->removeFromParent(); delete coin; break; } } #else for(;it1!=end1;++it1) { if((*it1)->_map == map) { (*it1)->removeFromParent(); m_vecCoinsList.erase(it1); //delete *it1; break; //end1 = m_vecCoinsList.end(); } } #endif //清除石头 std::list<Rock*>::iterator it2 = m_vecRocksList.begin(); std::list<Rock*>::iterator end2 = m_vecRocksList.end(); #if 0 while (it2 != end2) { Rock *rock = *it2++; if (rock->_map == map) { rock->removeFromParent(); delete rock; break; } } #else for(;it2!=end2;++it2) { if((*it2)->_map == map) { (*it2)->removeFromParent(); m_vecRocksList.erase(it2); //delete *it2; break; //end1 = m_vecCoinsList.end(); } } #endif return true; }
int main(int argc,char **argv) { if(argc != 5) { fprintf(stderr,"%s <bank public info> <private coin request> <signed coin request> <coin>\n", argv[0]); exit(1); } const char *szBankFile=argv[1]; const char *szPrivateRequestFile=argv[2]; const char *szSignatureFile=argv[3]; const char *szCoinFile=argv[4]; SetDumper(stderr); BIO *bioBank=BIO_new_file(szBankFile,"r"); BIO *bioPrivateRequest=BIO_new_file(szPrivateRequestFile,"r"); BIO *bioSignature=BIO_new_file(szSignatureFile,"r"); BIO *bioCoin=BIO_new_file(szCoinFile,"w"); PublicBank bank(bioBank); CoinRequest req(bioPrivateRequest); ReadNumber(bioSignature,"request="); BIGNUM *bnSignature=ReadNumber(bioSignature,"signature="); DumpNumber("signature=",bnSignature); Coin coin; req.ProcessResponse(&coin,bank,bnSignature); coin.WriteBIO(bioCoin); }
vector<unsigned> Arbiter::sellerResolveI(const ResolutionPair &keyMessagePair){ // first, store the keys keys = keyMessagePair.first; // now, unwrap and check the buyMessage, then store everything BuyMessage* buyMessage = keyMessagePair.second; Coin coinPrime = buyMessage->getCoinPrime(); VECiphertext escrow = *buyMessage->getEscrow(); // want to store the contract as well (for stage II) contract = *buyMessage->getContract(); // check the timeout to make sure it hasn't passed if(contract.checkTimeout(timeoutTolerance)) { endorsement = verifiableDecrypter->decrypt(escrow.getCiphertext(), saveString(contract), hashAlg); // make sure the endorsement on the coin is valid if(coinPrime.verifyEndorsement(endorsement)){ // construct verifiers based on the data in the contract and // return a set of challenges hash_t ptHash = contract.getPTHashB(); hash_t ctHash = contract.getCTHashB(); ptVerifier = shared_ptr<MerkleVerifier>(new MerkleVerifier(ptHash, contract.getNumPTHashBlocksB(), MerkleContract(ptHash.key,ptHash.alg))); ctVerifier = shared_ptr<MerkleVerifier>(new MerkleVerifier(ctHash, contract.getNumCTHashBlocksB(), MerkleContract(ctHash.key,ctHash.alg))); return ptVerifier->getChallenges(); } else { throw CashException(CashException::CE_FE_ERROR, "[Arbiter::sellerResolveI] invalid endorsement"); } } else { throw CashException(CashException::CE_FE_ERROR, "[Arbiter::sellerResolveI] contract has expired"); } }
// receive coin Coin<FIELD> decrypt(const SecretAddr<FIELD>& secretAddr, const PublicAddr<FIELD>& publicAddr) const { DECRYPTOR DEC(secretAddr.cryptoKey()); RANDPOOL RNG; // recovered text length const std::size_t rtextLen = DEC.MaxPlaintextLength(m_cipherText.size()); if (rtextLen) { // recovered text bytes std::vector<byte> rtext(rtextLen, 0xfb); if (DEC.Decrypt(RNG, m_cipherText.data(), m_cipherText.size(), rtext.data()).isValidCoding) { // convert recovered text to stream std::stringstream ss(std::string(rtext.begin(), rtext.end())); Coin<FIELD> coin; if (coin.marshal_in(ss, false)) { // false means omit public address // set public address of recovered coin coin.addr(publicAddr); // must check: // 1. cm matches pour transaction cm (coin exists in ledger) // 2. serial number is not in ledger (not already spent) if (coin.valid()) return coin; } } } return Coin<FIELD>(); // failed }
HitResponse Block::collision(GameObject& other, const CollisionHit& ) { Player* player = dynamic_cast<Player*> (&other); if(player) { if(player->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) { hit(*player); } } // only interact with other objects if... // 1) we are bouncing // and // 2) the object is not portable (either never or not currently) Portable* portable = dynamic_cast<Portable*> (&other); if(bouncing && (portable == 0 || (!portable->is_portable()))) { // Badguys get killed BadGuy* badguy = dynamic_cast<BadGuy*> (&other); if(badguy) { badguy->kill_fall(); } // Coins get collected Coin* coin = dynamic_cast<Coin*> (&other); if(coin) { coin->collect(); } } return SOLID; }
void Coin::compare(Coin B){ //Ideal coin struct initialization double value[4] = {.75, .835, .705, .955}; string name[4] = {"penny","nickel","dime","quarter"}; for(int i = 0; i<16; i++){ Ideal[i].Ratio = value[i/4]/value[i%4]; Ideal[i].CoinA = name[i/4]; Ideal[i].CoinB = name[i%4]; Ideal[i].Difference = abs(value[i/4]-value[i%4]); Ideal[i].ScaledDifference = Ideal[i].Difference/((value[i/4]+value[i%4])/2); } double dA = diameter; double dB = B.getDiameter(); double ratio = dA/dB; double scaledDifference = abs(dA-dB)/((dA+dB)/2); double sProb, rProb, aProb; for(int i = 0; i<16; i++){ if(Ideal[i].Ratio != 1){ rProb = 1 - abs(ratio - Ideal[i].Ratio); sProb = 1 - abs(scaledDifference - Ideal[i].ScaledDifference); aProb = abs((rProb + sProb)/2); updateProbablities(Ideal[i].CoinA,aProb); B.updateProbablities(Ideal[i].CoinB,aProb); } } };
int main() { // Instantiate a coin and some dice Coin c; Die<6> d6; Die<12> d12; Die<20> d20; // Now we test them! std::cout << "Coin:"; for ( auto i = 0; i < 25; ++i ) std::cout << std::setw(3) << c.flip(); std::cout << "\n" "D6 :"; for ( auto i = 0; i < 25; ++i ) std::cout << std::setw(3) << d6.roll(); std::cout << "\n" "D12 :"; for ( auto i = 0; i < 25; ++i ) std::cout << std::setw(3) << d12.roll(); std::cout << "\n" "D20 :"; for ( auto i = 0; i < 25; ++i ) std::cout << std::setw(3) << d20.roll(); std::cout << std::endl; return 0; }
static void SetCoinsValue(CAmount value, Coin& coin) { assert(value != ABSENT); coin.Clear(); assert(coin.IsSpent()); if (value != PRUNED) { coin.out.nValue = value; coin.nHeight = 1; assert(!coin.IsSpent()); } }
// this method sets up the resolve for a failed barter vector<unsigned> Arbiter::responderResolveI(const vector<string> &ks, const FEMessage* msg, const FESetupMessage* setup) { // stores keys and message keys = ks; message = msg; Coin coinPrime = setup->getCoinPrime(); // this is the regular encryption vector<ZZ> sigEscrow = message->getEscrow(); // this is the verifiable encryption VECiphertext vEscrow = *setup->getEscrow(); contract = message->getContract(); const Signature::Key* sigPK = setup->getPK(); // verify that the signature given in BarterMessage is correct bool sigCorrect = Signature::verify(*sigPK, message->getSignature(), CommonFunctions::vecToString(sigEscrow), hashAlg); if (!sigCorrect){ throw CashException(CashException::CE_FE_ERROR, "[Arbiter::responderResolveI] signature was malformed"); } // also need to make sure the contract hasn't expired if (!contract.checkTimeout(timeoutTolerance)){ throw CashException(CashException::CE_FE_ERROR, "[Arbiter::responderResolveI] contract has expired"); } vector<ZZ> end = verifiableDecrypter->decrypt(vEscrow.getCiphertext(), sigPK->publicKeyString(), hashAlg); // now verify the endorsement (and store it if it's valid) if(coinPrime.verifyEndorsement(end)){ // first store endorsement endorsement = end; // set up merkle verifiers and return challenges hash_t ptHash = contract.getPTHashB(); hash_t ctHash = contract.getCTHashB(); ptVerifier = boost::shared_ptr<MerkleVerifier>(new MerkleVerifier(ptHash, contract.getNumPTHashBlocksB(), MerkleContract(ptHash.key,ptHash.alg))); ctVerifier = boost::shared_ptr<MerkleVerifier>(new MerkleVerifier(ctHash, contract.getNumCTHashBlocksB(), MerkleContract(ctHash.key,ctHash.alg))); // XXX: right now this is only returning 0 every time!! return ptVerifier->getChallenges(); } else { throw CashException(CashException::CE_FE_ERROR, "[Arbiter::responderResolveI] invalid endorsement"); } }
//generateReward function void Nonbreakable::generateReward(bool isLarge) { // if it is a question block decide which reward to give to mario if (type_ == QUESTION) { if (reward_ == COIN) { // Create a coin above block it was in and adds drawable coin to the level // uses the left and right of the block and the top and bottom plus 16 Coin *coin = new Coin(); coin->setLeft(this->left()); coin->setRight(this->right()); coin->setTop(this->top()+16); coin->setBottom(this->top()); Level::sharedLevel()->addDrawable(coin); } else if (reward_ == MUSHROOM) { if (isLarge != true) { // Create a mushroom above block it was in and adds drawable coin to the level // uses the left and right of the block and the top and bottom plus 16 Mushroom *mushroom = new Mushroom(); mushroom->setLeft(this->left()); mushroom->setRight(this->right()); mushroom->setTop(this->top()+16); mushroom->setBottom(this->top()); Level::sharedLevel()->addMovable(mushroom); } else { // Create a fireflower above block it was in and adds drawable coin to the level // uses the left and right of the block and the top and bottom plus 16 FireFlower *fireFlower = new FireFlower(); fireFlower->setLeft(this->left()); fireFlower->setRight(this->right()); fireFlower->setTop(this->top()+16); fireFlower->setBottom(this->top()); Level::sharedLevel()->addDrawable(fireFlower); } } else { // Create a star above block it was in and adds drawable coin to the level // uses the left and right of the block and the top and bottom plus 16 Star *star = new Star(); star->setLeft(this->left()); star->setRight(this->right()); star->setTop(this->top()+16); star->setBottom(this->top()); Level::sharedLevel()->addDrawable(star); } // once the block has been hit by mario and the reward generated change type to regular from question type_ = OFFQUESTION; } }
bool BankTool::isCoinDoubleSpent(const Coin &coin1, const Coin &coin2) const { // throw an exception if these coins do not share the same S value if(coin1.getSPrime() != coin2.getSPrime()) { throw CashException(CashException::CE_UNKNOWN_ERROR, "[BankTool::checkIfCoinDoubleSpent] Coins do not share same serial " "coin point and are not valid candidates for checking double " "spending."); } // if contract hashes are same, then both coins were spent in the same // transaction so the coin was not double spent return (coin1.getR() != coin2.getR()); }
int main() { Coin coin; const int TURNS = 20; cout << "The initial side is: " << coin.getSideUp() << endl; for (int i = 0; i < TURNS; i++) { coin.toss(); cout << "For turn #" << i + 1 << " the side is: " << coin.getSideUp() << endl; } return 0; }
Coin * Coin::create(Vec2 position, GameStates & gameState) { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); auto spritecache = SpriteFrameCache::getInstance(); spritecache->addSpriteFramesWithFile(ptr->m_textureAtlasPlistFile); Coin* pSprite = new Coin(gameState); if (pSprite->initWithSpriteFrameName(ptr->m_coinFile)) { pSprite->autorelease(); pSprite->initOptions(position); pSprite->addEvents(); pSprite->setTag(30); auto towerBody = PhysicsBody::createBox(pSprite->getContentSize()); towerBody->setCollisionBitmask(0x000003); towerBody->setContactTestBitmask(true); towerBody->setTag(30); //towerBody->setDynamic(false); pSprite->setPhysicsBody(towerBody); return pSprite; } CC_SAFE_DELETE(pSprite); return NULL; }
int CoinFlip() { Coin coin; int numTosses; int expectedHeads; int expectedTails; int numSimulations = 100; int numHeads = 0; int numTails = 0; int count = 0; cout << "Enter the number of tosses for each simulation:" << endl; cin >> numTosses; cout << "Enter Expected Return of Heads. Number must be less than " << numTosses << endl; cin >> expectedHeads; expectedTails = numTosses - expectedHeads; cout << "Monte Carlo Simulation" << endl; cout << "----------------------" << endl; cout << "Number of coin tosses: " << numTosses << endl; cout << "Expected Number of Heads: " << expectedHeads << endl; cout << "Expected Number of Tails: " << expectedTails << endl; cout << "Number of simulations to be run: " << numSimulations << endl; cout << "Press any key to start runnig simulations:" << endl; system("pause"); for (int i = 0; i<numSimulations; i++) { numHeads = 0; numTails = 0; for (int j = 0; j<numTosses; j++) { if (coin.toss().compare("Heads")) numHeads++; else numTails++; } cout << "Heads: " << numHeads << " Tails: " << numTails << endl; if (numHeads>expectedHeads) count++; } cout << "-------------------" << endl; cout << "Simulation Complete" << endl; cout << "-------------------" << endl; cout << "Total number of simulations that resulted in Head values greater than the expected result of " << expectedHeads << " is " << count << endl; cout << "Now compare the simulated probability to the binomial distribution calculated probability" << endl; cout << "Simulated probability: " << ((double)count / numSimulations) << endl; system("pause"); return 0; }
// pour new coin EncryptedCoin(const Coin<FIELD>& coin) { ENCRYPTOR ENC(coin.addr().cryptoKey()); RANDPOOL RNG; std::stringstream ss; coin.marshal_out(ss, false); // false means omit public address const std::string& ptext = ss.str(); const std::size_t ptextLen = ptext.length() + 1; // encrypt message m_cipherText = std::vector<byte>(ENC.CiphertextLength(ptextLen), 0xfb); ENC.Encrypt(RNG, reinterpret_cast<const byte*>(ptext.data()), ptextLen, m_cipherText.data()); }
bool CCoinsViewCache::GetCoin(const COutPoint &outpoint, Coin &coin) const { CCoinsMap::const_iterator it = FetchCoin(outpoint); if (it != cacheCoins.end()) { coin = it->second.coin; return !coin.IsSpent(); } return false; }
LAURIE_BOOLEAN Bank::Verify(Coin &coin) { InitCTX(); BIGNUM *t=BN_new(); if(!coin.GenerateCoinNumber(t,*this)) return false; BN_mod_exp(t,t,priv_key(),p(),m_ctx); DumpNumber("y^k= ",t); BN_sub(t,t,coin.Signature()); LAURIE_BOOLEAN bRet=BN_is_zero(t); BN_free(t); return bRet; }
void Environment:: InitializeCoins(double& lastZ) { GLfloat groupX = GetRandomGLfloat(0.0, 1.0); Point3D initialPoint; initialPoint.x=groupX; double step=PI/10.0; int value=rand()%2; if(lastZ + (1.5 / 20)<road->GetRoadSize()) { for(int i = 0; i < 10; i++) { Coin *newCoin = new Coin(0.5, 0.5, 0.1); initialPoint.z=lastZ + 1.5 / 20; lastZ=initialPoint.z+newCoin->width/40.0; initialPoint.y+=0.5; Point3D currentPosition=road->GetOnRoadPosition(initialPoint, newCoin->width); if(value==0) { currentPosition.y+=sin(step)* 10.0+ 3.0; } else if(value==1) { currentPosition.y+= 3.0; } std::ofstream outfile; outfile.open("CoinsCoordinates.cpp", std::ios_base::app); outfile << initialPoint<<" "<<count<<endl; outfile.close(); newCoin->Translate(currentPosition); newCoin->Scale(Point3D(5.0, 5.0, 5.0)); newCoin->AddCollider(); road->AddRoadObject(newCoin); scene->AddObject(newCoin); //obstacles.push_back(newCoin); step+=PI/10.0; } } }
void Article::dead() { LifeObject::dead(); this->getBody()->SetLinearVelocity(b2Vec2(0,0)); this->setMask(TYPE_BRICK); Animate* animate = GameManager::getInstance()->getAnimate(SD_CHARS("article_animate_dead"), SD_FLOAT("article_float_dead_speed")); Sequence* action = Sequence::createWithTwoActions( animate, CallFunc::create(CC_CALLBACK_0(Article::ended, this))); this->runAction(action); //有一定几率给金币 float random = CCRANDOM_0_1() * 100; if (random < SD_FLOAT("article_float_bomb_coin_odds")) //几率 { Coin* coin = Coin::create(this->getPosition().x, this->getPosition().y, SD_FLOAT("coin_float_width"), SD_FLOAT("coin_float_height")); GameManager::getInstance()->thingLayer->addChild(coin); coin->getBody()->SetLinearVelocity(b2Vec2(0, 4)); } }
//Deletes all of the created objects here. void CloseFunc(){ window.window_handle = -1; cylinder.TakeDown();torus.TakeDown();square.TakeDown();square2.TakeDown(); disc.TakeDown();sphere.TakeDown();sphere2.TakeDown();tiger.TakeDown();goldeen.TakeDown(); stadium.TakeDown();coin.TakeDown();ss.TakeDown();healthBar.TakeDown(); shark.TakeDown();bird.TakeDown();sb.TakeDown();arena.TakeDown();skyboxUW.TakeDown();fbo.TakeDown();rain2.TakeDown(); tri2.TakeDown();skybox.TakeDown();skybox2.TakeDown();skybox3.TakeDown();egg.TakeDown();snow2.TakeDown(); star.TakeDown();magneton.TakeDown();haunter.TakeDown();frog.TakeDown(); sph1.TakeDown(); enm.TakeDown(); usr.TakeDown();sq4.TakeDown();soldier.TakeDown();userTeam.TakeDown();cpuTeam.TakeDown(); }
void Level1State::populateCoins() { int locations[8][2] = { {1068 ,140}, {1092 ,140}, {1116 ,140}, {1128 ,140}, {1140 ,140}, {1164, 140}, {1188, 140}, {1200, 140} }; for (int i=0; i<8; i++) { Coin *c = new Coin(tileMap, renderTarget, 10); c->setPosition(locations[i][0], locations[i][1]); coins.push_back(c); } }
HitResponse Block::collision(GameObject& other, const CollisionHit& ) { Player* player = dynamic_cast<Player*> (&other); if(player) { if(player->get_bbox().get_top() > get_bbox().get_bottom() - SHIFT_DELTA) { hit(*player); } } // only interact with other objects if... // 1) we are bouncing // 2) the object is not portable (either never or not currently) // 3) the object is being hit from below (baguys don't get killed for activating boxes) Portable* portable = dynamic_cast<Portable*> (&other); MovingObject* moving_object = dynamic_cast<MovingObject*> (&other); bool is_portable = ((portable != 0) && portable->is_portable()); bool hit_mo_from_below = ((moving_object == 0) || (moving_object->get_bbox().get_bottom() < (get_bbox().get_top() + SHIFT_DELTA))); if(bouncing && !is_portable && hit_mo_from_below) { // Badguys get killed BadGuy* badguy = dynamic_cast<BadGuy*> (&other); if(badguy) { badguy->kill_fall(); } // Coins get collected Coin* coin = dynamic_cast<Coin*> (&other); if(coin) { coin->collect(); } //Eggs get jumped GrowUp* growup = dynamic_cast<GrowUp*> (&other); if(growup) { growup->do_jump(); } } return FORCE_MOVE; }
void GameScene::updateFloorsAndCoins() { //改变山体的位置 for (int i =0; i<floorArray.size(); i++) { Floor *floor = floorArray.at(i); //forceX=300,speedFix = 0.01 floor->setPosition(Point(floor->getPositionX()-forceX * speedFix, floor->getPositionY())); } //改变金币的位置 for (int i = 0; i<coinArray.size(); i++) { Coin *coin = coinArray.at(i); coin->setPosition(Point(coin->getPositionX()-forceX * speedFix, coin->getPositionY())); } //当第一个山体移出屏幕 if (floorArray.at(0)->getPositionX() <-50) { int num = floorArray.size()-1;//数组中最后一个元素下标 float posx = floorArray.at(num)->getPositionX();//获取最后一个山体的X坐标 //将第一个山体再加入数组中,这样它就成为最后一个元素 floorArray.pushBack(floorArray.at(0)); //删除数组中第一个元素,这样就完成了第一个山体移动到数组中最后的位置 floorArray.eraseObject(floorArray.at(0)); coinArray.pushBack(coinArray.at(0)); coinArray.eraseObject(coinArray.at(0)); //获取0~2的随机数 randomNum = this->getRandomNumber(0, 2); if (randomNum == 0) { isFrontBlank = true; randomNum = this->getRandomNumber(1, 4); } Coin *coin = coinArray.at(num); //数组中最后一个元素,即原来的第一个元素移动到最后位置,再获取最后一个 coin->setVisible(true); if (isFrontBlank) { //posx为数组中倒数第二个元素的X坐标,高度为随机数100~150之间 //设置新的最后一个元素的位置 floorArray.at(num)->setPosition(Point(posx + randomNum*35 + 35, this->getRandomNumber(winSize.height/2 -100,170))); coinArray.at(num)->setPosition(Point(posx + randomNum*35 + 35, floorArray.at(num)->getPositionY() + this->getRandomNumber(50, 150))); isFrontBlank = false; }else{ //X轴坐标后移,高度同前一个山体 floorArray.at(num)->setPosition(Point(posx + 35 , floorArray.at(num - 1)->getPositionY())); coinArray.at(num)->setPosition(Point(posx + 35, floorArray.at(num)->getPositionY() + this->getRandomNumber(50, 150))); } randomNum = this ->getRandomNumber(0, 2); if (randomNum == 0) { coin->setVisible(false); } } }
HitResponse Block::collision(GameObject& other, const CollisionHit& ) { Player* player = dynamic_cast<Player*> (&other); if(player) { if(player->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) { hit(*player); } } if(bouncing) { BadGuy* badguy = dynamic_cast<BadGuy*> (&other); if(badguy) { badguy->kill_fall(); } Coin* coin = dynamic_cast<Coin*> (&other); if(coin) { coin->collect(); } } return SOLID; }
ZZ BankTool::identifyDoubleSpender(const Coin& coin1, const ZZ &tPrime2, const ZZ& rValue2) const { // Should probably check that the R values are different ZZ mod = coin1.getCashGroup()->getModulus(); ZZ order = coin1.getCashGroup()->getOrder(); ZZ t1 = coin1.getTPrime(); ZZ t2 = tPrime2; ZZ r1 = coin1.getR(); ZZ r2 = rValue2; if (r2 > r1) { NTL::swap(r2, r1); NTL::swap(t2, t1); } ZZ exp = InvMod(r1 - r2, order); ZZ num = PowerMod(t2, r1, mod); ZZ denom = InvMod(PowerMod(t1, r2, mod), mod); ZZ base = MulMod(num, denom, mod); ZZ publicKeyUser = PowerMod(base, exp, mod); return publicKeyUser; }
ZZ BankTool::identifyDoubleSpender(const Coin& coin1, const Coin& coin2) const { return identifyDoubleSpender(coin1, coin2.getTPrime(), coin2.getR()); }
// Lucre step 4: client unblinds token -- now it's ready for use. bool OTToken::ProcessToken(const OTPseudonym & theNym, OTMint & theMint, OTToken & theRequest) { // OTLog::vError("%s <bank public info> <private coin request> <signed coin request> <coin>\n", bool bReturnValue = false; // When the Mint has signed a token and sent it back to the client, // the client must unblind the token and set it as spendable. Thus, // this function is only performed on tokens in the signedToken state. if (OTToken::signedToken != m_State) { OTLog::Error("Signed token expected in OTToken::ProcessToken\n"); return false; } // Lucre SetDumper(stderr); BIO *bioBank = BIO_new(BIO_s_mem()); // input BIO *bioSignature = BIO_new(BIO_s_mem()); // input BIO *bioPrivateRequest = BIO_new(BIO_s_mem()); // input BIO *bioCoin = BIO_new(BIO_s_mem()); // output // Get the bank's public key (decoded into strPublicMint) // and put it into bioBank so we can use it with Lucre. OTASCIIArmor ascPublicMint; theMint.GetPublic(ascPublicMint, GetDenomination()); OTString strPublicMint(ascPublicMint); BIO_puts(bioBank, strPublicMint.Get()); // Get the existing signature into a bio. // OTLog::vError("DEBUGGING, m_Signature: -------------%s--------------\n", m_Signature.Get()); OTString strSignature(m_Signature); BIO_puts(bioSignature, strSignature.Get()); // I need the Private coin request also. (Only the client has this private coin request data.) OTASCIIArmor thePrototoken; // The server sets m_nChosenIndex when it signs the token. bool bFoundToken = theRequest.GetPrivatePrototoken(thePrototoken, m_nChosenIndex); if (bFoundToken) { // OTLog::vError("THE PRIVATE REQUEST ARMORED CONTENTS:\n------------------>%s<-----------------------\n", // thePrototoken.Get()); // Decrypt the prototoken OTString strPrototoken; OTEnvelope theEnvelope(thePrototoken); theEnvelope.Open(theNym, strPrototoken); // todo check return value. // OTLog::vError("THE PRIVATE REQUEST CONTENTS:\n------------------>%s<-----------------------\n", // strPrototoken.Get()); // copy strPrototoken to a BIO BIO_puts(bioPrivateRequest, strPrototoken.Get()); // ------- Okay, the BIOs are all loaded.... let's process... PublicBank bank(bioBank); CoinRequest req(bioPrivateRequest); // TODO make sure I'm not leaking memory with these ReadNumbers // Probably need to be calling some free function for each one. // Apparently reading the request id here and then just discarding it... ReadNumber(bioSignature,"request="); // Versus the signature data, which is read into bnSignature apparently. BIGNUM * bnSignature = ReadNumber(bioSignature,"signature="); DumpNumber("signature=", bnSignature); // Produce the final unblinded token in Coin coin, and write it to bioCoin... Coin coin; // Coin Request, processes into Coin, with Bank and Signature passed in. req.ProcessResponse(&coin, bank, bnSignature); // Notice still apparently "request" info is discarded. coin.WriteBIO(bioCoin); // convert bioCoin to a C-style string... char CoinBuffer[1024]; // todo stop hardcoding these string lengths int coinLen = BIO_read(bioCoin, CoinBuffer, 1000); // cutting it a little short on purpose, with the buffer. Just makes me feel more comfortable for some reason. if (coinLen) { // ...to OTString... OTString strCoin; strCoin.Set(CoinBuffer, coinLen); // OTLog::vError("Processing token...\n%s\n", strCoin.Get()); // ...to Envelope stored in m_ascSpendable (encrypted and base64-encoded) OTEnvelope theEnvelope; theEnvelope.Seal(theNym, strCoin); // Todo check the return values on these two functions theEnvelope.GetAsciiArmoredData(m_ascSpendable); // Here's the final product. // OTLog::vError("NEW SPENDABLE token...\n--------->%s<----------------\n", m_ascSpendable.Get()); // Now the coin is encrypted from here on out, and otherwise ready-to-spend. m_State = OTToken::spendableToken; bReturnValue = true; // Lastly, we free the signature data, which is no longer needed, and which could be // otherwise used to trace the token. (Which we don't want.) m_Signature.Release(); } } // Todo log error here if the private prototoken is not found. (Very strange if so!!) // else {} // Cleanup openssl resources. BIO_free_all(bioBank); BIO_free_all(bioSignature); BIO_free_all(bioPrivateRequest); BIO_free_all(bioCoin); return bReturnValue; }
//------------------------------------------------------------ void Level::makeLevel(int levelNumber) { //if the level already exists delete it if ((activeDrawable_.first() != NULL) || (activeMovable_.first() != NULL) || (activeBlocks_.first() != NULL)) { resetLevel(); } // Mac environment variable for home directory char *cHomeDir = NULL; cHomeDir = getenv("HOME"); // I think Windows uses HOMEPATH if (!cHomeDir) { cHomeDir = getenv("HOMEPATH"); } string homeDir = cHomeDir; homeDir += "/CS330/"; string fname; ifstream inFile; if (levelNumber== 1) { fname = homeDir + "levelfiles/level1.txt"; inFile.open(fname.c_str()); } else if (levelNumber== 2) { fname = homeDir + "levelfiles/level3.txt"; inFile.open(fname.c_str()); } int xcoord = 0, ycoord = 0, type, reward; char object; while (inFile.good()) { object= inFile.get(); /*at this point the variable 'object' has the next item in the .txt and here the 'object' and it's xcord and ycord are sent off to the correct LList*/ if (object== 'b') { //create breakable block Breakable *bBlock = new Breakable; bBlock->setTop(ycoord + 16); bBlock->setBottom(ycoord); bBlock->setLeft(xcoord); bBlock->setRight(xcoord + 16); //add block to the list if (xcoord<256){ activeBlocks_.append(bBlock); } else { levelBlocks_.append(bBlock); } } else if (object== 'B' || object=='M' || object=='C' || object=='S'){ // sets the type and reward based off the letter passed and creates the block if (object == 'B') { type = REGULAR; reward = 0; } else if (object == 'M'){ type = QUESTION; reward = MUSHROOM; } else if (object == 'S'){ type = QUESTION; reward = STAR; } else if (object == 'C'){ type = QUESTION; reward = COIN; } Nonbreakable *nBlock = new Nonbreakable(type, reward); nBlock->setTop(ycoord + 16); nBlock->setBottom(ycoord); nBlock->setLeft(xcoord); nBlock->setRight(xcoord + 16); //place in correct list if (xcoord<256) { activeBlocks_.append(nBlock); } else { levelBlocks_.append(nBlock); } } else if (object == 'c') { //create coin Coin *coin = new Coin; coin->setTop(ycoord + 16); coin->setBottom(ycoord); coin->setLeft(xcoord); coin->setRight(xcoord + 16); //place in correct list if (xcoord<256) { activeDrawable_.append(coin); } else { levelDrawable_.append(coin); } } else if (object== 'f'){ //create flag pole Flag *flag = new Flag; flag->setTop(ycoord + 16); flag->setBottom(ycoord); flag->setLeft(xcoord+6); flag->setRight(xcoord + 10); //place in correct list if (xcoord<256){ activeBlocks_.append(flag); } else { levelBlocks_.append(flag); } } else if (object== 'P'){ //create Pipe top Pipe *pipe = new Pipe; pipe->setType(0); pipe->setTop(ycoord + 16); pipe->setBottom(ycoord); pipe->setLeft(xcoord); pipe->setRight(xcoord + 32); //place in correct list if (xcoord<256){ activeBlocks_.append(pipe); } else { levelBlocks_.append(pipe); } } else if (object== 'p'){ //create Pipe body Pipe *pipe = new Pipe; pipe->setType(1); pipe->setTop(ycoord + 16); pipe->setBottom(ycoord); pipe->setLeft(xcoord); pipe->setRight(xcoord + 32); //place in correct list if (xcoord<256){ activeBlocks_.append(pipe); } else { levelBlocks_.append(pipe); } } else if (object== 'g'){ //create goomba Goomba *goomba = new Goomba; goomba->setTop(ycoord + 16); goomba->setBottom(ycoord); goomba->setLeft(xcoord); goomba->setRight(xcoord + 16); //place in correct list if (xcoord<256) { activeMovable_.append(goomba); } else { levelMovable_.append(goomba); } } else if (object == 'k') { //create koopa Turtle *koopa = new Turtle; koopa->setTop(ycoord + 24); koopa->setBottom(ycoord); koopa->setLeft(xcoord); koopa->setRight(xcoord + 16); //place in correct list if (xcoord<256) { activeMovable_.append(koopa); } else { levelMovable_.append(koopa); } } else if (object == 's') { //creates the coordinates for marios starting point leftStart_ = xcoord; bottomStart_ = ycoord; } else if (object== 'u' || object=='y' || object=='w' || object=='1'|| object=='2' || object=='3' || object=='7' || object =='8' || object== 'v' || object== 't' || object== 'd'){ //create bush Background *background = new Background(object); background->setTop(ycoord + background->getHeight()); background->setBottom(ycoord); background->setLeft(xcoord); background->setRight(xcoord + background->getWidth()); //place in correct list if (xcoord<256) { activeDrawable_.append(background); } else { levelDrawable_.append(background); } } if (ycoord < 224) { ycoord += 16; } else if (ycoord == 224) { xcoord += 16; ycoord = 0; } } inFile.close(); }
bool BankTool::verifyCoin(const Coin &coin) const { return coin.verifyCoin(); }