UNPKG

node-red-contrib-services-mentor

Version:

Mentor Services

95 lines (83 loc) 2.72 kB
/* Usage // example usage: checkInternet(function(isConnected) { if (isConnected) { // connected to the internet } else { // not connected to the internet } }); */ module.exports.checkInternet = (function (cb) { require('dns').lookup('google.com',function(err) { if (err && err.code == "ENOTFOUND") { cb(false); } else { cb(true); } }) } ); module.exports.encode = (function (texto) { var indx1; var limite; var texto_codificado = ""; var code = Buffer.from(texto, 'utf-8'); texto_codificado = new Buffer.from(""); indx1 = 1; limite = 3; for (indx = 0; indx < code.length; indx += 1) { if (indx1 == limite) { indx1 = 1; limite += 1; } if (indx1 % 2 == 0) { tem_cod = code.readUInt8(indx) + 1 ; } else { tem_cod = code.readUInt8(indx) - 1 ; } buffer1 = Buffer.from(texto_codificado); buffer2 = Buffer.from([tem_cod]); if (indx % 2 == 0) { texto_codificado = Buffer.concat([buffer1,buffer2]); } else { texto_codificado = Buffer.concat([buffer2,buffer1]); } indx1 += 1; } code = texto_codificado; texto_codificado = Buffer.from(""); for (indx = 0; indx < code.length; indx += 1) { tem_cod = code.readUInt8(indx); buffer1 = Buffer.from(texto_codificado); buffer2 = Buffer.from([tem_cod]); if (indx % 2 == 0) { texto_codificado = Buffer.concat([buffer2,buffer1]); } else { texto_codificado = Buffer.concat([buffer1,buffer2]); } } code = texto_codificado; texto_codificado = Buffer.from(""); for (indx = 0; indx < code.length; indx += 1) { tem_cod = code.readUInt8(indx); buffer1 = Buffer.from(texto_codificado); buffer2 = Buffer.from([tem_cod]); if (indx % 2 == 0) { texto_codificado = Buffer.concat([buffer1,buffer2]); } else { texto_codificado = Buffer.concat([buffer2,buffer1]); } } delete buffer1; delete buffer2; delete code; return texto_codificado.toString(); } );