01/10/2018, 10:38

Gặp lỗi khi debug c++

em có đoạn code sau:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <windows.h>

    const std::string &SALT1 = "LM::TB::BB";
    const std::string &SALT2 = "__:/__77";
    const std::string &SALT3 = "line=wowC++";
    const std::string &BASE64_CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

    std::string DecryptB64 (std::string s);
    std::string base64_decode(const std::string &s);



int main()
{

    std::string in("C:\Users\Admin\AppData\Roaming\Microsoft\CLR\23.07.2017-15_58_34.log");
    std::string out("C:\Users\Admin\AppData\Roaming\Microsoft\CLR\decryt.log");

    std::ifstream fi (in);
    std::string data;
    fi >> data;



    data = DecryptB64(data);
    std::ofstream fo (out);
    fo << data;
    std::cout << "Decoding was succesfull" << std::endl;
    return 0;
}

std::string base64_decode(const std::string &s)
    {
        std::string ret;
        std::vector<int> vec(256, -1);
        for (int i = 0; i < 64; i++)
            vec [BASE64_CODES[i]] = i;
        int val = 0, bits = -8;
        for (const auto &c : s)
            {
                if (vec[c] == -1) break;
                val = (val << 6) + vec[c];
                bits += 6;

                if (bits >= 0)
                    {

                        ret.push_back(char((val >> bits) & 0xFF));
                        bits -= 8;
                    }
            }

        return ret;
    }

std::string DecryptB64 (std::string s)
    {
        s = s.erase (7, 1);
        s = s.erase (1, 1);
        s = base64_decode (s);
        s = s.substr (SALT2.length() + SALT3.length());
        s = s.substr (0, s.length() - SALT1.length());
        s = base64_decode (s);
        s = s.substr (0, s.length() - SALT1.length());
        s = s.erase (7, SALT3.length());
        s = base64_decode (s);
        s = s.substr (SALT1.length());
        s = s.substr (0, s.length() - SALT2.length() - SALT3.length());
        return s;
    }

Khi debug gặp lỗi Runtime Error. this application has requested the runtime to terminate it in an unusual way. Em đã check rất kĩ đảm bảo thuật toán code và mọi thứ liên quan đến mã nguồn ok, nhưng khi run thì hiện lỗi đó.

Henry viết 12:40 ngày 01/10/2018

Bạn format code đi nào Dễ lắm
```cpp

code của bạn

```

Lekien viết 12:40 ngày 01/10/2018

ok thank, đang xoay sở mãi :))))

Bài liên quan
0