bool OcTreeLUT::genNeighborKey(const OcTreeKey& node_key, const signed char& dir, OcTreeKey& neighbor_key) const { neighbor_key.k[0] = node_key.k[0]; neighbor_key.k[1] = node_key.k[1]; neighbor_key.k[2] = node_key.k[2]; unsigned int depth = 0; signed char curDir = dir; signed char pos; while (depth < max_depth) { pos = static_cast<signed char>(genPos(neighbor_key, depth)); changeKey(nf_values[pos][curDir], neighbor_key, depth); if (nf_rec_values[pos][curDir] != LUT_NO_REC) { // recurs curDir -= nf_rec_values[pos][curDir]; depth++; } else { return true; } } return false; };
/* InputPrefsPanel::addKey * Adds a new key to the currently selected keybind *******************************************************************/ void InputPrefsPanel::addKey() { // Get selected item wxTreeListItem item = list_binds->GetSelection(); BindListItemData* bind = ((BindListItemData*)list_binds->GetItemData(item)); // Do nothing if item is a group if (!bind) return; // Get parent-level keybind item if (!bind->bind) item = list_binds->GetItemParent(item); // Add new keybind item wxTreeListItem n = list_binds->AppendItem(item, "", -1, -1, new BindListItemData(keypress_t())); changeKey(n); // Delete item if no key was chosen (or dialog cancelled) bind = ((BindListItemData*)list_binds->GetItemData(n)); if (bind->key.key.IsEmpty()) list_binds->DeleteItem(n); else { // Otherwise update the new keybind text list_binds->SetItemText(n, 1, bind->key.as_string()); } }
/* InputPrefsPanel::onBtnChangeKey * Called when the 'Set Key' button is clicked *******************************************************************/ void InputPrefsPanel::onBtnChangeKey(wxCommandEvent& e) { // Get selected item wxTreeListItem item = list_binds->GetSelection(); // Change keybind if the item isn't a group if (list_binds->GetItemData(item)) changeKey(item); }
void MifareUltralightCCommands::changeKey(std::shared_ptr<AccessInfo> aiToWrite) { if (aiToWrite) { std::shared_ptr<MifareUltralightCAccessInfo> mAi = std::dynamic_pointer_cast<MifareUltralightCAccessInfo>(aiToWrite); EXCEPTION_ASSERT_WITH_LOG(mAi, std::invalid_argument, "aiToWrite must be a MifareUltralightCAccessInfo."); if (mAi->key) { changeKey(mAi->key); } } }
Set *dijkstra(Graph *g, Label v, int Home, int n) { // for the school vertex v, find all indices for homes and put all into // a set Heap *H; Edge *Eu; Set *S; int i, usize; Label u; float R[n], delta; // create a heap to store the distance for every vertices // and an array to store dist values H = createHeap(); for (i=0;i<n;i++) { if (i==v) { insert(H, i, 0); R[i]=0; continue; } insert(H, i, INFINITY); R[i] = INFINITY; } // then loop through the heap while (H->n) { // extract the min in the heap u = removeMin(H); // if dist of u exceeds 1km, stop the loop if (R[u]>1000) { break; } Eu = graph_get_edge_array(g, u, &usize); for (i=0;i<usize;i++) { if (R[Eu[i].u]>R[u]+ *(float*)(Eu[i].data)) { delta = R[u] + *(float*)(Eu[i].data) - R[Eu[i].u]; changeKey(H, Eu[i].u, delta); R[Eu[i].u] = R[u]+ *(float*)(Eu[i].data); } } } // now add all home indices with in the range of 1km into the set S = set_new(); for (i=0;i<Home;i++) { if (R[i]<=1000) { set_add(S, i); } } return S; }
void setCover(Universe *Uni,int num_houses) { Heap *Q = createHeap(); set_t *covered = create_set(num_houses); for(int i=0;i<Uni->size_of_universe;i++) { insert_in_heap(Q,i,Uni->sets[i].covered_items,max_func); } while(covered->covered_items < num_houses) { if(isEmpty(Q)) { break; } HeapItem max = removeTop(Q,max_func); //updating the covered set for(int i=0;i<Uni->sets[max.dataIndex].covered_items;i++) { //if its not covered if(!covered->set[Uni->sets[max.dataIndex].set[i]]) { //set to the house being covered covered->set[Uni->sets[max.dataIndex].set[i]] = 1; //increment number of covered houses covered->covered_items++; } } //flag the current set to be covered Uni->sets[max.dataIndex].covered = 1; //update the other sets for(int i=0;i<Uni->size_of_universe;i++) { //if they are not already covered if(!Uni->sets[i].covered) { //find set diff and update the heap int diff = set_diff(&Uni->sets[i],covered); changeKey(Q,i,diff,max_func); } } } if(covered->covered_items < num_houses) { fprintf(stderr, "Not enough houses to cover all houses.\n"); exit(EXIT_FAILURE); } for(int i=0; i<Uni->size_of_universe;i++) { if(Uni->sets[i].covered) { printf("%d\n",i); } } destroyHeap(Q); free_set(covered); free_Universe(Uni); }
KKeyChooser::KKeyChooser( QDict<KKeyEntry> *aKeyDict, QWidget *parent ) : QWidget( parent ) { bKeyIntercept = FALSE; kbMode = NoKey; aKeyIt = new QDictIterator<KKeyEntry> ( *aKeyDict ); // TOP LAYOUT MANAGER // The following layout is used for the dialog // LIST LABELS LAYOUT // SPLIT LIST BOX WIDGET // CHOOSE KEY GROUP BOX WIDGET // BUTTONS LAYOUT // Items are added to topLayout as they are created. QBoxLayout *topLayout = new QVBoxLayout( this, 0, 10 ); // CREATE LIST LABELS QGridLayout *stackLayout = new QGridLayout( 2, 2, 2); topLayout->addLayout( stackLayout, 50 ); stackLayout->setRowStretch(1,10); keyLabel = new QLabel(this); stackLayout->addWidget(keyLabel, 0, 1); keyLabel->setText( i18n("Current key") ); keyLabel->setFixedHeight( keyLabel->sizeHint().height() ); // CREATE SPLIT LIST BOX // Copy all currentKeyCodes to configKeyCodes // and fill up the split list box with the action/key pairs. wList = new KSplitList( this ); stackLayout->addMultiCellWidget( wList, 1, 1, 0, 1 ); actLabel = new QLabel( wList, i18n("&Action"), this ); stackLayout->addWidget( actLabel, 0, 0 ); actLabel->setFixedHeight( actLabel->sizeHint().height() ); wList->setAutoUpdate(FALSE); wList->setFocus(); aIt = aKeyIt; aIt->toFirst(); while ( aIt->current() ) { aIt->current()->aConfigKeyCode = aIt->current()->aCurrentKeyCode; KSplitListItem *sli = new KSplitListItem( item( aIt->current()->aConfigKeyCode, aIt->currentKey() ) ); connect( wList, SIGNAL( newWidth( int ) ), sli, SLOT( setWidth( int ) ) ); wList->insertItem( sli ); ++ ( *aIt ); } if ( wList->count() == 0 ) wList->setEnabled( FALSE ); //connect( wList, SIGNAL( selected( int ) ), SLOT( toChange( int ) ) ); connect( wList, SIGNAL( highlighted( int ) ), SLOT( updateAction( int ) ) ); // CREATE CHOOSE KEY GROUP fCArea = new QGroupBox( this ); topLayout->addWidget( fCArea, 1 ); fCArea->setTitle( i18n("Choose a key for the selected action") ); fCArea->setFrameStyle( QFrame::Box | QFrame::Sunken ); // CHOOSE KEY GROUP LAYOUT MANAGER QGridLayout *grid = new QGridLayout( fCArea, 6, 4, 5 ); grid->setRowStretch(0,10); grid->setRowStretch(1,10); grid->setRowStretch(2,10); grid->setRowStretch(3,10); grid->setRowStretch(4,10); grid->setRowStretch(5,10); grid->setColStretch(0,0); grid->setColStretch(1,10); grid->setColStretch(2,90); grid->setColStretch(3,0); grid->addRowSpacing(0,15); grid->addRowSpacing(5,1); kbGroup = new QButtonGroup( fCArea ); kbGroup->hide(); kbGroup->setExclusive( true ); QRadioButton *rb = new QRadioButton( i18n("&No key"), fCArea ); rb->adjustSize(); rb->setFixedHeight( rb->height() ); rb->setMinimumWidth( rb->width() ); kbGroup->insert( rb, NoKey ); grid->addMultiCellWidget( rb, 1, 1, 1, 2 ); rb = new QRadioButton( i18n("&Default key"), fCArea ); rb->adjustSize(); rb->setFixedHeight( rb->height() ); rb->setMinimumWidth( rb->width() ); kbGroup->insert( rb, DefaultKey ); grid->addMultiCellWidget( rb, 2, 2, 1, 2 ); rb = new QRadioButton( i18n("&Custom key"), fCArea ); rb->adjustSize(); rb->setFixedHeight( rb->height() ); rb->setMinimumWidth( rb->width() ); kbGroup->insert( rb, CustomKey ); connect( kbGroup, SIGNAL( clicked( int ) ), SLOT( keyMode( int ) ) ); grid->addMultiCellWidget( rb, 3, 3, 1, 2 ); QBoxLayout *pushLayout = new QHBoxLayout( 2 ); grid->addLayout( pushLayout, 4, 2 ); cShift = new QCheckBox( fCArea ); cShift->setText( "SHIFT" ); cShift->setEnabled( FALSE ); connect( cShift, SIGNAL( clicked() ), SLOT( shiftClicked() ) ); cCtrl = new QCheckBox( fCArea ); cCtrl->setText( "CTRL" ); cCtrl->setEnabled( FALSE ); connect( cCtrl, SIGNAL( clicked() ), SLOT( ctrlClicked() ) ); cAlt = new QCheckBox( fCArea ); cAlt->setText( "ALT" ); cAlt->setEnabled( FALSE ); connect( cAlt, SIGNAL( clicked() ), SLOT( altClicked() ) ); bChange = new KKeyButton("key", fCArea); bChange->setEnabled( FALSE ); connect( bChange, SIGNAL( clicked() ), SLOT( changeKey() ) ); // Set height of checkboxes to basic key button height. // Basic key button height = push button height. cAlt->adjustSize(); cAlt->setFixedHeight( bChange->sizeHint().height() ); cAlt->setMinimumWidth( cAlt->width() ); cShift->adjustSize(); cShift->setFixedHeight( bChange->sizeHint().height() ); cShift->setMinimumWidth( cShift->width() ); cCtrl->adjustSize(); cCtrl->setFixedHeight( bChange->sizeHint().height() ); cCtrl->setMinimumWidth( cCtrl->width() ); fCArea->setMinimumHeight( bChange->sizeHint().height() + 20 + 3*rb->height() + 4*10); // Add widgets to the geometry manager pushLayout->addWidget( cShift ); pushLayout->addSpacing( 8 ); pushLayout->addWidget( cCtrl ); pushLayout->addSpacing( 8 ); pushLayout->addWidget( cAlt ); pushLayout->addSpacing( 18 ); pushLayout->addWidget( bChange ); pushLayout->addStretch( 10 ); lNotConfig = new QLabel(fCArea); lNotConfig->resize(0,0); lNotConfig->setFont( QFont("Helvetica", 14, QFont::Bold) ); lNotConfig->setAlignment( AlignCenter ); lNotConfig->setFrameStyle( QFrame::Panel | QFrame::Sunken ); if ( wList->count()==0 ) lNotConfig->setText(i18n("No keys defined")); else { lNotConfig->setText(i18n("Not configurable")); lNotConfig->hide(); } lNotConfig->hide(); lInfo = new QLabel(fCArea); resize(0,0); lInfo->setAlignment( AlignCenter ); lInfo->setEnabled( FALSE ); lInfo->hide(); wList->setAutoUpdate(TRUE); wList->update(); globalDict = new QDict<int> ( 37, false ); globalDict->setAutoDelete( true ); readGlobalKeys(); topLayout->activate(); }
void Dijkstra(Graph *g,int source,Universe *Uni,int (cmp)(int,int)) { int *dist; dist = (int*)malloc(sizeof(int)*(g->number_of_vertices)); assert(dist); //set all vertices distance to INF for(int i=0;i<g->number_of_vertices;i++) { dist[i] = INF; } Heap *Q = createHeap(); //insert everything into heap for(int i=0;i<g->number_of_vertices;i++) { if(i==source) { insert_in_heap(Q,i,0,cmp); } else { insert_in_heap(Q,i,INF,cmp); } } // update the distance of source dist[source] = 0; while(!isEmpty(Q)) { HeapItem min = removeTop(Q,cmp); // min can't be > 1000, if so we can stop if(min.key > MAX_KM) { break; } // prune any schools, only houses if(min.dataIndex < g->num_houses) { insert(Uni, source-g->num_houses, min.dataIndex); } int n_edges; //get all edges from min.dataIndex Edge *edges = graph_get_edge_array(g,min.dataIndex,&n_edges); for(int i=0;i<n_edges;i++) { //update all the edges distances if there is a minimum if(dist[edges[i].u] > (dist[min.dataIndex] +edges[i].weight)) { dist[edges[i].u] = dist[min.dataIndex]+edges[i].weight; // update the heap changeKey(Q,edges[i].u,dist[edges[i].u],cmp); } } } }
int main(int, char **) { introduction(); ReaderProviderPtr provider; ReaderUnitPtr readerUnit; ChipPtr chip; std::tie(provider, readerUnit, chip) = pcsc_test_init(); PRINT_TIME("CHip identifier: " << logicalaccess::BufferHelper::getHex(chip->getChipIdentifier())); LLA_ASSERT(chip->getCardType() == "DESFireEV1", "Chip is not an DESFireEV1, but is " + chip->getCardType() + " instead."); auto location_root_node = chip->getRootLocationNode(); auto cmd = std::dynamic_pointer_cast<logicalaccess::DESFireISO7816Commands>( chip->getCommands()); auto cmdev1 = std::dynamic_pointer_cast<logicalaccess::DESFireEV1ISO7816Commands>( chip->getCommands()); LLA_ASSERT(cmd && cmdev1, "Cannot get correct command object from chip."); cmd->selectApplication(0x00); cmd->authenticate(0); cmd->erase(); cmdev1->createApplication(0x521, logicalaccess::DESFireKeySettings::KS_DEFAULT, 3, logicalaccess::DESFireKeyType::DF_KEY_AES, logicalaccess::FIDS_NO_ISO_FID, 0, std::vector<unsigned char>()); cmd->selectApplication(0x521); std::shared_ptr<logicalaccess::DESFireKey> key(new logicalaccess::DESFireKey()); key->setKeyType(logicalaccess::DESFireKeyType::DF_KEY_AES); cmd->authenticate(0, key); LLA_SUBTEST_PASSED("Authenticate"); logicalaccess::DESFireAccessRights ar; ar.readAccess = logicalaccess::TaskAccessRights::AR_KEY2; ar.writeAccess = logicalaccess::TaskAccessRights::AR_KEY1; ar.readAndWriteAccess = logicalaccess::TaskAccessRights::AR_KEY1; ar.changeAccess = logicalaccess::TaskAccessRights::AR_KEY1; cmdev1->createStdDataFile(0x00, logicalaccess::EncryptionMode::CM_ENCRYPT, ar, 4, 0); cmd->authenticate(1, key); std::vector<unsigned char> data = {0x01, 0x02, 0x03, 0x04}, tmp; cmdev1->writeData(0, 0, data, logicalaccess::EncryptionMode::CM_ENCRYPT); cmd->authenticate(2, key); tmp = cmdev1->readData(0, 0, 4, logicalaccess::EncryptionMode::CM_ENCRYPT); LLA_ASSERT(std::equal(data.begin(), data.end(), tmp.begin()), "read and write data are different!"); LLA_SUBTEST_PASSED("WriteRead"); cmd->authenticate(0x00, key); cmd->deleteFile(0x00); cmd->authenticate(0x00, key); std::shared_ptr<logicalaccess::DESFireKey> newkey( new logicalaccess::DESFireKey("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03")); cmd->changeKey(0x00, newkey); LLA_SUBTEST_PASSED("ChangeKey"); cmd->selectApplication(0x00); cmd->authenticate(0); cmd->deleteApplication(0x521); auto service = std::dynamic_pointer_cast<logicalaccess::AccessControlCardService>( chip->getService(logicalaccess::CardServiceType::CST_ACCESS_CONTROL)); LLA_ASSERT(service, "Cannot retrieve access control service from chip."); auto location = std::make_shared<logicalaccess::DESFireLocation>(); location->aid = 0x522; location->file = 0; auto ai = std::make_shared<logicalaccess::DESFireAccessInfo>(); auto format = std::make_shared<logicalaccess::Wiegand26Format>(); format->setUid(1000); format->setFacilityCode(67); service->writeFormat(format, location, ai, ai); auto formattmp = std::make_shared<logicalaccess::Wiegand26Format>(); auto rformat = std::dynamic_pointer_cast<logicalaccess::Wiegand26Format>( service->readFormat(formattmp, location, ai)); if (!rformat || rformat->getUid() != 1000 || rformat->getFacilityCode() != 67) THROW_EXCEPTION_WITH_LOG(std::runtime_error, "Bad format"); LLA_SUBTEST_PASSED("ReadFormat"); pcsc_test_shutdown(readerUnit); return EXIT_SUCCESS; }