string chrClasses(int mask) { if(mask == -1) #if DEBUG_DATA return "(-1)"; #else return ""; #endif gChrClasses.load(); ChrClasses::citr itr = gChrClasses.begin(); string s; bool full = true; for(; itr != gChrClasses.end(); ++itr) { const ChrClass& c(itr->second); if(mask & (1 << (itr->first - 1))) { if(!s.empty()) s += ", "; s += c.name; } else { full = false; } } if(s.empty()) s = "Unknown class mask: " + toString(mask); else { if(full) s.clear(); #if DEBUG_DATA s += " (" + toStringHex(mask) + ")"; #endif } return s; }
int main() { //testing printf("createRandomLongPoly() Output\n"); unsigned long polyLong = createRandomLongPoly(); //createRandomLongPoly() works :D printf("Output from createRandomLongPoly() = "); printf("\n%lu\n", polyLong); //output polyLong printf("toStringPoly() Output\n"); char* polyString; polyString = toStringPoly(polyLong); //now testing toStringPoly printf("Output from toStringPoly() = "); printf("\n%lu\n", polyString); printf("toStringHex() output\n"); unsigned long *polyLongHex; polyLongHex = toStringHex(polyLong); printf("Output from toStringHex() = "); printf("\n%lu\n", polyLongHex); //output hex - need fix? return 0; }
char *toStringBin(unsigned long l){ //hex is a nice starting point for binary char* tempHexString; tempHexString=(char*)malloc(sizeof(l)*2+1); // two hex chars make up 1 byte, add 1 for term char) tempHexString=toStringHex(l); //our main string char* binString; binString=(char*)malloc((sizeof(l)*2+1)*4); // it takes 4 bits to represent one hex so the sting needs be 4 times as long int i = 0; for (; i < strlen(tempHexString);i++)// forgot ; at beginning of for loop { switch(tempHexString[i]) { case '0':strcat(binString,"0000");break; case '1':strcat(binString,"0001");break; case '2':strcat(binString,"0010");break; case '3':strcat(binString,"0011");break; case '4':strcat(binString,"0100");break; case '5':strcat(binString,"0101");break; case '6':strcat(binString,"0110");break; case '7':strcat(binString,"0111");break; case '8':strcat(binString,"1000");break; case '9':strcat(binString,"1001");break; case 'A':strcat(binString,"1010");break; case 'B':strcat(binString,"1011");break; case 'C':strcat(binString,"1100");break; case 'D':strcat(binString,"1101");break; case 'E':strcat(binString,"1110");break; case 'F':strcat(binString,"1111");break; } } free(tempHexString); return binString; }
int main (int argc, char*argv[]){ // will take a list of files to be fingerprinted //bit_array_print_report(); if(argc == 1) {print_usage();} // nothing specied bits *bitmask, *poly; char *files[1000]; int file_count = 0; char* stdin_data; int option; int generate = -1, irreducible = -1, file = -1, standardin = -1, mask = -1, window = -1; while ((option = getopt(argc, argv,"g:i:f:s:b:w:")) != -1) { // looping through specified opts switch (option) { case 'g' : generate = atoi(optarg); break; case 'i' : irreducible = 0; poly = bits_initstring(optarg); break; case 'f' : file = 0; //get all files int index = optind-1; while(index < argc) { if(argv[index][0] != '-') files[file_count] = argv[index]; else break; file_count++; index++; if (file_count == MAX_FILES) break; } break; case 's' : standardin = 0; stdin_data = optarg; break; case 'b' : mask = atoi(optarg); break; case 'w' : window = atoi(optarg); break; default: print_usage(); exit(EXIT_FAILURE); } } if(generate > 0) { srand(time(0)); if (generate > 32) printf("This may take awhile...\n"); printf("%s\n",toStringHex(*createIrreducible(generate))); } if (irreducible == 0) { if (standardin < 0 && file < 0) {print_usage();} //set window if (window > 0) { if (window <= poly->size) { print_usage(); exit(EXIT_FAILURE); } } else { //default poly->size+4 window = poly->size+4; } //set bitmask if (mask > 0) { long max = ~0; long bits = ~(max << mask); bitmask = bits_initlong(bits); } else { //defualt 13 bitmask = bits_initlong(0x1FFF); } if (file == 0) { //fingerprint i int i; for (i=0;i<file_count;i++) { //check file exist if (fileCheckM(files[i])) { chunks* hashes = find_fingerprints_file(files[i], window, poly, bitmask, 0, 0); print_chunks(hashes); //free data free_chunks(hashes); } } } //fingerprint std if (standardin == 0) { chunks* hashes = find_fingerprints_bytes(stdin_data, strlen(stdin_data), window, poly, bitmask, 0, 0); print_chunks(hashes); //free data free_chunks(hashes); } //free data free(poly->byte); free(poly); free(bitmask->byte); free(bitmask); } return 0; }