git-svn-id: svn://db.shs.com.ru/pip@658 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
291
main.cpp
291
main.cpp
@@ -1,239 +1,68 @@
|
||||
#include "pip.h"
|
||||
#include "piauth.h"
|
||||
|
||||
/*
|
||||
class Obj : public PIObject {
|
||||
PIOBJECT(Obj)
|
||||
public:
|
||||
Obj() : PIObject() {}
|
||||
|
||||
EVENT_HANDLER2(void, authorizeServer, PIByteArray, info, bool *, ok) {
|
||||
piCout << "[authorizeServer]" << PIString(info);
|
||||
//*ok = true;
|
||||
}
|
||||
EVENT_HANDLER2(void, passwordCheck, PIByteArray, phash, bool *, ok) {
|
||||
piCout << "[passwordCheck]" << phash.toHex();
|
||||
PIByteArray ph = PICrypt::passwordHash("secret", PIByteArray::fromHex("AABBCCDD"));
|
||||
piCout << "[passwordCheck]" << ph.toHex();
|
||||
if (phash == ph) *ok = true;
|
||||
}
|
||||
EVENT_HANDLER1(void, userEnterPassword, PIString *, password) {
|
||||
*password = "secret";
|
||||
piCout << "[userEnterPassword]" << *password;
|
||||
}
|
||||
EVENT_HANDLER(void, clientConnect) {
|
||||
piCout << "clientConnect OK!";
|
||||
}
|
||||
EVENT_HANDLER(void, serverConnect) {
|
||||
piCout << "serverConnect OK!";
|
||||
}
|
||||
EVENT_HANDLER1(void, f, int, id) {
|
||||
piCout << "finished" << id;
|
||||
}
|
||||
};
|
||||
|
||||
class A: public PIObject {
|
||||
PIOBJECT(A)
|
||||
public:
|
||||
A() {}
|
||||
EVENT_HANDLER2(void, pcf, int, id, PIString*, buff) {
|
||||
piCout << "PICout(" << id << ") finished:" << (*buff);
|
||||
}
|
||||
};
|
||||
*/
|
||||
/*class O {
|
||||
public:
|
||||
O() {piCout << "O";}
|
||||
~O() {piCout << "~O";}
|
||||
};
|
||||
|
||||
class Buffer {
|
||||
public:
|
||||
Buffer() {}
|
||||
template<typename T>
|
||||
static Buffer create() {
|
||||
Buffer ret;
|
||||
ret.data = new T();
|
||||
ret.pdestroy = (void *)(T::~T);
|
||||
return ret;
|
||||
}
|
||||
void destroy() {}
|
||||
void * data;
|
||||
void * pdestroy;
|
||||
};
|
||||
|
||||
|
||||
class __BufferStorage {
|
||||
public:
|
||||
|
||||
};
|
||||
*/
|
||||
int main() {
|
||||
//Buffer b = Buffer::create<O>();
|
||||
// PIMathMatrix<complexd> m1(2,2, PIVector<complexd>() << complexd(1.) << complexd(1.) << complexd(0.) << complexd(1.));
|
||||
// PIMathMatrix<complexd> m2(2,3, PIVector<complexd>() << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.));
|
||||
PIMathMatrix<double> m1(3,3, PIVector<double>() << 1. << 2. << 3. << 4. << 6. << 5. << 9. << 8. << 7.);
|
||||
// PIMathMatrix<double> m2(2,3, PIVector<double>() << 1. << 2. << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.));
|
||||
// PIMathMatrix<double> m3(vv);
|
||||
// piCout << m2 << PICoutManipulators::NewLine;
|
||||
// piCout << (PIVector2D<complexd>)m2 << PICoutManipulators::NewLine;
|
||||
// for (uint r = 0; r < m2.rows(); ++r) {
|
||||
// for (uint c = 0; c < m2.cols(); ++c) {
|
||||
//// piCout << m2[r][c];
|
||||
// m2[r][c] = complexd(m2[r][c].real(), -(m2[r][c].imag()));
|
||||
//// m2[r][c] = complexd();
|
||||
|
||||
|
||||
// PIEvaluator eval, eval2;
|
||||
// eval.check("1-1*2");
|
||||
// piCout << eval.evaluate().real();
|
||||
/*eval.setVariable("t", complexd(1, 2));
|
||||
eval.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
|
||||
PIByteArray ba = eval.save();
|
||||
piCout << ba.size();
|
||||
PITimeMeasurer tm; double us = 0.;
|
||||
|
||||
tm.reset();
|
||||
PIEvaluator e1;
|
||||
piForTimes(100) {
|
||||
e1.setVariable("t", complexd(1, 2));
|
||||
e1.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
|
||||
complexd ret = e1.evaluate();
|
||||
}
|
||||
us = tm.elapsed_u(); piCout << "check" << us / 100.;
|
||||
|
||||
tm.reset();
|
||||
PIEvaluator e2;
|
||||
e2.load(ba);
|
||||
piForTimes(10000) {
|
||||
e2.setVariable("t", complexd(1, 2));
|
||||
complexd ret = e2.evaluate();
|
||||
}
|
||||
us = tm.elapsed_u(); piCout << " save" << us / 10000.;*/
|
||||
|
||||
|
||||
|
||||
/*A a;
|
||||
CONNECTU(PICout::Notifier::object(), finished, &a, pcf);
|
||||
PIString buffer = "my buff:";
|
||||
PICout(&buffer, 1) << "int 10 ->" << 10 << ", time ->" << PITime::current();*/
|
||||
/*PISerial ser(PISerial::availableDevices(false)[0], PISerial::S115200);
|
||||
piCout << ser.constructFullPath();
|
||||
piCout << ser.open();
|
||||
ser.startThreadedRead();
|
||||
FOREVER {
|
||||
piCout << ser.isOpened();
|
||||
piMSleep(200);
|
||||
}*/
|
||||
/*PIVector<PIFile::FileInfo> fl = PIDir::current().allEntries();
|
||||
PIFile out("out.txt", PIIODevice::ReadWrite);
|
||||
out.clear();
|
||||
piForeachC (PIFile::FileInfo & f, fl) {
|
||||
PIString e = f.extension();
|
||||
PIString comm;
|
||||
if (e == "h") comm = PIString::fromUTF8("Заголовочный файл");
|
||||
if (e == "cpp") comm = PIString::fromUTF8("Файл релизации");
|
||||
if (e == "ui") comm = PIString::fromUTF8("Форма");
|
||||
if (e == "qrc") comm = PIString::fromUTF8("Файл ресурсов");
|
||||
if (comm.isEmpty()) continue;
|
||||
out << "\n\n" << comm << ": " << f.name() << "\n";
|
||||
PIFile file(f.name(), PIIODevice::ReadOnly);
|
||||
while (!file.isEnd()) {
|
||||
PIString line = file.readLine(), tl = line.trimmed();
|
||||
if (tl.isEmpty() || tl.startsWith("//")) continue;
|
||||
out << line << "\n";
|
||||
}
|
||||
}*/
|
||||
|
||||
return 0;
|
||||
/*}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Obj o;
|
||||
CONNECTU(PICout::Notifier::object(), finished, &o, f);
|
||||
PIString s = "!!!";
|
||||
piCout << s;
|
||||
PICout(&s, 1) << "now" << PIDateTime::current() << ", int 1 =" << 1;
|
||||
piCout << s;*/
|
||||
|
||||
/*piCout << "start";
|
||||
PICrypt crypt;
|
||||
PIByteArray skey1, pkey1;
|
||||
crypt.generateKeypair(pkey1, skey1);
|
||||
PIByteArray skey2, pkey2;
|
||||
crypt.generateKeypair(pkey2, skey2);
|
||||
PIByteArray sign = PIAuth::generateSign(PICrypt::generateKey());
|
||||
piCout << "sign" << sign.toHex();
|
||||
|
||||
piCout << "key1 " << pkey1.toHex() << skey1.toHex();
|
||||
piCout << "key2 " << pkey2.toHex() << skey2.toHex();
|
||||
PIString msg = "what the f*ck?";
|
||||
PIByteArray ba = msg.toUTF8();
|
||||
piCout << "source" << ba.toHex() << msg;
|
||||
PIByteArray cba = crypt.crypt(ba, pkey2, skey1);
|
||||
PIByteArray psign = crypt.extractSignPublicKey(sign);
|
||||
PIByteArray scba = crypt.signMessage(cba, sign);
|
||||
piCout << "crypted" << cba.toHex();
|
||||
piCout << "signed" << scba.toHex() << psign.toHex();
|
||||
PIByteArray dba = crypt.decrypt(cba, pkey1, skey2);
|
||||
piCout << "decrypted" << dba.toHex() << PIString(dba);
|
||||
piCout << "verify" << crypt.verifySign(cba, scba, psign);
|
||||
cba = crypt.crypt(ba, pkey1, skey2);
|
||||
piCout << "crypted" << cba.toHex();
|
||||
//cba[7] = 0;
|
||||
dba = crypt.decrypt(cba, pkey2, skey1);
|
||||
piCout << "decrypted" << dba.toHex() << PIString(dba);
|
||||
|
||||
|
||||
|
||||
|
||||
piCout << "=======================================";
|
||||
|
||||
PIAuth server(PIAuth::generateSign(pkey1));
|
||||
|
||||
msg = "This is Server with PIAuth";
|
||||
server.setInfoData(msg.toUTF8());
|
||||
|
||||
PIAuth client(PIAuth::generateSign(pkey2));
|
||||
|
||||
client.setAuthorizedPublicKeys(PIVector<PIByteArray>() << server.getSignPublicKey());
|
||||
// server.setAuthorizedPublicKeys(PIVector<PIByteArray>() << client.getSignPublicKey());
|
||||
Obj o;
|
||||
CONNECTU(&client, authorize, &o, authorizeServer);
|
||||
CONNECTU(&client, passwordRequest, &o, userEnterPassword);
|
||||
CONNECTU(&server, passwordCheck, &o, passwordCheck);
|
||||
CONNECTU(&client, connected, &o, clientConnect);
|
||||
CONNECTU(&server, connected, &o, serverConnect);
|
||||
client.startClient();
|
||||
ba = server.startServer();
|
||||
int st = PIAuth::AuthProbe;
|
||||
piCout << "server" << st << ba.toHex() << ba.size();*/
|
||||
|
||||
|
||||
|
||||
// ba[40] = 2;
|
||||
// {
|
||||
// int s;
|
||||
// ba >> s;
|
||||
// PIByteArray rinfo;
|
||||
// PIByteArray rsign;
|
||||
// PIByteArray rsign_pk;
|
||||
// PIByteArray box_pk;
|
||||
// PIByteArray noise;
|
||||
// ba >> rinfo >> rsign_pk >> box_pk >> noise >> rsign;
|
||||
// ba.clear();
|
||||
// PIByteArray sign2 = PIAuth::generateSign(PICrypt::generateRandomBuff(100));
|
||||
// msg = "Server";
|
||||
// ba << s << msg.toUTF8() << crypt.extractSignPublicKey(sign2) << box_pk << noise;
|
||||
// rsign = crypt.signMessage(ba, sign2);
|
||||
// ba << rsign;
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
piCout << "server" << st << ba.toHex() << ba.size();
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
piCout << "server" << st << ba.toHex() << ba.size();
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
piCout << "server" << st << ba.toHex() << ba.size();
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
piCout << "server" << st << ba.toHex() << ba.size();*/
|
||||
// }
|
||||
piCout << m1 << PICoutManipulators::NewLine;
|
||||
// piCout << m2 << PICoutManipulators::NewLine;
|
||||
// piCout << (PIVector2D<complexd>)m2 << PICoutManipulators::NewLine;
|
||||
// piCout << m2.transposed() << PICoutManipulators::NewLine;
|
||||
// piCout << hermitian(m2) << PICoutManipulators::NewLine;
|
||||
// piCout << (m2*m1);
|
||||
// PIMathVector<complexd> v(PIVector<complexd>() << complexd(1.) << complexd(2.));
|
||||
// piCout << (m1*PIMathMatrix<complexd>::matrixCol(v));```
|
||||
// piCout << m2;
|
||||
// piCout << m3;
|
||||
bool ok;
|
||||
PIMathMatrix<double> mi = m1.inverted(&ok);
|
||||
piCout << mi << ok;
|
||||
piCout << (mi * m1);
|
||||
piCout << m1.row(0).toVector();
|
||||
piCout << m1.row(1).toVector();
|
||||
piCout << m1.row(2).toVector();
|
||||
piCout << "";
|
||||
piCout << m1.col(0).toVector();
|
||||
piCout << m1.col(1).toVector();
|
||||
piCout << m1.col(2).toVector();
|
||||
//m2 = m2.transposed();
|
||||
// piCout << m2 << PICoutManipulators::NewLine << hermitian(m2);
|
||||
// piCout << PICoutManipulators::NewLine << hermitian(m2) * mi;
|
||||
// piCout << PICoutManipulators::NewLine << m1 * m2 << PICoutManipulators::NewLine << m2 * m1;
|
||||
// piCout << PICoutManipulators::NewLine << hermitian(m1*m2) << PICoutManipulators::NewLine << hermitian(m2) * hermitian(m1);
|
||||
// PIVector2D<double> v(3,2);
|
||||
// for (uint r = 0; r < v.rows(); ++r) {
|
||||
// for (uint c = 0; c < v.cols(); ++c) {
|
||||
// piCout << r*v.cols()+c+1;
|
||||
// v[r][c] = r*v.cols()+c+1;
|
||||
// }
|
||||
// }
|
||||
// piCout << v;
|
||||
// for (uint c = 0; c < v.cols(); ++c) {
|
||||
// for (uint r = 0; r < v.rows(); ++r) {
|
||||
// piCout << r*v.cols()+c+1;
|
||||
// v[r][c] = -v[r][c];
|
||||
// }
|
||||
// }
|
||||
PIMathMatrix<double> v = PIMathMatrix<double>(3,2, m1.toPlainVector().resize(6));
|
||||
PIMathMatrix<double> v2 = PIMathMatrix<double>(2,3, m1.toPlainVector().resize(6));
|
||||
piCout << v << PICoutManipulators::NewLine;
|
||||
piCout << v.toVectors() << PICoutManipulators::NewLine;
|
||||
// PIMathMatrix<double> v2 = PIMathMatrix<double>(v.toVectors());
|
||||
piCout << v2 << PICoutManipulators::NewLine;
|
||||
piCout << v*v2 << PICoutManipulators::NewLine;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user