Compare commits

...

8 Commits

Author SHA1 Message Date
Dmitry Sovetin
15b4013868 Изменения, которые будут включены в коммит:
изменено:      .gitignore
	удалено:       .vscode/c_cpp_properties.json
2022-06-15 13:52:02 +03:00
Dmitry Sovetin
2517617d4f json11.h rename for VSCode 2022-04-17 12:44:24 +03:00
Dmitry Sovetin
cd0a0d5e44 Version 2022-04-16 09:34:49 +03:00
Dmitry Sovetin
e7e42922b6 Update README.md 2020-02-14 09:13:23 +03:00
Dmitry Sovetin
c0ed7ca721 Update README.md 2020-02-14 09:01:27 +03:00
Dmitry Sovetin
08129fee79 Update README.md 2019-10-31 15:57:15 +03:00
Dmitry Sovetin
fbbbef7da6 Update README.md 2019-10-31 15:54:06 +03:00
Dmitry Sovetin
bba8c620bd Corrections 2019-10-24 13:53:28 +03:00
5 changed files with 21 additions and 20 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
udpserver
*.log
*.pid
.vscode

View File

@@ -1,12 +1,13 @@
# Simple multithreaded UDP server
# Simple C++ multithreaded UDP server
[![Languages](https://img.shields.io/github/languages/top/SDMMSK/UDPServer.svg?style=flat-square)](README.md)
[![Code Size](https://img.shields.io/github/languages/code-size/SDMMSK/UDPServer.svg?style=flat-square)](README.md)
[![License](https://img.shields.io/github/license/SDMMSK/UDPServer.svg?style=flat-square)](LICENSE)
Simple multithreaded UDP server.
Simple C++ multithreaded UDP server.
The number of threads is determined by the number of CPU cores.
JSON logging.
JSON logging.
XTea encryption functions.
## Getting Started

View File

@@ -19,7 +19,7 @@
* THE SOFTWARE.
*/
#include "json11.hpp"
#include "json11.h"
#include <cassert>
#include <cmath>
#include <cstdlib>

View File

@@ -1,5 +1,6 @@
/* g++ -o udpserver udpserver.cpp -std=c++11 json11.cpp -pthread -s -O2 */
/* udpserver 127.0.0.1 10003 */
/* Version 2022.04 */
#include <iostream>
#include <sstream>
@@ -9,7 +10,7 @@
#include <signal.h>
#include <thread>
#include "json11.hpp"
#include "json11.h"
using namespace std;
using namespace json11;
@@ -162,7 +163,7 @@ void termHandler(int i) {
// XTea Encryption, use if necessary...
void xteaEncipher(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4]) {
unsigned int i;
unsigned int i;
uint32_t v0 = v[0], v1 = v[1], sum = 0, delta = 0x9E3779B9;
for (i = 0; i < num_rounds; i++) {
v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
@@ -185,26 +186,24 @@ void xteaDecipher(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4])
void stringCrypt(char *inout, int len, bool encrypt) // encrypt true - encrypt, false - decript
{
for (int i = 0; i < len / BLOCK_SIZE; i++) {
if (encrypt) {
xteaEncipher(32, (uint32_t*)(inout + (i * BLOCK_SIZE)), key);
} else {
xteaDecipher(32, (uint32_t*)(inout + (i * BLOCK_SIZE)), key);
}
for (int i = 0; i < len / BLOCK_SIZE; i++) {
if (encrypt) {
xteaEncipher(32, (uint32_t*)(inout + (i * BLOCK_SIZE)), key);
} else {
xteaDecipher(32, (uint32_t*)(inout + (i * BLOCK_SIZE)), key);
}
}
if (len % BLOCK_SIZE != 0)
{
int mod = len % BLOCK_SIZE;
if (len % BLOCK_SIZE != 0) {
int mod = len % BLOCK_SIZE;
int offset = (len / BLOCK_SIZE) * BLOCK_SIZE;
char data[BLOCK_SIZE];
memcpy(data, inout + offset, mod);
if (encrypt) {
xteaEncipher(32, (uint32_t*)data, key);
} else {
xteaEncipher(32, (uint32_t*)data, key);
} else {
xteaDecipher(32, (uint32_t*)data, key);
}
memcpy(inout + offset, data, mod);
cout << mod << endl;
}
memcpy(inout + offset, data, mod);
}
}