I was recently converting an obfuscated js code to python I'm not good at js when I saw this I had no clue what to do is there anyway to convert this to simple js code
return 12 === selector ? (data = data >> 4, outstring = outstring + String.fromCharCode(data)) : 18 === selector && (data = data >> 2, outstring = outstring + String.fromCharCode((65280 & data) >> 8), outstring = outstring + String.fromCharCode(255 & data)), outstring;
Here is somewhat simplified version of your code:
if (selector === 12) {
data = data >> 4; // or data = Math.floor(data / 16), which is do right shift operation with data by 4 bits; 16 means 2 to the power of 4
outstring += String.fromCharCode(data); // append char value of data
return outstring;
} else if (selector === 18) {
data = data >> 2;
outstring = outstring + String.fromCharCode((65280 & data) >> 8); // turn higher 8 of 16 bits to a character and append
outstring = outstring + String.fromCharCode(255 & data); // turn lower 8 of 16 bits to a character and append
}
return outstring;
If you are completely new to JS, you will probably find links String.fromCharCode() and Right shift (>>) helpful