C++ (Qt)uchar k[128]; memset(k,'Q',128); BF_KEY key; BlowfishSetKey(&key,128,k); QString dt = tr("привет"); QString crypt; QString decr; while(dt.size() < 128) dt.append("#"); qDebug() << dt; for (int i=0;i<128;i+=8) { uchar *out; out=new uchar[8]; uchar *in; in=new uchar[8]; QByteArray da(dt.mid(i,8).toAscii()); for (int d = 0;d<da.size();d++) { in[d] = da.data()[d]; } qDebug() << dt.mid(i,8) << "-<<<!!!!"; BlowfishEncryptLE(in,out,&key,1); QByteArray b1; for(int j=0;j<8;j++) { b1[j]=out[j]; } qDebug() << b1 << "<<<-B1"; crypt.append(b1); delete [] out; delete [] in; } QByteArray base(crypt.toAscii()); crypt = base.toBase64(); qDebug() << crypt << "<CRYPT"; QByteArray bas = QByteArray::fromBase64(crypt.toAscii()); for (int i=0;i<128;i+=8) { uchar *data; data=new uchar[8]; uchar *in; in=new uchar[8]; QByteArray data2 = bas.mid(i,8); for (int h = 0;h<data2.size();h++) { in[h] = data2[h]; } qDebug() << (char*)in << "<<---"; BlowfishEncryptLE(in,data,&key,0); qDebug() << (char*)data; QByteArray b2; for(int j=0;j<8;j++) { b2[j]=data[j]; } qDebug() << b2<< "<<<--B2"; decr.append(b2); delete [] data; delete [] in; } qDebug() << decr;
// преобразование Windows-1251 в UNICODE (UTF-8)QString FTr(QString rustext){ QTextCodec *codec=QTextCodec::codecForName("Windows-1251"); QByteArray ba; ba.append(rustext); return codec->toUnicode(ba);}
C++ (Qt)QByteArray encrypt(QByteArray dat){ QByteArray ke("qwerty"); uchar *k = new uchar[ke.size()]; for (int i=0;i<ke.size();i++) k[i] = ke[i]; BF_KEY key; BlowfishSetKey(&key,ke.size(),k); delete [] k; QByteArray dt(dat); QByteArray cry; dt = dt.toHex(); while(dt.size() < 128) dt.append("#"); for (int i=0;i<128;i+=8) { uchar *in = new uchar[8]; uchar *out = new uchar[8]; for (int x=0;x<8;x++) in[x] = dt.mid(i,8)[x]; BlowfishEncryptLE(in,out,&key,1); QByteArray b1; for(int j=0;j<8;j++) { b1[j]=out[j]; } cry.append(b1); delete [] out; delete [] in; } cry = cry.toBase64(); return cry;} QString decrypt(QByteArray dat){ QByteArray ke("qwerty"); uchar *k = new uchar[ke.size()]; for (int i=0;i<ke.size();i++) k[i] = ke[i]; BF_KEY key; BlowfishSetKey(&key,ke.size(),k); delete [] k; QByteArray dt(dat.fromBase64(dat)); QByteArray decr; QString dr; for (int i=0;i<128;i+=8) { uchar *in = new uchar[8]; uchar *out = new uchar[8]; for (int x=0;x<8;x++) in[x] = dt.mid(i,8)[x]; BlowfishEncryptLE(in,out,&key,0); QByteArray b2; for(int j=0;j<8;j++) { b2[j]=out[j]; } decr.append(b2); delete [] in; delete [] out; } dr = QString(decr.fromHex(decr)); return dr;}