-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSource.cpp
1119 lines (827 loc) · 22.9 KB
/
Source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
#include <cctype>
#include <map>
#include <cstring>
using namespace std;
void swap(string s)
{
ofstream myfile;
string data;
cout << "Please enter words to swap: " << endl;
cout << "(i.e. 'word1 word2 word3')" << endl;
cin.ignore(1); //for some reason I was getting an error if i wasnt using cin.ignore, using this bypassed that error
getline(cin, data);
stringstream X(data); //Used stirngstream since dealing with int and string data types
stringstream Y(data);
int countW = 0;
while (getline(X, data, ' ')) //counting x(data)...
{
countW++; //count
}
vector<string> Store(countW);//once words were counted, they are stored
int index = 0;
while (Y >> data)//repeat
{
Store[index] = data;
index++;
}
myfile.open("Word-Swap-File.txt"); //opened new file
cout << "\n\n";
for (int i = 0; i < countW; i++) //these for loops consists of placing all coutned words into
//new file
{
string temp = Store[0];
for (int j = 0; j < countW; j++)
{
myfile << Store[j];
cout << Store[j];
if (j < countW - 1)
{
Store[j] = Store[j + 1];
}
else
{
Store[j] = temp;
}
}
cout << "\n";
myfile << "\n";
}
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
myfile.close(); //close file
}
//similar to the swap function, this function serves to permute all possible
//combinations of letters that the user inputs
void permute(string perm)
{
ofstream Permfile;
string permute_file;
cout << "Please enter name for your output file: ";
cin >> permute_file; //user inputs file name for output file
Permfile.open(permute_file);
char permutations[1000];//little overexagerated here but it is set to take 1000 characters
cout << "Please enter letters/word to permutate: ";
cin >> permutations;//user inputs word to permute
int len = strlen(permutations);
sort(permutations, permutations + len);//sorting between permutation and length of word
do
{
Permfile << permutations << endl;
} while (next_permutation(permutations, permutations + len));
cout << "Successfully processed the file" << endl;
system("pause");
Permfile.close();
}
void add2wordlist(string add2)
{
string file1, file2, file3;
string word;
string wordlist = " ";
cout << "Enter filename 1: "; cin >> file1;
cout << "Enter filename 2: "; cin >> file2;
cout << "Enter new filename: "; cin >> file3;
ifstream ifs1(file1);
ofstream ofs(file3);
while (true) {
ifs1 >> word;
if (ifs1.fail()) break;
ofs << word << endl;
wordlist += word + " ";
}
ifs1.close();
ifstream ifs2(file2);
while (true) {
ifs2 >> word;
if (ifs2.fail()) break;
if (wordlist.find(" " + word + " ") != string::npos) continue;
ofs << word << endl;
}
ifs2.close();
ofs.close();
}
//This function will replace a specified letter for another letter.
void replace(string rplace)
{
ifstream fin;
string filename, txtfile;
ofstream file;
cout << "Enter name for new file" << endl;
cin >> filename;
cout << endl;
file.open(filename + "-Replaced", ios::out);
cout << "Please insert your text file: ";
cin >> txtfile;
fin.open(txtfile);
char Mchar, inp, outp;
cout << "Please enter the letter you want to target: ";
cin >> inp;
cout << "Please enter the string to replace: ";
cin >> outp;
int number_of_lines = 0;
while (!fin.eof()) // while its not the end of file
{
fin.get(Mchar); //searching for letter to replace
if (Mchar == inp)
{
Mchar = outp;
}
file << Mchar; //input new words with replaced letters into a new file
}
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
file.close();
fin.close();
}
//The capitalize function will capitalize the first letter of every word and the whole word
//similartly, for the lowercase function, the exact method was applied
//except the method "tolower"ss
//these two functions have a switch statement that has two options, First letter and whole word.
void capitalize(string cap)
{
char choice;
system("clear");
do {
cout << "Would you like to capitalize the first letter or whole word?" << endl;
cout << "\n Choose an option: \t";
cout << "\n [A] First Letter \t";
cout << "\n [B] Whole Word \t";
cout << "\n [Z] Exit" << endl;
cout << "Input: ";
cin >> choice;
switch (choice)
{
case'a':
case'A':
{
string filename, newfile;
cout << "Please input text file:";
cin >> filename;
ifstream RFILE(filename);
string Text;
cout << "Please enter a name for your output file:";
cin >> newfile;
ofstream WFILE(newfile + "First-letter-Capitalized");
while (getline(RFILE, Text)) {
Text[0] = toupper(Text[0]);
WFILE << Text + '\n';
}
// Close the file
RFILE.close();
WFILE.close();
system("pause");
cout << "\n\n\nSuccessfully processed the file!" << endl;
break;
};
case'b':
case'B':
{
ifstream inputfile;
ofstream outputfile;
string inputname, outputname;
cout << "Please enter the file to capitalize" << endl;
cin >> inputname;
inputfile.open(inputname);
outputfile.open(inputname + " -capitalized");// wrie to file
if (inputfile.is_open()) {
string Line;
// get line from inputstring
while (getline(inputfile, Line))
{
// capitalizing the string process
string Capstring;
for (int i = 0; i < Line.size(); i++) {
// first word of the sentence always capital
Capstring += toupper(Line[i]);
}
// writing the capitalized sentence to the output file
outputfile << Capstring << endl;
}
}
// closing the file
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
inputfile.close();
outputfile.close();
};
default:
system("clear");
cout << "Please select a letter from the menu\n";
cin.ignore();
break;
}
} while (!((choice == 'z') || (choice == 'Z')));
}
void lowercase(string low)
{
char choice;
system("clear");
do {
cout << "Would you like to lowercase the first letter or whole word?" << endl;
cout << "\n Choose an option: \t";
cout << "\n [A] First Letter \t";
cout << "\n [B] Whole Word \t";
cout << "\n [Z] Exit" << endl;
cout << "Input: ";
cin >> choice;
switch (choice)
{
case'a':
case'A':
{
system("clear");
string filename, newfile;
cout << "Please input text file:";
cin >> filename;
ifstream RFILE(filename);
string Text;
cout << "Please enter a name for your output file:";
cin >> newfile;
ofstream WFILE(newfile + "First-letter-Lowercased");
while (getline(RFILE, Text)) {
Text[0] = tolower(Text[0]);
WFILE << Text + '\n';
}
// Close the file
RFILE.close();
WFILE.close();
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
break;
};
case'b':
case'B':
{
system("clear");
ifstream inputfile;
ofstream outputfile;
string inputname, outputname;
cout << "Please enter the file to lowercase" << endl;
cin >> inputname;
inputfile.open(inputname);
// writing to a file
outputfile.open(inputname + " -lowercase");
if (inputfile.is_open()) {
string Line;
// getting each line from a file
while (getline(inputfile, Line))
{
// capitalizing the string
string Capstring;
for (int i = 0; i < Line.size(); i++) {
// first word of the sentence always capital
Capstring += tolower(Line[i]);
}
// writing the capitalized sentence to the output file
outputfile << Capstring << endl;
}
}
// closing the file
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
inputfile.close();
outputfile.close();
};
default:
system("clear");
cout << "Please select a letter from the menu\n";
cin.ignore();
break;
}
} while (!((choice == 'z') || (choice == 'Z')));
}
//This function will allow a user create anew wordlist from scratch based on input
//program will read via getline all of the users inputs and then create
//a new file with all of the input words
void Createlist(string Cr_list)
{
// set variable
string input, outputname;
cout << "Please enter a name for the output file :";
cin >> outputname;
cout << "\nPlease input words: ";
cin.ignore(1);
getline(cin, input); //reads input
string word;
vector<string> words;
// stringstream variable
stringstream in_str(input);
while (getline(in_str, word, ' '))
{
//moves word back
words.push_back(word);
}
//read size of words
for (int i = 0; i < (int)words.size(); i++)
cout << words[i] << "\n";
//set output file
ofstream file;
file.open(outputname); //open file
for (int i = 0; i < (int)words.size(); i++)
{
file << words[i];
file << "\n";
}
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
file.close();
}
//The merger2 function will allow the user to merge 2 files
//together. Program will create a new file, take the words from first file
//from user input, then take the words from the second file from user input
//and concatanate the words into the new file
//
void merge2(string MFile2)
{
cout << "You have chosen to merge 2 wordlists" << endl;
string file1name, file2name, file3name;
cout << endl << endl;
cout << "** Drag and drop or type in file name (i.e. filename.txt)\n";
cout << "Enter name of first file: " << endl;;
cin >> file1name;
cout << "Enter name of second file:" << endl;
cin >> file2name;
cout << "\nEnter name of output file: " << endl;
cin >> file3name;
ofstream oFile(file3name.c_str()); // create output file
string word1, word2;
ifstream inFileOne(file1name.c_str());//first input file
while (inFileOne >> word1) //word 1 is set into first input file (which is the first file from user)
{
ifstream inFileTwo(file2name.c_str()); //repeated
while (inFileTwo >> word2) //repeated from first while loop
{
oFile << word1 << word2 << endl; //finally word 1 and word 2 are put into output file and concatanated
}
inFileTwo.close();
}
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
inFileOne.close();
oFile.close();
}
//merge3 function is similar to the merge2 function
//only difference is that the concatanation is repeated once more
void merge3(string MFile3)
{
cout << "You have chosen to merge 3 wordlists" << endl;
string file1name, file2name, file3name, outfilename, word1, word2, word3;
cout << endl << endl;
cout << "** Drag and drop or type in file name (i.e. filename.txt)" << endl;
cout << "Enter name of first file: " << endl;;
cin >> file1name;
cout << "Enter name of second file: " << endl;
cin >> file2name;
cout << "Enter name of third file: " << endl;
cin >> file3name;
cout << "Enter name of output file: " << endl;
cin >> outfilename;
ofstream inFileFour(outfilename.c_str());
ifstream inFileOne(file1name.c_str());
while (inFileOne >> word1)
{
ifstream inFileTwo(file2name.c_str());
while (inFileTwo >> word2)
{
ifstream inFileThree(file3name.c_str());
while (inFileThree >> word3)
{
inFileFour << word1 << word2 << word3 << endl; //word 1 2 3 being concatanated into output
}
inFileThree.close();
}
inFileTwo.close();
}
inFileOne.close();
inFileFour.close();
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
}
//This unctio will delete words based on the character length that the user
//sets it to.
// User is allowed to have multiple inputs
void delWords(int del_L)
{
string filename;
ifstream fin;
ofstream fout;
//string line;
cout << "Please enter the file to delete characters: "; // User applies the filename
cin >> filename;
fin.open(filename);
cout << "\nEnter the characters to be deleted" << endl;
cout << "Seperate using spaces\n\nEXAMPLE: 5 7 10" << endl;
cout << "Input: ";
int num;
vector<int> v;
char c = 'a';
for (;;)
{
if (c == '\n')
break;
cin >> num;
v.push_back(num);
c = getchar();
if (c == '\n')
break;
}
map<int, int>mm;
for (auto x : v) {
mm[x] = 1;// see if the word of particular length should be deleted or not
}
string ofile;
cout << "enter the output file name" << endl;
cin >> ofile;
fout.open(ofile + "-deleted-characters");
char ch;
string sss = "";
while (fin)
{
fin.get(ch);
if (ch == ' ' || ch == '\n') {
if (!mm[sss.length()]) {//if word length matches one of the input lengths then delete the word
fout << sss;
}
fout << ch;
sss = "";
}
else {
sss += ch;
}
}
cout << "Please run the 'delete empty lines', option after!" << endl;
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("Pause");
// Close the File
fin.close();
fout.close();
}
// This function will use getline to detect what line is 0 characters
// for every line that is x>=1 characters, will grab the word and place it in another file
// that user names.
void del_empty_lines(int emt)
{
string StoreWord;
string filename, newfile;
cout << "You have chosen to delete characters based on length" << endl;
cout << endl << endl;
cout << "** Drag and drop or type in file name (i.e. filename.txt)" << endl;
emt = 0;
cout << "Please enter the file: ";
cin >> filename;
cout << "Deleting empty lines..." << endl;
ifstream WordIFILE(filename);
ofstream oFile(filename + " -emptylines");
while (getline(WordIFILE, StoreWord))
{
if (StoreWord.length() != emt)
{
oFile << StoreWord << endl;
}
}
WordIFILE.close();
oFile.close();
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
}
//This function will count all the words and character on each line,
//the way this works is by reading each word on each line and then taking that
//and creating another file with the information of how many words containing what amount of characters
void ch_count(string wCount)
{
string infilename;
string newfilename;
cout << "Please enter name of text file: ";
cin >> infilename;
ifstream fin(infilename); //added some validation incase anything goes wrong
if (!fin)
{
cout << "\nERROR FILE DOES NOT EXIST";
}
ofstream fiout(infilename + "-Counted"); //file will appear with endinf of "-Counted"
int count[500] = { 0 }; //amount of word space to count
string word;
int len;
while (fin >> word)
{
len = word.length(); //reading word lenght and initiallizing it into another variable named len
count[len - 1] += 1; //counting
}
fiout << "This wordlist contains:\n";
// print larger word count first
// Loop form i = 19 to 0
for (int i = 19; i >= 0; i--)
{
// If count of ith index is not == 0
if (count[i] != 0)
{
// Write count & length of word in file
fiout << count[i] << " word(s) of " << i + 1 << " characters\n";
}
}
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
}
// In this function the user will generate a wordlist based of phone numbers
// by simply putting 3 digits, the function will generate a wordlists of all possible 7 digit
// phone numbers
void GenNum(long long num)
{
ofstream Outfile;
int zip;
cout << "Please enter Zip code to generate list of phone numbers(i.e.'123'):";
cin >> zip; //user input of 3 digits
if (zip > 999)
{
cout << "Error, Invalid zip code" << endl;
system("pause");
return;
}
Outfile.open("Phone-Number-Wordlist.txt");
if (Outfile.is_open())
{
for (int a = 1000000; a <= 9999999; a++) {
Outfile << zip << a << endl; //generate zip number concatanated with generated numbers
}
}
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
Outfile.close();
}
//this function will generate a wordlist with minimum and maximum range,
//user sets the range
void NumRange(int Rnums)
{
ofstream Outfile;
int min, max;
cout << "Please set the range to generate numbers" << endl;
//set the range
cout << "Min range:"; //minimum
cin >> min;
cout << "Max range";
cin >> max;//maximum
if (min >= max)
{
cout << "Error, Min is greater than max" << endl;
system("pause");
return;
}
Outfile.open("Range-Number-Wordlist.txt");
if (Outfile.is_open())
{
//min = x, max = y , if min is less than x then increment min
for (min = min; min <= max; min++)
{
cout << min << endl;
Outfile << min << endl; //grabbing all increments of min and setting them to the
// output file
}
}
cout << "\n\n\nSuccessfully processed the file!" << endl;
system("pause");
Outfile.close();
}
int main()
{
//Variables for main
int del_L = 0;
int emt = 0;
string MFile2, MFile3, perm, rplace, wCount, s, Cr_list, cap, low,add2;
int Rnums = 0;
unsigned num = 9999999;
char choices;
do {
system("clear");
cout << "\n\n\t\tCRUMBLE" << endl;
cout << "\t\t" << endl;
cout << "By: " << endl;
cout << "sudo-su-FDEL" << endl;
cout << "-----------------------------------------------------------";
cout << "\n Choose an option: |\t";
cout << "\n [A] Create wordlist |\t";
cout << "\n [B] Edit Wordlists |\t";
cout << "\n [C] Numbers for Wordlists |\t";
cout << "\n [D] Analysis |\t";
cout << "\n |\t";
cout << "\n [Z] Exit |" << endl;
cout << "-----------------------------------------------------------" << endl;
cout << "Input: ";
cin >> choices;
system("clear");
switch (choices)
{
case 'A':
case 'a':
char wordlist;
do {
cout << "\n [A] Create Wordlist";
cout << "\n [B] Merge two wordlists";
cout << "\n [C] Merge three wordlists\n";
cout << "\n [Z] Go back\n";
cout << "Input: ";
cin >> wordlist;
switch (wordlist)
{
case 'A':
case 'a':
//create wordlist
system("clear");
Createlist(Cr_list);
system("pause");
system("clear");
break;
case 'B':
case 'b':
//merge 2
system("clear");
merge2(MFile2);
system("clear");
break;
case 'C':
case 'c':
//merge 3
system("clear");
merge3(MFile3);
system("clear");
break;
case 'Z':
case 'z':
system("clear");
break;
default:
system("clear");
cout << "Please select a letter from the menu\n";
cin.ignore();
break;
}
} while (!((wordlist == 'z') || (wordlist == 'Z')));
break;
case 'B':
case 'b':
{
system("clear");
char Schar;
do {
cout << "'*' manually input word(s) input\n";
cout << "\n [A] Replace letters";
cout << "\n [B] Add words to wordlist";
cout << "\n [C] Swap*";
cout << "\n [D] Permute*";
cout << "\n [E] Capitalize first letter";
cout << "\n [F] Lowercase first letter\n";
cout << "\n [Z] Go back\n";
cout << "Input: ";
cin >> Schar;
switch (Schar)
{
case 'A':
case 'a':
system("clear");
replace(rplace);
system("clear");
break;
case 'B':
case 'b':
system("clear");
add2wordlist(add2);
system("clear");
break;
case 'C':
case 'c':
system("clear");
swap(s);
system("clear");
break;
case 'D':
case 'd':
system("clear");
permute(perm);
system("clear");
break;
case 'E':
case 'e':
system("clear");
capitalize(cap);
system("clear");
break;
case 'F':
case 'f':
lowercase(low);
system("clear");
break;
case 'Z':
case 'z':
system("clear");
break;
default:
system("clear");
cout << "Please select a letter from the menu\n";
cin.ignore();
break;
}
} while (!((Schar == 'z') || (Schar == 'Z')));
break;
}
case 'C':
case 'c':
{
system("clear");
//Numbers
char Numbers;
do {
cout << "\n [A] Create Phone Number wordlist";
cout << "\n [B] Generate numbers based on range\n";
cout << "\n [Z] Go back\n";
cout << "Input: ";
cin >> Numbers;
switch (Numbers)
{