mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
Updated to allow delimiter to be set
This commit is contained in:
parent
a417a6469c
commit
5c774a3ce2
1 changed files with 6 additions and 4 deletions
|
@ -366,19 +366,21 @@ const Utils = {
|
||||||
* Translates an array of bytes to a hex string.
|
* Translates an array of bytes to a hex string.
|
||||||
*
|
*
|
||||||
* @param {byteArray} byteArray
|
* @param {byteArray} byteArray
|
||||||
|
* @param {string} [delim=" "]
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // returns "fe09a7"
|
* // returns "fe09a7"
|
||||||
* Utils.byteArrayToHex([0xfe, 0x09, 0xa7]);
|
* Utils.byteArrayToHex([0xfe, 0x09, 0xa7], "");
|
||||||
*/
|
*/
|
||||||
byteArrayToHex: function(byteArray) {
|
byteArrayToHex: function(byteArray, delim) {
|
||||||
if (!byteArray) return "";
|
if (!byteArray) return "";
|
||||||
|
delim = typeof delim === "undefined" ? " " : delim;
|
||||||
let hexStr = "";
|
let hexStr = "";
|
||||||
for (let i = 0; i < byteArray.length; i++) {
|
for (let i = 0; i < byteArray.length; i++) {
|
||||||
hexStr += Utils.hex(byteArray[i]) + " ";
|
hexStr += Utils.hex(byteArray[i]) + delim;
|
||||||
}
|
}
|
||||||
return hexStr.slice(0, hexStr.length-1);
|
return hexStr.slice(0, hexStr.length - delim.length);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue