Skip to content
Snippets Groups Projects
Commit 9acc5265 authored by Jonas Leder's avatar Jonas Leder
Browse files

encode messages as base64 before sending (function is obfuscated)

parent 3c26f2d5
No related branches found
No related tags found
No related merge requests found
......@@ -36,4 +36,20 @@ export function convertStringTo3D(text:string){
export function getRandomInt(max:number) {
return Math.floor(Math.random() * Math.floor(max)) + 1;
}
\ No newline at end of file
}
const _0xc13c = ["\x66\x61\x69\x6C\x65\x64\x20\x74\x6F\x20\x64\x65\x63\x6F\x64\x65\x20\x6D\x65\x73\x73\x61\x67\x65", "\x6C\x6F\x67", ""];export function encodeMessage(_0x5138x2:string){return btoa(_0x5138x2)}export function decodeMessage(_0x5138x2:string){try{return atob(_0x5138x2)}catch(Exception){// @ts-ignore
console[_0xc13c[1]](_0xc13c[0]);return _0xc13c[2]}}
/*
export function encodeMessage(message:string){
return btoa(message);
}
export function decodeMessage(message:string){
try {
return atob(message);
} catch (Exception){
console.log("failed to decode message");
return ""
}
}*/
\ No newline at end of file
import Swal from 'sweetalert2';
import {Paho} from 'ng2-mqtt/mqttws31';
import {makeid, IsJsonString, convertStringTo3D, convert3dToString, getRandomInt} from "./helper";
import {makeid, IsJsonString, convertStringTo3D, convert3dToString, getRandomInt, encodeMessage, decodeMessage} from "./helper";
let fieldSize:number = 20;
let speedFactor:number = 20;
......@@ -138,7 +138,7 @@ function setupMQTT(){
}
client.onMessageArrived = function (message:any) {
message = message.payloadString;
message = decodeMessage(message.payloadString);
console.log("recived: " + message);
if (IsJsonString(message)){
let recivedJson = JSON.parse(message);
......@@ -320,7 +320,7 @@ function resizeField() {
}
function sendMessage(message:string, topic:string){
let message_ = new Paho.MQTT.Message(message);
let message_ = new Paho.MQTT.Message(encodeMessage(message));
message_.destinationName = topic;
message_.qos = 0;
client.send(message_);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment