Guest User

Untitled

a guest
Jan 21st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. void MainWindow::performRead()
  2. {
  3.  
  4.  
  5. QTcpSocket * sock = static_cast<QTcpSocket*>(this->sender());
  6. if (key == 0)
  7. {
  8. busy = true;
  9. QString recv(sock->readLine());
  10. key = recv.toInt();
  11. qDebug() << "Cheia este " << key;
  12.  
  13. char * response = enc_dec("#AUTH|admin|admin",strlen("#AUTH|admin|admin"),key);
  14. sock->write(response);
  15. }
  16. else
  17. {
  18. busy = true;
  19. while (sock->bytesAvailable() > 0)
  20. {
  21. unsigned short word;
  22. sock->read((char*)(&word),2);
  23. qDebug()<<word;
  24. QByteArray bts = sock->read(word);
  25. char * decodat = enc_dec((char*)bts.data(),bts.length() - 2,key);
  26. char testx[2];
  27. sock->peek(&testx[0],2);
  28. qDebug() << decodat;
  29. }
  30.  
  31. }
  32.  
  33. busy = false;
  34. }
  35.  
  36. void MainWindow::on_pushButton_clicked()
  37. {
  38. if (!busy)
  39. {
  40. key = 0;
  41. QTcpSocket * sock = new QTcpSocket();
  42. connect(sock,SIGNAL(readyRead()),this,SLOT(performRead()));
  43. sock->connectToHost("194.110.212.46",6550);
  44. }
  45. else qDebug()<<"Can't you see I am busy??" << endl;
  46. }
  47.  
  48. char * enc_dec(char * str,int len, int key)
  49. {
  50. unsigned char keys[2];
  51. keys[0] = (unsigned char)key;
  52. keys[1] = keys[0] ^ 255;
  53. char * nou = new char[len + 1];
  54. nou[len] = '';
  55. for (int i = 0; i < len; i++)
  56. {
  57. char tmpy = str[i] ^ keys[i % 2];
  58. nou[i] = tmpy;
  59. }
  60. return nou;
  61. }
Add Comment
Please, Sign In to add comment