Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern "C" __declspec(dllexport) void encode(char* user) {
- string filename = Get_List_Directory() + "\\preferences.ini";
- string tmp{};
- string username = string(user);
- fstream f;
- stringstream ss;
- bool containsKey = false;
- f.open(filename, fstream::out | fstream::in | fstream::app);
- if (!f.is_open()) {
- Log("error failed to open file preferences.ini");
- return;
- }
- while (getline(f, tmp)) { //read file into ss
- if (tmp.find("username=") != tmp.npos) {
- containsKey = true;
- }
- ss << tmp << '\n';
- }
- srand(time(0));
- tmp = "";
- int num = 0;
- for (int i = 0; i < username.size() + 1; i++) {
- int j = 0;
- while (j < i + 1) {
- num = 0;
- while (num < 33) {
- num = rand() % 127;
- }
- tmp += (char)num;
- j++;
- }
- if (i == username.size()) {
- break;
- }
- tmp += username[i];
- }
- f.close();
- f.open(filename, fstream::out | fstream::app);
- if (!containsKey) {
- cout << tmp;
- f << "username=" << tmp;
- return;
- }
- f.close();
- f.open(filename, fstream::out);
- containsKey = false;
- while (getline(ss, username)) {
- cout << username << '\n';
- if (username.find("username=") != username.npos) {
- containsKey = true;
- }
- else if (containsKey && username.find("=")) {
- containsKey = false;
- f << username << '\n';
- }
- else if (!containsKey) {
- f << username << "\n";
- }
- }
- f << "username=" << tmp;
- f.close();
- }
- extern "C" __declspec(dllexport) int decode(int num) {
- string filename = Get_List_Directory() + "\\preferences.ini";
- string tmp{};
- fstream f;
- bool containskey = false;
- f.open(filename, fstream::in);
- if (!f.is_open()) {
- Log(" error failed to open file");
- return 0;
- }
- while (getline(f, tmp)) {
- if (tmp.find("username=") != tmp.npos) {
- containskey = true;
- break;
- }
- }
- if (containskey) {
- tmp = tmp.substr(tmp.find("=") + 1, tmp.size() - (tmp.find("=") + 1));
- int n = 1;
- int b = 0;
- b += num;
- while (n < num + 2) {
- b += n;
- n++;
- if (b > tmp.size() - 1) {
- return 0;
- }
- }
- return (int)tmp[b];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement