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
|
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
string data, datae, datal;
int save ();
int load ();
int edit ();
int decrypt ();
int encrypt ();
int fnew ();
int main () {
datal = "";
// This asks what you want to do, pretty basic
string wtd;
cout << "Welcome To XED Reader\n";
cout << "What Would You like To Do? (new, edit, save, load, view, help or exit)\n";
quick: // yada yada yada, goto is bad, whatever. it's quick and easy.
cout << "> ";
cin >> wtd; // this takes input
if (wtd == "new") { // And now we begin handling the input...
fnew (); // yup, new file
} else if (wtd == "edit") {
edit (); // edit
} else if (wtd == "save") {
save (); // save
} else if (wtd == "load") {
load (); // load
} else if (wtd == "view") {
cout << datal; // view the loaded data!
goto quick;
} else if (wtd == "help") { // get some help :)
cout << "Command Help :\n";
cout << "New -> Go To Edit A New File\n";
cout << "Edit -> Edit The Loaded File\n";
cout << "Save -> Save The File, This Includes Loaded & New Data\n";
cout << "Load -> Load A File, From Any Directory\n";
cout << "View -> View The Contents Of The Loaded File\n";
cout << "Help -> View This Screen\n";
cout << "Exit -> Exit The Program\n";
} else if (wtd == "exit") { // NOOOOOOO DON'T LEAVE ME!!!!!!!!!!!!!!! D:
return 0;
} else { // Aww... You Were THIIIIIIS Close To Being A Real Command
cout << "Invalid Action\n";
goto quick;
}
}
// Dummy Main to skip over the welcome message when we need to go back to this.
int dummy () {
string wtd;
cout << "What Would You like To Do? (new, edit, save, load, view, help or exit)\n";
quick: // yada yada yada, goto is bad, whatever. it's quick and easy.
cout << "> ";
cin >> wtd; // this takes input
if (wtd == "new") { // See The Comments On Main :O
fnew ();
} else if (wtd == "edit") {
edit ();
} else if (wtd == "save") {
save ();
} else if (wtd == "load") {
load ();
} else if (wtd == "view") {
cout << datal;
goto quick;
} else if (wtd == "help") {
cout << "Command Help :\n";
cout << "New -> Go To Edit A New File\n";
cout << "Edit -> Edit The Loaded File\n";
cout << "Save -> Save The File, This Includes Loaded & New Data\n";
cout << "Load -> Load A File, From Any Directory\n";
cout << "View -> View The Contents Of The Loaded File\n";
cout << "Help -> View This Screen\n";
cout << "Exit -> Exit The Program\n";
} else if (wtd == "exit") {
return 0;
} else {
cout << "Invalid Action\n";
goto quick;
}
}
int fnew () {
// This Function Allows You To Input Text Onto The Open Document, it outputs datal incase you loaded a file.
cout << "\nNote : XED Is Written All On One Line.";
cout << "\n> "; // Yup, This Is Where We Start Writing...
cin >> data;
dummy ();
}
int edit () {
// This Function Allows You To Input Text Onto The Open Document, it outputs datal incase you loaded a file.
cout << "\nNote : XED Is Written All On One Line.";
cout << "\n> "; // Yup, This Is Where We Start Writing...
cout << datal; // Yeah, the difference is an output... :P
cin >> data;
dummy ();
}
int load () {
string fname, dir;
filename:
cout << "\nDirectory (Case-Sensitive) >"; // ZOMFG, YOU CAN SELECT THE DIRECTORY
cin >> dir;
cout << "\nFilename > ";
cin >> fname;
ifstream load;
load.open((dir + fname + ".xed").c_str(), ios::app); // Yeah, it's gotta be .xed
if ( ! load ) {
cout << "File Not Found\n"; // oh wow, you tried to load a nonexistant file, nice.
goto filename;
} else {
load >> datae; // mhmm, yup : loading the data.
decrypt (); // ZOMFG, WE'RE GONNA GO DECRYPT :O
}
dummy (); // somehow... just.... just if you somehow beat the if statement... :P
}
int save () {
int sig;
string fname, sign, dir;
saving:
cout << "\nDirectory > "; // See comments on loading :P
cin >> dir;
cout << "\nFilename > ";
cin >> fname;
ofstream save;
save.open((dir + fname + ".xed").c_str());
if ( ! save ) {
cout << "An unknown error has occured.\n"; // unknown? well, i couldn't think of something that might happen to make it fail at saving...
goto saving; // ... a goto?!?!?! NOT AGAIN!!!!!!!!!!!!11oneone!!!1!1!11oneone1!1one!111!111!11!!!!!11!1one
} else {
encrypt (); // yup, encrypting it real fast.
save << datae; // saving, assuming that it knows to come back here after encrypting... if it does't im gonna need another file for saving.
cout << "Sign (y/n) > "; // oh man, you can sign it!
cin >> sign; // yerr input?
if (sign == "y") { // if its a yes
save << " Signature : "; // dividing between signature and normal.
save << sig; // yup, its the signature
// How it works : the data cannot be modified by the program without placing it after signature. the reciever will know easily if it's been modified, use this for cryptographic purposes, or in places where you'll need to toss around the data in new files every time.
}
}
dummy ();
}
int encrypt () {
// This Pads The Data... I Hope...
int x;
x = atoi(data.c_str()); // yup, it actually pads it... i think...?
// This is where the algorithm would go, but its hidden for security purposes
datae = /* variable would be here, its secret though :P */;
}
int decrypt () {
int x;
x = atoi(datae.c_str());
// This is where the algorithm would go, but its hidden for security purposes
// This Un-Pads The Data... I Hope...
datal = itoa(x);
}
|