Author

Topic: Javascript encryption - need little help (Read 138 times)

legendary
Activity: 1988
Merit: 1317
Get your game girl
March 13, 2018, 01:33:30 AM
#3
--snip--
I don't think you understand how encryption works.The following code is not only a bad example of using arrays to declare a constant but also shows how poor the approach is.

1.Why would you want to encrypt the port number ? It is not very difficult to get the port number using any routing commands/tools.
2.If you wish to do it anyway,you have two options
  a.Write your own encryption algorithm method which you can call on your private constants like.
 
Code:
  //Closure 
  function(portNumber) {
      return {
          ownEncryptionAlgo: function() {
              //returns encrypted constant
          }
      }
  }
 

b.Use a third party library like crypto-js
Ideally,you'd have something like
Code:
var CryptoJS = require("crypto-js");

// Encrypt
let portNumber = CryptoJS.AES.encrypt('port_num', 'secret key 123');

// Decrypt
let decryptedPort  = CryptoJS.AES.decrypt(portNumber.toString(), 'secret key 123');
let plaintext = decryptedPort.toString(CryptoJS.enc.Utf8);

legendary
Activity: 2772
Merit: 3284
March 12, 2018, 08:39:50 PM
#2
Why even bother going through all of this? This doesn't encrypt anything, and anyone remotely competent could easily see though the 'encryption' (more like scrambling, and even then, it's incredibly obvious).

If you wanted port 35555, you'd have
Code:
var init_port_h = conect + listConect[7] + listConect[7] + listConect[7] + listConect[7]

Basically you have an array ['7', '2', '8', '4', '9', '6', '0', '5', '1', '3'] of values, and arrays start at zero, so you'd be taking values from the placement you request. listConect[5] would be requesting the 6th value, etc.

Honestly, just do this:
Code:
var init_port_h = 35555
hero member
Activity: 696
Merit: 500
March 12, 2018, 06:37:19 PM
#1
Greetings

im looking for little help with javascript encryption
trying to encrypt my own chat platform and want to understand this code  

Code:
var listConect = ['7', '2', '8', '4', '9', '6', '0', '5', '1', '3'];
var conect = listConect[9];
var init_port_h = conect + listConect[5] + listConect[2] + listConect[7] + listConect[0];

that mean the port is 36857 right ?

ok lets say i want to change the port of my chat to another port like 35555 or anythings else

what should be here ?
Code:
var init_port_h = conect + listConect[5] + listConect[2] + listConect[7] + listConect[0];
Jump to: