PDA

View Full Version : Simple Encrypt For Qt and PHP



wirasto
1st May 2013, 18:51
I found simple encrypt/decrypt for PHP here (http://tech.chitgoks.com/2008/03/24/php-encrypt-decrypt-using-base64/).

The result is:

Enc: 6dXM5pPw0ODLi+LR1pPX4I/X0t7g4srj5uA=
Dec: teks yang mau di enskripsi

I try decrypt from Qt with this function, but failed :(


QString Dialog::dec(const QByteArray &teks, const QString &pwd) const
{
QString result;
QString string(QByteArray::fromBase64(teks).constData());

int i;
QChar chr;
QChar keychr;
for (i=0; i < string.length(); i++) {
keychr=pwd.at( (i % pwd.length()) - 1 );
chr = QChar(string.at(i).unicode() - keychr.unicode());
result.append(chr);
}

return result;
}

...
....

qDebug() << dec("6dXM5pPw0ODLi+LR1pPX4I/X0t7g4srj5uA=", "passwordku");


The Qt result is


éeks yang âau di ensà ripsi

I think there is something different between php and Qt

wysota
1st May 2013, 18:59
Yes, the code :)

BTW. It is hard to call what you have there "encryption". It's so weak it can be broken manually within minutes.