|
发表于 2024-7-2 10:12:16
|
显示全部楼层
- #include <string>
- #include <cstring>
- #include <cryptopp/base64.h>
- #include <cryptopp/filters.h>
- #include <cryptopp/osrng.h>
- // ObjectARX头文件
- #include <aced.h> // 或者根据你的具体需求导入相应的ObjectARX头文件
- class CMsoftlimit {
- public:
- CMsoftlimit() : m_key('A') {} // 初始化XOR密钥
- // 使用XOR加密后进行Base64编码
- CString EncryptAndEncode(CString csOriginal) {
- std::string strPlain = csOriginal.GetBuffer();
- std::string encrypted = XOREncrypt(strPlain);
- std::string encoded = Base64Encode(encrypted);
- return CString(encoded.c_str());
- }
- // 使用Base64解码后进行XOR解密
- CString DecodeAndDecrypt(CString csEncoded) {
- std::string decoded = Base64Decode(csEncoded.GetBuffer());
- std::string decrypted = XORDecrypt(decoded);
- return CString(decrypted.c_str());
- }
- private:
- std::string XOREncrypt(const std::string& plainText) {
- std::string cipherText = plainText;
- for (size_t i = 0; i < cipherText.length(); ++i) {
- cipherText[i] ^= m_key;
- }
- return cipherText;
- }
- std::string XORDecrypt(const std::string& cipherText) {
- return XOREncrypt(cipherText); // 因为XOR是它自己的逆运算
- }
- std::string Base64Encode(const std::string& input) {
- std::string output;
- CryptoPP::StringSource s(input, true,
- new CryptoPP::Base64Encoder(
- new CryptoPP::StringSink(output), false
- )
- );
- return output;
- }
- std::string Base64Decode(const char* input) {
- std::string output;
- CryptoPP::StringSource s(input, true,
- new CryptoPP::Base64Decoder(
- new CryptoPP::StringSink(output)
- )
- );
- return output;
- }
- char m_key; // XOR密钥
- };
- // 示例使用
- void main() {
- CMsoftlimit softlimit;
- CString originalText = _T("Hello, World!");
- CString encodedText = softlimit.EncryptAndEncode(originalText);
- CString decodedText = softlimit.DecodeAndDecrypt(encodedText);
- acutPrintf(_T("Original: %s\n"), originalText.GetString());
- acutPrintf(_T("Encoded: %s\n"), encodedText.GetString());
- acutPrintf(_T("Decoded: %s\n"), decodedText.GetString());
- }
复制代码 |
|