void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> *dists) { //The first time we print a record is when we print any header, because the header //hasn't been read from the query file until after the first record has also been read. checkForHeader(); const ContextClosest *context = static_cast<const ContextClosest *>(_context); bool deleteBlocks = false; const Record *keyRec = keyList.getKey(); RecordKeyVector blockList(keyRec); if (keyRec->getType() == FileRecordTypeChecker::BAM_RECORD_TYPE) { _bamBlockMgr->getBlocks(blockList, deleteBlocks); _currBamBlockList = &blockList; } if (!keyList.empty()) { int distCount = 0; for (RecordKeyVector::const_iterator_type iter = keyList.begin(); iter != keyList.end(); iter = keyList.next()) { const Record *hitRec = *iter; printKey(keyRec, keyRec->getStartPosStr(), keyRec->getEndPosStr()); tab(); addDbFileId(hitRec->getFileIdx()); printKey(hitRec, hitRec->getStartPosStr(), hitRec->getEndPosStr()); if (dists != NULL) { tab(); int dist = (*dists)[distCount]; //if not using sign distance, use absolute value instead. dist = context->signDistance() ? dist : abs(dist); _outBuf.append(dist); distCount++; } newline(); if (needsFlush()) flush(); } } else { printKey(keyRec, keyRec->getStartPosStr(), keyRec->getEndPosStr()); tab(); // need to add a dummy file id if multiple DB files are used if (_context->getNumInputFiles() > 2) { _outBuf.append('.'); tab(); } null(false, true); if (context->reportDistance()) { tab(); _outBuf.append(-1); } newline(); } if (deleteBlocks) { _bamBlockMgr->deleteBlocks(blockList); _currBamBlockList = NULL; } return; }
/*! \fn void aes256CtrTest(void) * \brief Perform a CTR test using test vectors found in * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf * page 57 */ void aes256CtrTest(void) { // init aes256CtrCtx_t ctx; aes256CtrInit(&ctx, key, iv, 16); // Encrypt init string printTextP(PSTR("CTR-AES256Encrypt")); // Print key printKey(key); // Encrypt TEST 1 printBlock(1); printEncryptTest(&ctx, v1, 16); // Encrypt TEST 2 printBlock(2); printEncryptTest(&ctx, v2, 16); // Encrypt TEST 3 printBlock(3); printEncryptTest(&ctx, v3, 16); // Encrypt TEST 4 printBlock(4); printEncryptTest(&ctx, v4, 16); // Decrypt init string printTextP(PSTR("\n\nCTR-AES256Decrypt")); aes256CtrSetIv(&ctx, iv, 16); // print key printKey(key); // Encrypt TEST 1 printBlock(1); printDecryptTest(&ctx, v1, 16); // Encrypt TEST 2 printBlock(2); printDecryptTest(&ctx, v2, 16); // Encrypt TEST 3 printBlock(3); printDecryptTest(&ctx, v3, 16); // Encrypt TEST 4 printBlock(4); printDecryptTest(&ctx, v4, 16); }
static void ptreeCheck( ptree_sTable *tp, pool_tRef nr, int *count, int *maxlevel, int *hight, int level, char *(*printKey)(ptree_sNode *)) { int comp; int hleft; int hright; ptree_sNode *np, *left, *right; pwr_tStatus sts; if (nr == tp->g->null) { *hight = 0; return; } if (level > *maxlevel) *maxlevel = level; np = pool_Address(&sts, tp->php, nr); ptreeCheck(tp, np->left, count, maxlevel, &hleft, level+1, printKey); if (np->left != tp->g->null) { left = pool_Address(&sts, tp->php, np->left); if (left->parent != nr) { printf("leftLinkerror: Node key: %s not linked to parent key: %s\n", printKey(left), printKey(np)); } comp = tp->compareFunc(tp, np, left); if (comp < 1) { printf("leftLink sort error: Node key: %s not less than key: %s\n", printKey(left), printKey(np)); } } (*count)++; ptreeCheck(tp, np->right, count, maxlevel, &hright, level+1, printKey); if (np->right != tp->g->null) { right = pool_Address(&sts, tp->php, np->right); if (right->parent != nr) { printf("rightLinkerror: Node key: %s not linked to parent key: %s\n", printKey(right), printKey(np)); } comp = tp->compareFunc(tp, np, right); if (comp > -1) { printf("rightLink sort error: Node key: %s not greater than key: %s\n", printKey(right), printKey(np)); } } if ((hright - hleft) != np->bal) { printf("balerror key: %s, level: %d, hr: %d, hl: %d, bal: %d\n", printKey(np), level, hright, hleft, np->bal); } *hight = (hright > hleft ? hright : hleft) + 1; }
void printPubKey(feePubKey pubKey) { pubKeyInst *pkinst = pubKey; printf("\ncurveParams:\n"); printCurveParams(pkinst->cp); printf("plus:\n"); printKey(pkinst->plus); printf("minus:\n"); printKey(pkinst->minus); if(pkinst->privGiant != NULL) { printf("privGiant : "); printGiant(pkinst->privGiant); } }
static void msBedPrintTable(struct bed *bedList, struct hash *erHash, char *itemName, char *expName, float minScore, float maxScore, float stepSize, int base, void(*printHeader)(struct bed *bedList, struct hash *erHash, char *item), void(*printRow)(struct bed *bedList,struct hash *erHash, int expIndex, char *expName, float maxScore, enum expColorType colorScheme), void(*printKey)(float minVal, float maxVal, float size, int base, struct rgbColor(*getColor)(float val, float max, enum expColorType colorScheme), enum expColorType colorScheme), struct rgbColor(*getColor)(float val, float max, enum expColorType colorScheme), enum expColorType colorScheme) /* prints out a table from the data present in the bedList */ { int i,featureCount=0; if(bedList == NULL) errAbort("hgc::msBedPrintTable() - bedList is NULL"); featureCount = slCount(bedList); /* time to write out some html, first the table and header */ if(printKey != NULL) printKey(minScore, maxScore, stepSize, base, getColor, colorScheme); printf("<p>\n"); printf("<basefont size=-1>\n"); printf("<table bgcolor=\"#000000\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tr><td>"); printf("<table bgcolor=\"#fffee8\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">"); printHeader(bedList, erHash, itemName); for(i=0; i<bedList->expCount; i++) { printRow(bedList, erHash, i, expName, maxScore, colorScheme); } printf("</table>"); printf("</td></tr></table>"); printf("</basefont>"); }
static void recordKeyboardEvent(int keyCode, int pressCode, int modifiers, int ucs4) { sqKeyboardEvent *evt= allocateKeyboardEvent(); if (keyCode < 0) keyCode= 0; evt->charCode= keyCode; evt->pressCode= pressCode; evt->modifiers= modifiers; evt->utf32Code= ucs4; evt->reserved1= evt->windowIndex= 0; signalInputEvent(); #if DEBUG_KEYBOARD_EVENTS printf("EVENT: key"); switch (pressCode) { case EventKeyDown: printf(" down "); break; case EventKeyChar: printf(" char "); break; case EventKeyUp: printf(" up "); break; default: printf(" ***UNKNOWN***"); break; } printModifiers(modifiers); printKey(keyCode); printf(" ucs4 %d\n", ucs4); #endif }
void doSim() { uint8_t key[KEYBYTES]; int i,j; PTW_attackstate * state; state = PTW_newattackstate(); printf("starting new sim\n"); for (i = 0; i < HSBYTES; i++) { key[IVBYTES + i] = rand()%n; } for (i = 0; i < STARTSESS; i++) { addRound(key, state); } printStats(state, i, &key[3]); while (i < ENDSESS) { for (j = 0; j < INCSESS; j++) { addRound(key, state); } i += INCSESS; printStats(state, i, &key[3]); } printKey(&key[3], 13); PTW_freeattackstate(state); }
static void recordKeystroke(int keyCode) /* DEPRECATED */ { if (inputEventSemaIndex == 0) { int keystate= keyCode | (modifierState << 8); # if DEBUG_KEYBOARD_EVENTS printf("RECORD keystroke"); printModifiers(modifierState); printKey(keyCode); printf(" = %d 0x%x\n", keystate, keystate); # endif if (keystate == getInterruptKeycode()) setInterruptPending(true); else { keyBuf[keyBufPut]= keystate; keyBufPut= (keyBufPut + 1) % KEYBUF_SIZE; if (keyBufGet == keyBufPut) { /* buffer overflow; drop the last character */ keyBufGet= (keyBufGet + 1) % KEYBUF_SIZE; keyBufOverflows++; } } } }
static void treeCheck(tree_sTable *tp, tree_sNode *np, int *count, int *maxlevel, int *hight, int level, char *(*printKey)(tree_sNode *)) { int comp; int hleft; int hright; if (np == tp->null) { *hight = 0; return; } if (level > *maxlevel) *maxlevel = level; treeCheck(tp, np->left, count, maxlevel, &hleft, level+1, printKey); if (np->left != tp->null) { if (np->left->parent != np) { printf("leftLinkerror: Node key: %s not linked to parent key: %s\n", printKey(np->left), printKey(np)); } comp = tp->compareFunc(tp, np, np->left); if (comp < 1) { printf("leftLink sort error: Node key: %s not less than key: %s\n", printKey(np->left), printKey(np)); } } (*count)++; treeCheck(tp, np->right, count, maxlevel, &hright, level+1, printKey); if (np->right != tp->null) { if (np->right->parent != np) { printf("rightLinkerror: Node key: %s not linked to parent key: %s\n", printKey(np->right), printKey(np)); } comp = tp->compareFunc(tp, np, np->right); if (comp > -1) { printf("rightLink sort error: Node key: %s not greater than key: %s\n", printKey(np->right), printKey(np)); } } if ((hright - hleft) != np->bal) { printf("balerror key: %s, level: %d, hr: %d, hl: %d, bal: %d\n", printKey(np), level, hright, hleft, np->bal); } *hight = (hright > hleft ? hright : hleft) + 1; }
std::ostream & StateStorage::print( std::ostream & o ) const { //Print the set of all states. o << "Q: {\n "; bool first = true; for(const_iterator it = beginStates(); it != endStates() ; it++, first=false ) { if( !first ) o << ",\n "; printKey(o,*it); o << " (=" << *it << ")"; } o << "}\n" << std::endl; //Prints the initial states. o << "Q0: {\n "; first = true; for(const_iterator it = beginInitialStates(); it != endInitialStates() ; it++, first=false ) { if( !first ) o << ",\n "; printKey(o,*it); o << " (=" << *it << ")"; } o << "}\n" << std::endl; //Print the final states. o << "Qf: {\n "; first = true; for(const_iterator it = beginFinalStates(); it != endFinalStates() ; it++, first=false ) { if( !first ) o << ",\n "; printKey(o,*it); o << " (=" << *it << ")"; } o << "}" << std::endl; return o; }
static void listKey(struct afsconf_dir *dir, int argc, char **argv) { struct afsconf_typedKeyList *keys; int i; int code; code = afsconf_GetAllKeys(dir, &keys); if (code) { afs_com_err("asetkey", code, "while retrieving keys"); exit(1); } for (i = 0; i < keys->nkeys; i++) { afsconf_keyType type; int kvno; int minorType; struct rx_opaque *keyMaterial; afsconf_typedKey_values(keys->keys[i], &type, &kvno, &minorType, &keyMaterial); switch(type) { case afsconf_rxkad: if (kvno != -1) { printf("rxkad\tkvno %4d: key is: ", kvno); printKey(keyMaterial); } break; case afsconf_rxkad_krb5: if (kvno != -1) { printf("rxkad_krb5\tkvno %4d enctype %d; key is: ", kvno, minorType); printKey(keyMaterial); } break; default: printf("unknown(%d)\tkvno %4d subtype %d; key is: ", type, kvno, minorType); printKey(keyMaterial); break; } } printf("All done.\n"); }
void RecordOutputMgr::printClosest(RecordKeyVector &keyList, const vector<int> *dists) { const ContextClosest *context = static_cast<const ContextClosest *>(_context); bool deleteBlocks = false; RecordKeyVector blockList(keyList.getKey()); if (keyList.getKey()->getType() == FileRecordTypeChecker::BAM_RECORD_TYPE) { _bamBlockMgr->getBlocks(blockList, deleteBlocks); _currBamBlockList = &blockList; } if (!keyList.empty()) { int distCount = 0; for (RecordKeyVector::const_iterator_type iter = keyList.begin(); iter != keyList.end(); iter = keyList.next()) { printKey(keyList.getKey()); tab(); addDbFileId((*iter)->getFileIdx()); (*iter)->print(_outBuf); if (dists != NULL) { tab(); _outBuf.append((*dists)[distCount]); distCount++; } newline(); if (needsFlush()) flush(); } } else { printKey(keyList.getKey()); tab(); null(true, false); if (context->reportDistance()) { tab(); _outBuf.append(-1); } newline(); } if (deleteBlocks) { _bamBlockMgr->deleteBlocks(blockList); _currBamBlockList = NULL; } return; }
int main(int argc, char** argv){ //define the files to be used char *fileName, *inputFile, *outFile; int port; long fileLength=0; int opt, err; //add salt according to taste char *password, *salt = "NaCl"; int keyLength = 32, macLength = 32, blockLength = 16; int numberOfIterations = 4096; char *initCounter; char *key; //parse the arguments and let the program decide the mode to be followed opt = parseArgs(argc, argv, &fileName, NULL, &port); checkErr(opt, USAGE_STR); if(D_DAEMON == opt){ err = receiveFile(port, &inputFile, &fileLength); checkErr(err, "File receive error"); } else if(L_LOCAL == opt){ err = readFile(fileName, &fileLength, &inputFile ); checkErr(err, "File read error"); } password = getpass("Password:"******"Key derivation error"); printKey(key, keyLength); err = verifyMac(key, keyLength, inputFile, fileLength, macLength); checkErr(err, "HMAC verification error"); initCounter = (char*)(malloc(blockLength * sizeof(char))); memset((void *)initCounter, 0, (size_t)(blockLength * sizeof(char))); err = aesCounter(key, keyLength, inputFile, fileLength - macLength, initCounter, blockLength, &outFile); checkErr(err, "Decryption error"); err = writeFile(fileName, outFile, fileLength - macLength, NULL, 1, opt); checkErr(err, "Error in output file operation"); printf("%ld bytes written.\n", fileLength - macLength); return 0; }
int drawMap(){ printGrid(); printPond(); printField(); steve(8,8); printKey(40,10); attron(COLOR_PAIR(5)); mvprintw(usry,usrx*2,"@"); attron(COLOR_PAIR(4)); mvprintw(0,40,"Player name: %s",pName); mvprintw(1,40,"Health: %dHP",health); mvprintw(2,40,"Hunger: %d", hunger); mvprintw(4,40,"Description:"); return 0; }
int main(int argc, char** argv) { printKey(); // Command "key" printed to standard out glutInit(&argc, argv); my_setup(canvas_Width, canvas_Height, canvas_Name); initial(); // Set initial values of global variables glutDisplayFunc(display_func); // Register display callback glutKeyboardFunc(keypress); // Register key press callback glutMainLoop(); // Execute until killed return 0; }
/** * escreve as chaves de uma abp usando as funcoes de escrita dadas * a profundidade determina quantos espacos haverao a esquerda */ void abpPrint(t_abp *tree,void (*printKey)(void *),void (*printData)(void *),int depth) { if(tree == NULL) return; int i; for(i=0;i<depth;i++) printf("|"); printKey(tree->key); printf(":"); printData(tree->data); printf("\n"); abpPrint(tree->left,printKey,printData,depth+1); abpPrint(tree->right,printKey,printData,depth+1); }
int main() { int key[SIZE]; int guess[SIZE]; srand(time(0)); // Set up the game. fillKey(key, SIZE); int correct = 0, newCorrect; while (1) { getGuess(guess, SIZE); newCorrect = numCorrect(guess, key, SIZE); // No new correct digits were discovered, you lose. if (newCorrect <= correct) { printf("Sorry, you did not improve the number of correct digits.\n"); printf("You lose.\n"); printKey(key, SIZE); break; } // Print out which digits were correct. else { printNumCorrect(guess, key, SIZE); correct = newCorrect; } // Winning case! if (correct == SIZE) { printf("Congratulations, you won the car!\n"); break; } } system("PAUSE"); return 0; }
/** * * @brief print the collection of transitions * * @param - o: the output stream to print to * @return the output stream that was printed to * */ std::ostream & TransitionStorage::print( std::ostream & o ) const { //Print call transitions. o << "Delta_c: {\n "; bool first = true; for( CallIterator cit = callTrans.begin(); cit != callTrans.end(); cit++, first=false ) { if( !first ) o << ", \n "; o << "("; printKey(o,getCallSite(*cit)); o << " (=" << getCallSite(*cit) << ") "; o << ", "; printKey(o,getCallSym(*cit)); o << ", "; printKey(o,getEntry(*cit)); o << " (=" << getEntry(*cit) << ") "; o << ")"; } o << "\n}\n"; //Print internal transitions. o << "Delta_i: {\n "; first = true; for(InternalIterator iit = internalTrans.begin(); iit != internalTrans.end(); iit++, first=false ) { if( !first ) o << ",\n "; o << "("; printKey(o,getSource(*iit)); o << " (=" << getSource(*iit) << ") "; o << ", "; printKey(o,getInternalSym(*iit)); o << ", "; printKey(o,getTarget(*iit)); o << " (=" << getTarget(*iit) << ") "; o << ")"; } o << "\n}\n"; //Print return transitions. o << "Delta_r: {\n "; first = true; for(ReturnIterator rit = returnTrans.begin(); rit != returnTrans.end(); rit++, first = false ) { if( !first ) o << ",\n "; o << "("; printKey(o,getExit(*rit)); o << " (=" << getExit(*rit) << ") "; o << ", "; printKey(o,getCallSite(*rit)); o << " (=" << getCallSite(*rit) << ") "; o << ", "; printKey(o,getReturnSym(*rit)); o << ", "; printKey(o,getReturnSite(*rit)); o << " (=" << getReturnSite(*rit) << ") "; o << ")"; } o << "\n}\n"; return o; }
int main(int argc, char **argv) { string inp = "secrets! very secrets!"; cout << "inp = \"" << inp << "\"" << endl; vector<pt_key32> k = pt_genKey(); pt_expandKey(k); printKey(k); // initialize helib long m=0, p=2, r=1; long L=23; long c=3; long w=64; long d=0; long security = 128; cout << "L=" << L << endl; ZZX G; cout << "Finding m..." << endl; m = FindM(security,L,c,p,d,0,0); cout << "Generating context..." << endl; FHEcontext context(m, p, r); cout << "Building mod-chain..." << endl; buildModChain(context, L, c); cout << "Generating keys..." << endl; FHESecKey seckey(context); const FHEPubKey& pubkey = seckey; G = context.alMod.getFactorsOverZZ()[0]; seckey.GenSecKey(w); addSome1DMatrices(seckey); EncryptedArray ea(context, G); global_nslots = ea.size(); cout << "nslots = " << global_nslots << endl; // set up globals CTvec maxint (ea, pubkey, transpose(uint32ToBits(0xFFFFFFFF))); global_maxint = &maxint; // HEencrypt key timer(true); cout << "Encrypting SIMON key..." << flush; vector<CTvec> encryptedKey = heEncrypt(ea, pubkey, k); timer(); // HEencrypt input cout << "Encrypting inp..." << flush; heblock ct = heEncrypt(ea, pubkey, inp); timer(); cout << "Running protocol..." << endl; for (size_t i = 0; i < T; i++) { cout << "Round " << i+1 << "/" << T << "..." << flush; encRound(encryptedKey[i], ct); timer(); // check intermediate result for noise cout << "decrypting..." << flush; vector<pt_block> bs = heblockToBlocks(seckey, ct); timer(); printf("block0 : 0x%08x 0x%08x\n", bs[0].x, bs[0].y); vector<pt_block> pt_bs = pt_simonEnc(k, inp, i+1); printf("should be : 0x%08x 0x%08x\n", pt_bs[0].x, pt_bs[0].y); cout << "decrypted : \"" << pt_simonDec(k, bs, i+1) << "\" " << endl; } return 0; }
int main(int argc, char *argv[]) { srand(time(NULL)); int fileSize, i, j, subkeySize = 1024, totalBytes = 0; // LOOOOOOOOOL int padMisses = 0; int got, numcrypts; char magic[2], dmagic[2]; uchar *aesKey, verifyBlock[22], backbuffer[16], subkey[1024]; uchar *plaintext = "<<'08infamouspat"; uchar *SHAworkspace; uchar salt[16], salted[16], dsalted[16]; uchar encbuf[4080], decbuf[4080]; aes_encrypt_ctx ctx[1]; char *openFile, *destFile; FILE *fd, *dfd; printIntro("Pump It Up Pro"); if (argc < 3) { printf("usage: %s <input file> <output file>\n", argv[0]); exit(0); } openFile = argv[1]; destFile = argv[2]; if ((fd = fopen(openFile, "rb")) == NULL) { fprintf(stderr, "%s: fopen(%s) failed D=\n", argv[0], argv[1]); exit(-1); } for (i = 0; i < subkeySize; i++) subkey[i] = rand() * 255; SHAworkspace = (uchar*)malloc(sizeof(uchar) * (subkeySize+47)); memcpy(SHAworkspace, subkey, subkeySize); memcpy(SHAworkspace+subkeySize, PProSubkeySalt, 47); aesKey = (uchar*)malloc(24 * sizeof(uchar)); memset(aesKey, '\0', 24); gcry_md_hash_buffer(GCRY_MD_SHA1, aesKey, SHAworkspace, subkeySize+47); printKey(aesKey); aes_encrypt_key(aesKey, 24, ctx); for (i = 0; i < 16; i++) salt[i] = rand() * 255; saltHash(salted, salt, 0x123456); aes_encrypt(salted, dsalted, ctx); for (i = 0; i < 16; i++) { verifyBlock[i] = plaintext[i] ^ dsalted[i]; } #ifdef KD_DEBUG printKey(aesKey); printbuffer("salt", salt); printbuffer("salted", salted); printbuffer("dsalted", dsalted); printbuffer("plaintext", plaintext); printbuffer("verifyBlock", verifyBlock); #endif if ((dfd = fopen(destFile, "wb")) == NULL) { fprintf(stderr, "%s: fopen(%s) failed D=\n", argv[0], destFile); fclose(fd); exit(-1); } fwrite("8O", 1, 2, dfd); fwrite(&subkeySize, 1, 4, dfd); fwrite(subkey, 1, subkeySize, dfd); fwrite(salt, 1, 16, dfd); fseek(fd, 0, SEEK_END); fileSize = ftell(fd); fseek(fd, 0, SEEK_SET); printf("file size: %u\n", fileSize); fwrite(&fileSize, 1, 4, dfd); fwrite(verifyBlock, 1, 16, dfd); printf("encrypting into %s...\n", destFile); do { if ((got = fread(decbuf, 1, 4080, fd)) == -1) { fprintf(stderr, "wtf..?\n"); fclose(dfd); fclose(fd); exit(-1); } numcrypts = got / 16; if (got % 16 > 0) { numcrypts++; } if (got > 0) { for (i = 0; i < numcrypts; i++) { //saltHash(salted, salt, numcrypts); //memcpy(salted, salt, 16); //salted[0] += numcrypts; aes_encrypt(salt, dsalted, ctx); // LOLOLOLOLOL // this should cover about a 320GB file, so we should be good... if (salt[0] == 255 && salt[1] == 255 && salt[2] == 255 && salt[3] == 255 && salt[4] == 255) salt[5]++; if (salt[0] == 255 && salt[1] == 255 && salt[2] == 255 && salt[3] == 255) salt[4]++; if (salt[0] == 255 && salt[1] == 255 && salt[2] == 255) salt[3]++; if (salt[0] == 255 && salt[1] == 255) salt[2]++; if (salt[0] == 255) salt[1]++; salt[0]++; for (j = 0; j < 16; j++) { encbuf[(i*16)+j] = dsalted[j] ^ decbuf[(i*16)+j]; } //decbuf[i] = dsalted[i%16] ^ encbuf[i]; } totalBytes += got; if (totalBytes > fileSize) { got -= totalBytes - fileSize; totalBytes -= totalBytes - fileSize; } fwrite(encbuf, 1, numcrypts * 16, dfd); } } while (got > 0); fclose(dfd); fclose(fd); return 0; }
/** * DEBUG function * Dump the keyboard layout to the release log. */ static void dumpLayout(Display *display) { LogRel(("Your keyboard layout does not appear to be fully supported by\n" "VirtualBox. If you are experiencing keyboard problems this.\n" "information may help us to resolve them.\n" "(Note: please tell us if you are using a custom layout.)\n\n" "The correct table for your layout is:\n")); /* First, build up a table of scan-to-key code mappings */ unsigned scanToKeycode[512] = { 0 }; int minKey, maxKey; XDisplayKeycodes(display, &minKey, &maxKey); for (int i = minKey; i < maxKey; ++i) scanToKeycode[X11DRV_KeyEvent(display, i)] = i; LogRel(("\"")); printKey(display, scanToKeycode[0x29]); /* `~ */ for (int i = 2; i <= 0xd; ++i) /* 1! - =+ */ { LogRel(("\",\"")); printKey(display, scanToKeycode[i]); } LogRel(("\",\n")); LogRel(("\"")); printKey(display, scanToKeycode[0x10]); /* qQ */ for (int i = 0x11; i <= 0x1b; ++i) /* wW - ]} */ { LogRel(("\",\"")); printKey(display, scanToKeycode[i]); } LogRel(("\",\n")); LogRel(("\"")); printKey(display, scanToKeycode[0x1e]); /* aA */ for (int i = 0x1f; i <= 0x28; ++i) /* sS - '" */ { LogRel(("\",\"")); printKey(display, scanToKeycode[i]); } LogRel(("\",\"")); printKey(display, scanToKeycode[0x2b]); /* \| */ LogRel(("\",\n")); LogRel(("\"")); printKey(display, scanToKeycode[0x2c]); /* zZ */ for (int i = 0x2d; i <= 0x35; ++i) /* xX - /? */ { LogRel(("\",\"")); printKey(display, scanToKeycode[i]); } LogRel(("\",\"")); printKey(display, scanToKeycode[0x56]); /* The 102nd key */ LogRel(("\",\"")); printKey(display, scanToKeycode[0x73]); /* The Brazilian key */ LogRel(("\",\"")); printKey(display, scanToKeycode[0x7d]); /* The Yen key */ LogRel(("\"\n\n")); }
int main(int argc, char *argv[]) { srand(time(NULL)); int fileSize, i, j, subkeySize = 1024, totalBytes = 0; // LOOOOOOOOOL int padMisses = 0; int got, numcrypts; char magic[2], dmagic[2]; uchar *aesKey, backbuffer[16], subkey[1024], verifyBlock[16]; uchar *plaintext = ":Dbyinfamouspat\0"; uchar encbuf[4080], decbuf[4080]; aes_encrypt_ctx ctx[1]; char *openFile, *destFile; FILE *fd, *dfd; printIntro("ITG2"); if (argc < 3) { printf("usage: %s <input file> <output file>\n", argv[0]); exit(0); } openFile = argv[1]; destFile = argv[2]; if ((fd = fopen(openFile, "rb")) == NULL) { fprintf(stderr, "%s: fopen(%s) failed D=\n", argv[0], argv[1]); exit(-1); } for (i = 0; i < subkeySize; i++) subkey[i] = rand() * 255; printf("retrieving key from dongle...\n"); aesKey = (uchar*)malloc(24 * sizeof(uchar)); if (getKey(subkey, aesKey) != 0) { fclose(fd); exit(-1); } aes_encrypt_key(aesKey, 24, ctx); aes_encrypt(plaintext, verifyBlock, ctx); #ifdef KD_DEBUG printKey(aesKey); printbuffer("plaintext",plaintext); printbuffer("verifyBlock",verifyBlock); #endif printf("encrypting into %s...\n", destFile); if ((dfd = fopen(destFile, "wb")) == NULL) { fprintf(stderr, "%s: fopen(%s) failed D=\n", argv[0], destFile); fclose(fd); exit(-1); } fseek(fd, 0, SEEK_END); fileSize = ftell(fd); fseek(fd, 0, SEEK_SET); fwrite(":|", 2, 1, dfd); fwrite(&fileSize, 1, 4, dfd); fwrite(&subkeySize, 1, 4, dfd); fwrite(subkey, 1, subkeySize, dfd); fwrite(verifyBlock, 1, 16, dfd); do { if ((got = fread(decbuf, 1, 4080, fd)) == -1) { fprintf(stderr, "%s: error: fread(%s) returned -1, exiting...\n", argv[0], openFile); fclose(dfd); fclose(dfd); exit(-1); } totalBytes += got; numcrypts = got / 16; if (got % 16 > 0) { numcrypts++; } if (got > 0) { memset(backbuffer, '\0', 16); for (i = 0; i < numcrypts; i++) { for (j = 0; j < 16; j++) { ((uchar*)(decbuf+(16*i)))[j] ^= (((uchar)backbuffer[j]) - j); } aes_encrypt(decbuf+(16*i), encbuf+(16*i), ctx); memcpy(backbuffer, encbuf+(16*i), 16); } fwrite(encbuf, 1, numcrypts*16, dfd); } } while (got > 0); printf("done :D\n"); fclose(dfd); fclose(fd); return 0; }
void RecordOutputMgr::reportOverlapDetail(const Record *keyRecord, const Record *hitRecord, int hitIdx) { //get the max start and min end as strings. const_cast<Record *>(hitRecord)->undoZeroLength(); const QuickString *startStr = NULL; const QuickString *endStr = NULL; int maxStart = 0; int minEnd = 0; int keyStart = keyRecord->getStartPos(); int keyEnd = keyRecord->getEndPos(); int hitStart = hitRecord->getStartPos(); int hitEnd = hitRecord->getEndPos(); if ( keyStart>= hitStart) { //the key start is after the hit start, but we need to check and make sure the hit end is at least after the keyStart. //The reason for this is that, in some rare cases, such as both the key and hit having been zero length intervals, //the normal process for intersection that allows us to simply report the maxStart and minEnd do not necessarily apply. if (hitEnd >= keyStart) { //this is ok. We have a normal intersection where the key comes after the hit. maxStart = keyStart; startStr = &(keyRecord->getStartPosStr()); minEnd = min(keyEnd, hitEnd); endStr = keyRecord->getEndPos() < hitRecord->getEndPos() ? &(keyRecord->getEndPosStr()) : &(hitRecord->getEndPosStr()); } else { //this is the weird case of not a "real" intersection. The keyStart is greater than the hitEnd. So just report the key as is. maxStart = keyStart; minEnd = keyEnd; startStr = &(keyRecord->getStartPosStr()); endStr = &(keyRecord->getEndPosStr()); } } else { //all of the above, but backwards. keyStart is before hitStart. if (keyEnd >= hitStart) { //normal intersection, key first maxStart = hitStart; startStr = &(hitRecord->getStartPosStr()); minEnd = min(keyEnd, hitEnd); endStr = keyRecord->getEndPos() < hitRecord->getEndPos() ? &(keyRecord->getEndPosStr()) : &(hitRecord->getEndPosStr()); } else { //this is the weird case of not a "real" intersection. The hitStart is greater than the keyEnd. So just report the hit as is. maxStart = hitStart; minEnd = hitEnd; startStr = &(hitRecord->getStartPosStr()); endStr = &(hitRecord->getEndPosStr()); } } if (!(static_cast<ContextIntersect *>(_context))->getWriteA() && !(static_cast<ContextIntersect *>(_context))->getWriteB() && !(static_cast<ContextIntersect *>(_context))->getWriteOverlap() && !(static_cast<ContextIntersect *>(_context))->getLeftJoin()) { printKey(keyRecord, *startStr, *endStr); newline(); if (needsFlush()) flush(); } else if (((static_cast<ContextIntersect *>(_context))->getWriteA() && (static_cast<ContextIntersect *>(_context))->getWriteB()) || (static_cast<ContextIntersect *>(_context))->getLeftJoin()) { printKey(keyRecord); tab(); addDbFileId(hitRecord->getFileIdx()); hitRecord->print(_outBuf); newline(); if (needsFlush()) flush(); } else if ((static_cast<ContextIntersect *>(_context))->getWriteA()) { printKey(keyRecord); newline(); if (needsFlush()) flush(); } else if ((static_cast<ContextIntersect *>(_context))->getWriteB()) { printKey(keyRecord, *startStr, *endStr); tab(); addDbFileId(hitRecord->getFileIdx()); hitRecord->print(_outBuf); newline(); if (needsFlush()) flush(); } else if ((static_cast<ContextIntersect *>(_context))->getWriteOverlap()) { int printOverlapBases = 0; if (_context->getObeySplits()) { printOverlapBases = _splitInfo->getOverlapBases(hitIdx); } else { printOverlapBases = minEnd - maxStart; } printKey(keyRecord); tab(); addDbFileId(hitRecord->getFileIdx()); hitRecord->print(_outBuf); tab(); int2str(printOverlapBases, _outBuf, true); newline(); if (needsFlush()) flush(); } const_cast<Record *>(keyRecord)->adjustZeroLength(); }
bool onKeyDown(const Keyboard& k){ printf("onKeyDown "); printKey(); return true; }
bool onKeyUp(const Keyboard& k){ printf("onKeyUp "); printKey(); return true; }
void RecordOutputMgr::reportOverlapDetail(const Record *keyRecord, const Record *hitRecord, int hitIdx) { // overlap interval is defined by min(e1,e2) - max(s1,s2) int maxStart = max(keyRecord->getStartPos(), hitRecord->getStartPos()); int minEnd = min(keyRecord->getEndPos(), hitRecord->getEndPos()); // need to undo our conversion of 1-based start coordinates to 0-based if (!keyRecord->isZeroBased()) maxStart++; // all of the different printing scenarios based upon the options used. if (!(static_cast<ContextIntersect *>(_context))->getWriteA() && !(static_cast<ContextIntersect *>(_context))->getWriteB() && !(static_cast<ContextIntersect *>(_context))->getWriteOverlap() && !(static_cast<ContextIntersect *>(_context))->getLeftJoin()) { const_cast<Record *>(keyRecord)->undoZeroLength(); printKey(keyRecord, maxStart, minEnd); } else if (((static_cast<ContextIntersect *>(_context))->getWriteA() && (static_cast<ContextIntersect *>(_context))->getWriteB()) || (static_cast<ContextIntersect *>(_context))->getLeftJoin()) { const_cast<Record *>(keyRecord)->undoZeroLength(); printKey(keyRecord); tab(); const_cast<Record *>(hitRecord)->undoZeroLength(); addDbFileId(hitRecord->getFileIdx()); hitRecord->print(_outBuf); } else if ((static_cast<ContextIntersect *>(_context))->getWriteA()) { const_cast<Record *>(keyRecord)->undoZeroLength(); printKey(keyRecord); } else if ((static_cast<ContextIntersect *>(_context))->getWriteB()) { printKey(keyRecord, maxStart, minEnd); tab(); addDbFileId(hitRecord->getFileIdx()); const_cast<Record *>(hitRecord)->undoZeroLength(); hitRecord->print(_outBuf); } else if ((static_cast<ContextIntersect *>(_context))->getWriteOverlap()) { int printOverlapBases = 0; if (_context->getObeySplits()) { printOverlapBases = _context->getSplitBlockInfo()->getOverlapBases(hitIdx); } else { // if one of the records was zerolength, the number of // overlapping bases needs to be corrected if (keyRecord->isZeroLength() || hitRecord->isZeroLength ()) { maxStart++; minEnd--; } printOverlapBases = minEnd - maxStart; } const_cast<Record *>(keyRecord)->undoZeroLength(); printKey(keyRecord); tab(); addDbFileId(hitRecord->getFileIdx()); const_cast<Record *>(hitRecord)->undoZeroLength(); hitRecord->print(_outBuf); tab(); int2str(printOverlapBases, _outBuf, true); } newline(); if (needsFlush()) flush(); const_cast<Record *>(hitRecord)->adjustZeroLength(); }
/* * FEE_SIG_USING_PROJ true : this is the "no Weierstrass" case * feeSigVerifyNoProj false : this is redefined to feeSigVerify */ feeReturn feeSigVerifyNoProj(feeSig sig, const unsigned char *data, unsigned dataLen, feePubKey pubKey) { giant Q = NULL; giant messageGiant = NULL; giant scratch = NULL; sigInst *sinst = (sigInst*) sig; feeReturn frtn; curveParams *cp; key origKey; // may be plus or minus key if(sinst->PmX == NULL) { dbgLog(("sigVerify without parse!\n")); frtn = FR_IllegalArg; goto out; } cp = feePubKeyCurveParams(pubKey); Q = newGiant(cp->maxDigits); /* * pick a key (+/-) * Q := P1 */ if(SIG_CURVE == CURVE_PLUS) { origKey = feePubKeyPlusCurve(pubKey); gtog(cp->x1Plus, Q); } else { origKey = feePubKeyMinusCurve(pubKey); gtog(cp->x1Minus, Q); } messageGiant = giant_with_data(data, dataLen); // M(ciphertext) /* Q := u 'o' P1 */ elliptic_simple(Q, sinst->u, cp); /* scratch := theirPub */ scratch = newGiant(cp->maxDigits); gtog(origKey->x, scratch); #if SIG_DEBUG if(sigDebug) { printf("verify origKey:\n"); printKey(origKey); printf("messageGiant: "); printGiant(messageGiant); printf("curveParams:\n"); printCurveParams(cp); } #endif // SIG_DEBUG /* scratch := M 'o' theirPub */ elliptic_simple(scratch, messageGiant, cp); #if SIG_DEBUG if(sigDebug) { printf("signature_compare, with\n"); printf("p0 = Q:\n"); printGiant(Q); printf("p1 = Pm:\n"); printGiant(sinst->PmX); printf("p2 = scratch = R:\n"); printGiant(scratch); } #endif // SIG_DEBUG if(signature_compare(Q, sinst->PmX, scratch, cp)) { frtn = FR_InvalidSignature; #if LOG_BAD_SIG printf("***yup, bad sig***\n"); #endif // LOG_BAD_SIG } else { frtn = FR_Success; } out: if(messageGiant != NULL) { freeGiant(messageGiant); } if(Q != NULL) { freeGiant(Q); } if(scratch != NULL) { freeGiant(scratch); } return frtn; }
feeReturn feeSigVerify(feeSig sig, const unsigned char *data, unsigned dataLen, feePubKey pubKey) { pointProjStruct Q; giant messageGiant = NULL; pointProjStruct scratch; sigInst *sinst = (sigInst*) sig; feeReturn frtn; curveParams *cp; key origKey; // may be plus or minus key if(sinst->PmX == NULL) { dbgLog(("sigVerify without parse!\n")); return FR_IllegalArg; } cp = feePubKeyCurveParams(pubKey); if(cp->curveType != FCT_Weierstrass) { return feeSigVerifyNoProj(sig, data, dataLen, pubKey); } borrowPointProj(&Q, cp->maxDigits); borrowPointProj(&scratch, cp->maxDigits); /* * Q := P1 */ gtog(cp->x1Plus, Q.x); gtog(cp->y1Plus, Q.y); int_to_giant(1, Q.z); messageGiant = giant_with_data(data, dataLen); // M(ciphertext) /* Q := u 'o' P1 */ ellMulProjSimple(&Q, sinst->u, cp); /* scratch := theirPub */ origKey = feePubKeyPlusCurve(pubKey); gtog(origKey->x, scratch.x); gtog(origKey->y, scratch.y); int_to_giant(1, scratch.z); #if SIG_DEBUG if(sigDebug) { printf("verify origKey:\n"); printKey(origKey); printf("messageGiant: "); printGiant(messageGiant); printf("curveParams:\n"); printCurveParams(cp); } #endif // SIG_DEBUG /* scratch := M 'o' theirPub */ ellMulProjSimple(&scratch, messageGiant, cp); #if SIG_DEBUG if(sigDebug) { printf("signature_compare, with\n"); printf("p0 = Q:\n"); printGiant(Q.x); printf("p1 = Pm:\n"); printGiant(sinst->PmX); printf("p2 = scratch = R:\n"); printGiant(scratch.x); } #endif // SIG_DEBUG if(signature_compare(Q.x, sinst->PmX, scratch.x, cp)) { frtn = FR_InvalidSignature; #if LOG_BAD_SIG printf("***yup, bad sig***\n"); #endif // LOG_BAD_SIG } else { frtn = FR_Success; } freeGiant(messageGiant); returnPointProj(&Q); returnPointProj(&scratch); return frtn; }
int main() { int i,j,T,N,M; int maxIters = 800; int iters = 0; double oldLogProb = -(1.0/0.0); printf("\nPlease enter a value for N : "); scanf("%d", &N); printf("\nPlease enter a value for M : "); scanf("%d", &M); printf("\nPlease enter a value for T : "); scanf("%d", &T); char *O = (char *)calloc(T, sizeof(char)); double *PI = (double *)calloc(N, sizeof(double)); double A[26][26] = { {0.00320,0.02153,0.04721,0.04476,0.00113,0.01417,0.02455,0.00459,0.04017,0.00195,0.01100,0.09790,0.03810,0.18396,0.00281,0.02016,0.00058,0.11674,0.10182,0.14237,0.01213,0.01929,0.01127,0.00346,0.03671,0.00096}, {0.11677,0.00882,0.00294,0.00257,0.28906,0.00196,0.00135,0.00257,0.06274,0.00539,0.00086,0.11089,0.00368,0.00110,0.11898,0.00196,0.00061,0.06163,0.01507,0.00821,0.10758,0.00270,0.00306,0.00061,0.08087,0.00074}, {0.12775,0.00182,0.01820,0.00276,0.14564,0.00195,0.00151,0.15442,0.06808,0.00050,0.04700,0.03633,0.00144,0.00113,0.21447,0.00295,0.00125,0.03915,0.00734,0.09192,0.02893,0.00088,0.00169,0.00031,0.00866,0.00044}, {0.11143,0.03926,0.02247,0.02257,0.17153,0.02531,0.01887,0.02800,0.11168,0.00538,0.00203,0.02105,0.03089,0.01643,0.07080,0.01856,0.00218,0.03256,0.06167,0.10326,0.03479,0.00771,0.02906,0.00025,0.01709,0.00046}, {0.07743,0.01878,0.05059,0.08977,0.03883,0.02537,0.01513,0.01586,0.02962,0.00308,0.00602,0.04128,0.03728,0.10133,0.02457,0.02857,0.00321,0.14522,0.10970,0.06244,0.00743,0.01720,0.02802,0.01121,0.01318,0.00055}, {0.09529,0.01090,0.02072,0.01045,0.08011,0.06725,0.00831,0.01768,0.11789,0.00366,0.00223,0.02635,0.01527,0.00911,0.19711,0.01393,0.00116,0.08109,0.02206,0.15442,0.03403,0.00259,0.01206,0.00045,0.00447,0.00071}, {0.11690,0.01263,0.01426,0.00916,0.17240,0.01477,0.01527,0.11487,0.08513,0.00305,0.00204,0.02363,0.01466,0.03248,0.09888,0.01171,0.00112,0.09430,0.03371,0.08004,0.03574,0.00234,0.01609,0.00051,0.00438,0.00051}, {0.15953,0.00460,0.00702,0.00310,0.47986,0.00337,0.00246,0.00667,0.11739,0.00095,0.00067,0.00417,0.00564,0.00722,0.09826,0.00460,0.00040,0.01921,0.01163,0.04139,0.01171,0.00127,0.00833,0.00020,0.00425,0.00024}, {0.03055,0.00961,0.07411,0.04589,0.04204,0.01470,0.02892,0.00143,0.00087,0.00034,0.00511,0.06298,0.02881,0.25476,0.07959,0.01029,0.00082,0.03654,0.11632,0.11750,0.00126,0.02976,0.00138,0.00242,0.00020,0.00672}, {0.15358,0.00524,0.00785,0.00611,0.13962,0.00436,0.00524,0.00960,0.04538,0.00698,0.00436,0.00611,0.00785,0.00524,0.30716,0.00611,0.00436,0.04538,0.00873,0.00611,0.28010,0.00436,0.00785,0.00436,0.00436,0.00436}, {0.07177,0.01196,0.01892,0.00918,0.33324,0.01530,0.00640,0.03310,0.14604,0.00668,0.00417,0.02865,0.01363,0.04896,0.05285,0.01113,0.00195,0.01363,0.09513,0.05202,0.00807,0.00306,0.02587,0.00139,0.01446,0.00139}, {0.12834,0.01892,0.01501,0.06400,0.16603,0.01644,0.00701,0.00801,0.12104,0.00133,0.00581,0.14211,0.01601,0.00486,0.07449,0.01549,0.00076,0.01020,0.04380,0.03479,0.02540,0.00705,0.01034,0.00024,0.06710,0.00038}, {0.18651,0.03753,0.00859,0.00347,0.25011,0.00565,0.00188,0.00678,0.11718,0.00143,0.00121,0.00445,0.04491,0.00317,0.11831,0.06232,0.00045,0.04039,0.02999,0.02720,0.03617,0.00083,0.00784,0.00038,0.01063,0.00045}, {0.07549,0.01200,0.05159,0.14048,0.08897,0.01677,0.10857,0.01370,0.06055,0.00385,0.00907,0.01148,0.01511,0.02065,0.06210,0.01120,0.00078,0.00757,0.07067,0.17194,0.01225,0.00732,0.01633,0.00036,0.01350,0.00058}, {0.02177,0.01789,0.02276,0.02172,0.00739,0.10623,0.01114,0.00997,0.01218,0.00167,0.00917,0.04448,0.06516,0.18545,0.03081,0.03009,0.00048,0.14231,0.04094,0.05886,0.09193,0.02281,0.03972,0.00133,0.00603,0.00048}, {0.13793,0.00381,0.00273,0.00254,0.16429,0.00449,0.00195,0.02987,0.06121,0.00146,0.00156,0.10045,0.01415,0.00098,0.13120,0.05476,0.00059,0.18167,0.02323,0.03954,0.04110,0.00059,0.00547,0.00049,0.00361,0.00049}, {0.01071,0.01071,0.01071,0.01071,0.01285,0.01071,0.01071,0.01285,0.01071,0.01071,0.01071,0.01071,0.01071,0.01071,0.01071,0.01285,0.01071,0.01071,0.01071,0.01071,0.94861,0.01071,0.01071,0.01071,0.01071,0.01071}, {0.10267,0.01015,0.02458,0.03757,0.21735,0.01142,0.01809,0.01295,0.09406,0.00268,0.01517,0.01803,0.03055,0.02846,0.10203,0.01446,0.00034,0.02009,0.08455,0.08012,0.02074,0.01086,0.01378,0.00015,0.03185,0.00049}, {0.10195,0.02292,0.03705,0.01425,0.10867,0.02126,0.00828,0.05316,0.09497,0.00358,0.00864,0.01735,0.02410,0.01292,0.07702,0.03774,0.00160,0.01126,0.07181,0.19948,0.03470,0.00265,0.03048,0.00015,0.00693,0.00021}, {0.07104,0.01045,0.01241,0.00547,0.11119,0.00964,0.00362,0.30486,0.11296,0.00157,0.00192,0.01560,0.01139,0.00554,0.11451,0.00848,0.00041,0.04002,0.04227,0.05523,0.01959,0.00135,0.02155,0.00011,0.02024,0.00085}, {0.03310,0.03913,0.04880,0.02923,0.04857,0.00750,0.03642,0.00147,0.02753,0.00186,0.00247,0.09365,0.03047,0.15614,0.00340,0.04176,0.00046,0.13959,0.12845,0.12977,0.00046,0.00240,0.00124,0.00093,0.00263,0.00062}, {0.08327,0.00180,0.00120,0.00260,0.61242,0.00160,0.00120,0.00180,0.21845,0.00180,0.00120,0.00160,0.00399,0.00120,0.05531,0.00240,0.00100,0.00240,0.00439,0.00339,0.00339,0.00180,0.00359,0.00100,0.00699,0.00100}, {0.20303,0.00723,0.00587,0.00644,0.15741,0.00565,0.00282,0.15842,0.20246,0.00282,0.00226,0.00734,0.00949,0.03771,0.12048,0.00621,0.00079,0.01400,0.02179,0.01705,0.00215,0.00113,0.00689,0.00056,0.01107,0.00068}, {0.14056,0.02711,0.09036,0.01004,0.09839,0.01406,0.00703,0.02510,0.08735,0.00502,0.00904,0.01707,0.01606,0.00703,0.03414,0.26807,0.00502,0.01205,0.01506,0.16064,0.00803,0.00602,0.02008,0.00602,0.01004,0.00502}, {0.10465,0.04215,0.04298,0.02598,0.10141,0.03149,0.01425,0.04227,0.06334,0.00778,0.00431,0.02634,0.04346,0.02191,0.09794,0.03161,0.00180,0.02419,0.10022,0.11566,0.00682,0.00467,0.05280,0.00060,0.00311,0.00072}, {0.21689,0.01142,0.02055,0.01826,0.42694,0.01370,0.01370,0.02283,0.09361,0.01370,0.01370,0.03425,0.01826,0.01142,0.05708,0.01370,0.01142,0.01826,0.02283,0.02511,0.03425,0.01598,0.01826,0.01142,0.02740,0.05251}}; double **B = (double **)calloc(N, sizeof(double *)); for(i=0;i<N;i++) B[i] = (double *)calloc(M, sizeof(double)); /* These are the scaling factor, alpha and beta pass matrices*/ double *c = (double *)calloc(T, sizeof(double)); double **a = (double **)calloc(T, sizeof(double *)); for(i=0;i<T;i++) a[i] = (double *)calloc(N, sizeof(double)); double **b = (double **)calloc(T, sizeof(double *)); for(i=0;i<T;i++) b[i] = (double *)calloc(N, sizeof(double)); /* These are the gamma and di-gamma matrices*/ double **gamma = (double **)calloc(T, sizeof(double *)); for(i=0;i<T;i++) gamma[i] = (double *)calloc(N, sizeof(double)); double ***gamma2 = (double ***)calloc(T, sizeof(double **)); for(i=0;i<T;i++) gamma2[i] = (double **)calloc(N, sizeof(double *)); for(i=0;i<T;i++) { for(j=0;j<N;j++) { gamma2[i][j] = (double *)calloc(M, sizeof(double)); } } printf("\nValue of LogProb : %f", oldLogProb); readCipher(O, T); initialize_PI(PI, N); initialize_B(B, N, M); print_A_B_PI(A, B, PI, N, M); computeAlphaPass(O, PI, A, B, c, a, N, T ); betaPass(c, A, B, O, a, b, N, T ); computegammapass(c, A, B, O, a, b, gamma, gamma2, N, T ); reestimate_B_PI(PI, gamma, gamma2, B, O, N, M, T); printf("\n\nPlease find below the values of PI, A and B matrices after the initial pass.\n---------------------------------------------------------------------------------\n"); print_A_B_PI(A, B, PI, N, M); double newLogProb = 0.0; newLogProb = computeLogP(c, T); printf("\nValue of Log Prob after initial pass is : %f\n",newLogProb); iters += 1; // while (iters < maxIters && newLogProb > oldLogProb) //This statement is not used as we reach a local maxima after the 3rd iteration while (iters < maxIters) { oldLogProb = newLogProb; computeAlphaPass(O, PI, A, B, c, a, N, T ); betaPass(c, A, B, O, a, b, N, T ); computegammapass(c, A, B, O, a, b, gamma, gamma2, N, T ); reestimate_B_PI(PI, gamma, gamma2, B, O, N, M, T); newLogProb = computeLogP(c, T); iters++; // printf("\nNo of iterations elapsed : %d", iters); } printf("\nNo of iterations elapsed : %d.\nCurrent LogProb : %f\t Previous LogProb : %f\n",iters-1,newLogProb,oldLogProb); printf("\n\nPlease find below the values of PI, A and B matrices after the final iteration.\n---------------------------------------------------------------------------------\n"); print_A_B_PI(A, B, PI, N, M); printKey(B, N, M); printf("\n\nThe program has run to successful completion.\n\n"); return 0; }