gpt4 book ai didi

c++ - 使用 Qt 获取一些具有 KEY 字符的 ascii 值

转载 作者:行者123 更新时间:2023-11-30 05:05:56 26 4
gpt4 key购买 nike

我正在连接到 http 服务器。

服务器有特定的授权 key 。值是日期和单词。我将 ascii 转换为字符串。我得到一些值(value)。它看起来是隐形的。

/image/iVS2t.png

字符串值异或运算

例如)“2018 年 1 月 8 日星期一”^“aoenthus-2c'\''34pnq”'

QString  auth_key= getXorEncryptDecrypt("Mon Jan 08 2018","aoenthus-2c'34pnq");

QString Test::getXorEncryptDecrypt(const char* str, const char* key)
{
QTextCodec *codec = QTextCodec::codecForName("utf-8");
QByteArray byte = codec->fromUnicode(str);

QString new_key;

int nSize = byte.size();

for(int i=0; i < nSize; i++){
byte[i] = byte[i] ^ key[i];

qDebug() << i << byte[i];
}


std::string strUtf8 = codec->toUnicode(byte).toStdString();

QString auth_key = convertKey(strUtf8);

qDebug() << auth_key;

return auth_key;
}

QString Test::convertKey(std::string inputString)
{

// check ascii code
int i = 0;

QString new_key;
for (std::string::iterator it=inputString.begin(); it!=inputString.end(); ++it,++i)
{
//a -z ,A-Z, " > ' white space
if (((*it) >= 0x61 && (*it) <= 0x7a) || //a-z
((*it) >= 0x41 && (*it) <= 0x5a) || // A- Z
((*it) == 0x22 || (*it) == 0x3e || (*it) ==0x27) //" > '
|| ((*it) == 0x20 ||(*it) == 0x09)
|| (*it) == 0x2C
|| (*it) ==0x0B || (*it) == 0x1B || (*it) == 0x1D
|| (*it) ==0x15 || (*it) == 0x03 || (*it) == 0x05) //VT

{
new_key.append(*it);
}

}

return new_key;
}

最佳答案

我认为您正在处理不可打印(不可见)的字符。我建议将加密的字节数组保存在十六进制编码的字符串中。我还建议您检查 key 字符串是否比要加密的字符串短(一种常见的解决方法是将 key 字符串加倍,直到其长度等于或大于数据长度)。

QString Test::getXorEncryptDecrypt(const char* str, const char* key)
{
QTextCodec *codec = QTextCodec::codecForName("utf-8");
QByteArray byte = codec->fromUnicode(str);

int nSize = byte.size();

QString keystring(key);
while(keystring.size() < nSize)
{
keystring += keystring;
}

for(int i=0; i<nSize; i++){

byte[i] = byte[i] ^ keystring.at(i).toLatin1();
}

return byte.toHex();
}

int main()
{
QString auth_key= getXorEncryptDecrypt("Mon Jan 08 2018","aoenthus-2c'34pnq");
qDebug() << auth_key; //"2c000b4e3e091b531d0a4315030548"
}

从十六进制编码的字符串中检索原始字节:

QByteArray byte = QByteArray::fromHex(hex_encoded);

关于c++ - 使用 Qt 获取一些具有 KEY 字符的 ascii 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48146756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com