1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

parsesnip source

Discussion in 'Programming & Webmastering' started by calvary1980, Jun 1, 2008.

  1. calvary1980

    calvary1980 New Member

    Joined:
    Dec 26, 2007
    Messages:
    1,801 (0.68/day)
    Thanks Received:
    310
    Location:
    Toronto, CA
    C++: Parsesnip Source

    being a security enthusiast I usually find my self writing little tools like this on the fly I wrote this a couple years ago and planned on releasing it but never did, since the programming section is pretty quiet these days I see no harm.

    Code:
    // parsesnip
    // version 1.0
    // author Christine "calvary" C.
    // this tool is used to parse common combinations from selected
    // input file to output file with the option of a histogram
    // available format http://*:*@* to *:*
    
    // coming soon support for Zima and Crime formats
    
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <algorithm>
    #include <vector>
    
    #define DUP_THRESHOLD 20
    
    using namespace std;
    
    void print_vector(vector<string> & vec);
    
    int main(int argc, char * argv[]){
    
    	string input_fn;
    	string output_fn;
    	string make_hist;
    	int threshold;
    	cout<<"enter the path of the input file: ";
    	cin>>input_fn;
    	cout<<"enter the path of the output file: ";
    	cin>>output_fn;
    	cout<<"how many instances constitues a common combination (num > 1) : ";
    	cin>>threshold;
    	cout<<"would you like to make a histogram (y/n): ";
    	cin>>make_hist;
    	cout<<endl;
    	
    	vector<string> vl_vec;
    	vector<string>::iterator new_end;
    	string line;
    	string::iterator line_iter;
    	string base;
    	ifstream in(input_fn.c_str());
    	if(!in.good()){
    		cout<<"error: "<<input_fn<<" could not be opened \n";
    		cin>>input_fn;
    		exit(1);
    	}
    	while (!in.eof()){
    		in>>line;
    		line_iter = line.begin();
    		line_iter += 7;
    		
    		while(*(++line_iter) != '/');
    		line_iter++;
    		base.erase(base.begin(),base.end());
    		base.resize(line_iter - line.begin() + 1);
    		copy(line.begin(), line_iter,base.begin());
    		vl_vec.push_back(base);
    	}
    	sort(vl_vec.begin(),vl_vec.end());
    	new_end = unique(vl_vec.begin(),vl_vec.end());
    	vl_vec.erase(new_end + 1,vl_vec.end());
    
    	vector<string> combo_vec;
    	for(vector<string>::iterator cur = vl_vec.begin();
    		cur < new_end;
    		cur++){
    			line_iter = cur->begin();
    			line_iter += 7;
    			while(*(++line_iter) != '@');
    			base.erase(base.begin(),base.end());
    			base.resize(line_iter - cur->begin() - 6);
    			copy(cur->begin()+7,line_iter,base.begin());
    			combo_vec.push_back(base);
    		};
    
    	ofstream out(output_fn.c_str());
    	int dups;
    	string cur_combo;
    	for(vector<string>::iterator cur2 = combo_vec.begin();
    		cur2 < combo_vec.end();
    		cur2++){
    			dups = 0;
    			cur_combo = *cur2;
    			while(cur_combo == *cur2 && cur2 < combo_vec.end() - 1){ 
    				cur2++; 
    				dups++;
    			};
    			
    			if(toupper(make_hist[0]) == 'Y'){
    				out.width(25);
    			}
    			if(dups >= threshold){
    				out<<cur_combo<<" ";
    				if(toupper(make_hist[0]) == 'Y'){
    					cout<<" ";
    					for(int i=0; i<dups; i++)
    						out<<"|";
    				}
    				out<<endl;
    			}
    		}
    		
    	return 0;
    }
    
    
    void print_vector(vector<string> & vec){ // debug
    	for(vector<string>::iterator cur = vec.begin();
    		cur < vec.end();
    		cur++){
    			cout<<*cur<<endl;
    		}
    }// end print_vector
    - Christine
     
    Last edited: Jun 8, 2008
    Solaris17, Oliver_FF and Kreij say thanks.
  2. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.66/day)
    Thanks Received:
    5,622
    Location:
    Cheeseland (Wisconsin, USA)
    Thanks Christine, this is good stuff and I just wanted to bump it once more so it does not fade into oblivion too soon ;)

    One quick suggestion. When you post a code example , prefix the title with the language you are using. Helps with searching. :toast:
     
  3. calvary1980

    calvary1980 New Member

    Joined:
    Dec 26, 2007
    Messages:
    1,801 (0.68/day)
    Thanks Received:
    310
    Location:
    Toronto, CA
    Will do. :)

    - Christine
     
  4. Solaris17

    Solaris17 Creator Solaris Utility DVD

    Joined:
    Aug 16, 2005
    Messages:
    17,538 (4.99/day)
    Thanks Received:
    3,820
    Location:
    Florida
    man you guys know so much cool stuff i wish i could code like you guys.
     
  5. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (4.66/day)
    Thanks Received:
    5,622
    Location:
    Cheeseland (Wisconsin, USA)

    You can, you just have to stick with it and learn.
     
  6. Oliver_FF

    Oliver_FF New Member

    Joined:
    Oct 15, 2006
    Messages:
    546 (0.18/day)
    Thanks Received:
    65
    Seriously cool code, between myself and all of my mates I'm usually the first to attempt to make some code run as fast as possible XD

    As far as I know I hold the record at my university for the fastest time to search modem connection logs to determine the times that all modems are concurrently connected - running the code on a server for everyones times to be comparable. Gotta love Algorithm assignments :eek:

    You know, if you first poster goes to Edit their post, in this case, Christine, then pick Advanced View, you can change the title of the thread?
     
  7. calvary1980

    calvary1980 New Member

    Joined:
    Dec 26, 2007
    Messages:
    1,801 (0.68/day)
    Thanks Received:
    310
    Location:
    Toronto, CA
    done.

    - Christine
     
  8. calvary1980

    calvary1980 New Member

    Joined:
    Dec 26, 2007
    Messages:
    1,801 (0.68/day)
    Thanks Received:
    310
    Location:
    Toronto, CA
    check out my new sig! what do you think :laugh:

    - Christine
     
  9. Solaris17

    Solaris17 Creator Solaris Utility DVD

    Joined:
    Aug 16, 2005
    Messages:
    17,538 (4.99/day)
    Thanks Received:
    3,820
    Location:
    Florida
    thiats nice cristine whant to know what gives it away?


    nobody writes a smiley face side ways ;)

    and even though you did a good job congrats on finding the font...the slight pixilation can be seen if you have good eyes.

    maybe i cant program but i do make things

    [​IMG]
     
  10. Solaris17

    Solaris17 Creator Solaris Utility DVD

    Joined:
    Aug 16, 2005
    Messages:
    17,538 (4.99/day)
    Thanks Received:
    3,820
    Location:
    Florida
    awww s#$%T i just burned the final of that disk to :(


    i used cd menu pro 6 to make an autorun splash
     
  11. calvary1980

    calvary1980 New Member

    Joined:
    Dec 26, 2007
    Messages:
    1,801 (0.68/day)
    Thanks Received:
    310
    Location:
    Toronto, CA
    what about now? :laugh:

    - Christine
     
  12. Solaris17

    Solaris17 Creator Solaris Utility DVD

    Joined:
    Aug 16, 2005
    Messages:
    17,538 (4.99/day)
    Thanks Received:
    3,820
    Location:
    Florida
    hahaha :p leave me alone your a programmer you know ill spend 27 hours perfecting this it was a late night running on cold coffe and dreams. dont tell me you dont know what im talking about :p ill fix it though thanks :)
     
  13. Paulieg

    Paulieg The Mad Moderator Staff Member

    Joined:
    Feb 19, 2007
    Messages:
    11,957 (4.04/day)
    Thanks Received:
    3,033
    Location:
    Wherever I can find the iron.
    Nice code Christine. I wish I could enjoy writing code. It's so damn useful.
     
  14. calvary1980

    calvary1980 New Member

    Joined:
    Dec 26, 2007
    Messages:
    1,801 (0.68/day)
    Thanks Received:
    310
    Location:
    Toronto, CA
    Thanks Paulie :laugh: ok my sides hurt, im done.

    - Christine
     
    Last edited: Jun 9, 2008
  15. Solaris17

    Solaris17 Creator Solaris Utility DVD

    Joined:
    Aug 16, 2005
    Messages:
    17,538 (4.99/day)
    Thanks Received:
    3,820
    Location:
    Florida
    easy christine...the forum rules say no nudity just a heads.
     
  16. calvary1980

    calvary1980 New Member

    Joined:
    Dec 26, 2007
    Messages:
    1,801 (0.68/day)
    Thanks Received:
    310
    Location:
    Toronto, CA
    lighten up, what is this a family forum all of a sudden. they are just boobs you should see the collage of me :p

    - Christine
     
  17. Solaris17

    Solaris17 Creator Solaris Utility DVD

    Joined:
    Aug 16, 2005
    Messages:
    17,538 (4.99/day)
    Thanks Received:
    3,820
    Location:
    Florida
    lol i dont care in the slightest i just didnt want you to get in trouble im not a prude. ;)
     
  18. intel igent

    intel igent New Member

    Joined:
    Jun 5, 2005
    Messages:
    4,641 (1.29/day)
    Thanks Received:
    434
    Location:
    Toronto, Canada
    i can't programm but i can laugh! :laugh: :roll: :laugh:

    i like the new sig's :)

    :toast:
     
  19. Paulieg

    Paulieg The Mad Moderator Staff Member

    Joined:
    Feb 19, 2007
    Messages:
    11,957 (4.04/day)
    Thanks Received:
    3,033
    Location:
    Wherever I can find the iron.
    Christine, YHPM
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page