how to do this in Javascript or Jquery?
Please suggest in 2 steps:
1.- Word Array to Single Byte Array.
2.- Byte Array to String.
Maybe this can help:
function hex2a(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
What you are trying to achieve is already implemented in CryptoJS. From the documentation:
Honestly I have no idea why you want to implement that yourself… But if you absolutely need to do it “manually” in the 2 steps you mentioned, you could try something like this:
The
wordToByteArrayfunction should work perfectly, but be aware thatbyteArrayToStringwill produce weird results in almost any case. I don’t know much about encodings, but ASCII only uses 7 bits so you won’t get ASCII chars when trying to encode an entire byte. So I added theescapefunction to at least be able to display all those strange chars you might get. 😉I’d recommend you use the functions CryptoJS has already implemented or just use the byte array (without converting it to string) for your analysis.