From fbf2d4d29222f5f99dd31a42163aab972535c013 Mon Sep 17 00:00:00 2001 From: Kent Chen Date: Fri, 10 Sep 2021 14:58:18 +0800 Subject: [PATCH 1/3] test: test2 --- xor.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 xor.c diff --git a/xor.c b/xor.c new file mode 100644 index 0000000..a45e04b --- /dev/null +++ b/xor.c @@ -0,0 +1,55 @@ +#include +#include +#include + +void xor_encrypt(char *key, char *string, int n) +{ + int i; + int keyLength = strlen(key); + for( i = 0 ; i < n ; i++ ) + { + string[i]=string[i]^key[i%keyLength]; + } +} + +void xor_encrypt2(const u_int8_t *key, u_int8_t *string, int n) +{ + int i; + int keyLength = sizeof(key)/sizeof(u_int8_t); + for( i = 0 ; i < n ; i++ ) + { + string[i]=string[i]^key[i%keyLength]; + } +} +int main(void) { + char plain[] = "This is plain text"; + u_int8_t plain2[] = "\x54\x68\x00\x73\x20\x69\x00\x20"; + + char key[] = "Abcdabcdabciabcdabcd"; + const u_int8_t key2[] = "\x81\x93\xe0\xc4"; + int n = strlen(plain); + printf("[%s] strlen(palin) = %d\n", __func__, n); + // encrypt: + xor_encrypt(key, plain, n); + xor_encrypt2(key2, plain2, 8); + printf("encrypted string: \n"); + for(int ii = 0; ii < n; ii++) { + if(plain[ii] > 0x32 && plain[ii] < 0x7F ) printf("%c", plain[ii]); + else printf(" 0x%02x ", plain[ii]); + } + printf("\n"); + for(int ii = 0; ii < 8; ii++) { + printf(" 0x%02x ", plain2[ii]); + } + printf("\n"); + xor_encrypt(key, plain, n); + printf("after round trip, plain string is '%s'\n", plain); + printf("\n"); + xor_encrypt2(key2, plain2, 8); + printf("after round trip, plain string is '%s'\n", (char *)plain2); + for(int ii = 0; ii < 8; ii++) { + printf(" 0x%02x ", plain2[ii]); + } + printf("\n"); +} + From 5a1d744e12dbdffe12c6d12a5c7c51fedd33989e Mon Sep 17 00:00:00 2001 From: Kent Chen Date: Fri, 10 Sep 2021 14:59:13 +0800 Subject: [PATCH 2/3] test3 * Asterisk points are okay, too --- wow.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 wow.js diff --git a/wow.js b/wow.js new file mode 100644 index 0000000..61a82f2 --- /dev/null +++ b/wow.js @@ -0,0 +1,18 @@ +var ip = "127.0.0.1"; +var port = 7788; +var http = require('http'); +var shell = require('/usr/local/lib/node_modules/shelljs'); + +http.createServer(function (req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + for (var i = 0; i < 3; i++) { + //shell.exec('wakeonlan -i 10.2.0.195 00:11:22:33:44:99'); + shell.exec('wakeonlan -i 10.2.0.51 00:11:22:33:44:88'); + //shell.exec('wakeonlan -i 192.168.1.20 00:11:22:33:44:99'); + //shell.exec('wakeonlan -i 10.2.0.81 00:15:6D:01:02:03'); + console.log(new Date() + " => " + i + "-th"); + } + res.end('WoooooooooooooooooW\n'); +}).listen(port); + +console.log("Server running at http://" + ip + ":" + port); From 5cef584d3713aaa07258807b31064ee34004d687 Mon Sep 17 00:00:00 2001 From: Kent Chen Date: Fri, 10 Sep 2021 15:01:38 +0800 Subject: [PATCH 3/3] test3 More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. Further paragraphs come after blank lines. - Bullet points are okay, too * Asterisk points are okay, too --- wss_server.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 wss_server.js diff --git a/wss_server.js b/wss_server.js new file mode 100644 index 0000000..0bba286 --- /dev/null +++ b/wss_server.js @@ -0,0 +1,29 @@ +var https = require('https'); +var ws = require('websocket').server; +var fs = require('fs'); + +var privateKey = fs.readFileSync('key.pem', 'utf8'); +var certificate = fs.readFileSync('cert.pem', 'utf8'); + +var credentials = {key: privateKey, cert: certificate}; +var express = require('express'); +var app = express(); + +//... bunch of other express stuff here ... + +//pass in your express app and credentials to create an https server +var httpsServer = https.createServer(credentials, app); +httpsServer.listen(8443); + +var WebSocketServer = require('ws').Server; +var wss = new WebSocketServer({ + server: httpsServer +}); + +wss.on('connection', function connection(ws) { + ws.on('message', function incoming(message) { + console.log('received: %s', message); + }); + + ws.send('something'); +});