Adds Octal functions
- To Octal - From Octal
This commit is contained in:
parent
94ea086e05
commit
b8ce10ae96
@ -35,6 +35,8 @@ var Categories = [
|
||||
"From Decimal",
|
||||
"To Binary",
|
||||
"From Binary",
|
||||
"To Octal",
|
||||
"From Octal",
|
||||
"To Base64",
|
||||
"From Base64",
|
||||
"Show Base64 offsets",
|
||||
|
@ -392,7 +392,7 @@ var OperationConfig = {
|
||||
]
|
||||
},
|
||||
"From Hex": {
|
||||
description: "Converts a hexadecimal byte string back into a its raw value.<br><br>e.g. <code>ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a</code> becomes the UTF-8 encoded string <code>Γειά σου</code>",
|
||||
description: "Converts a hexadecimal byte string back into its raw value.<br><br>e.g. <code>ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a</code> becomes the UTF-8 encoded string <code>Γειά σου</code>",
|
||||
run: ByteRepr.runFromHex,
|
||||
highlight: ByteRepr.highlightFrom,
|
||||
highlightReverse: ByteRepr.highlightTo,
|
||||
@ -421,6 +421,36 @@ var OperationConfig = {
|
||||
}
|
||||
]
|
||||
},
|
||||
"From Octal": {
|
||||
description: "Converts a octal byte string back into its raw value.<br><br>e.g. <code>316 223 316 265 316 271 316 254 40 317 203 316 277 317 205</code> becomes the UTF-8 encoded string <code>Γειά σου</code>",
|
||||
run: ByteRepr.runFromOct,
|
||||
highlight: false,
|
||||
highlightReverse: false,
|
||||
inputType: "string",
|
||||
outputType: "byteArray",
|
||||
args: [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: ByteRepr.OCT_DELIM_OPTIONS
|
||||
}
|
||||
]
|
||||
},
|
||||
"To Octal": {
|
||||
description: "Converts the input string to octal bytes separated by the specified delimiter.<br><br>e.g. The UTF-8 encoded string <code>Γειά σου</code> becomes <code>316 223 316 265 316 271 316 254 40 317 203 316 277 317 205</code>",
|
||||
run: ByteRepr.runToOct,
|
||||
highlight: false,
|
||||
highlightReverse: false,
|
||||
inputType: "byteArray",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: ByteRepr.OCT_DELIM_OPTIONS
|
||||
}
|
||||
]
|
||||
},
|
||||
"From Charcode": {
|
||||
description: "Converts unicode character codes back into text.<br><br>e.g. <code>0393 03b5 03b9 03ac 20 03c3 03bf 03c5</code> becomes <code>Γειά σου</code>",
|
||||
run: ByteRepr.runFromCharcode,
|
||||
|
@ -828,6 +828,38 @@ var Utils = {
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Convert an byte array into a octal string
|
||||
*
|
||||
* @author Matt C [matt@artemisbot.pw]
|
||||
* @param {byteArray} data
|
||||
* @param {string} [delim]
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
toOct: function(data, delim) {
|
||||
var output = "";
|
||||
delim = delim || "Space";
|
||||
data.map(val => output += (parseInt(Utils.bin(val), 2).toString(8) + delim));
|
||||
return output.slice(0, -delim.length);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Convert an Octal string into a byte array.
|
||||
*
|
||||
* @author Matt C [matt@artemisbot.pw]
|
||||
* @param {string} data
|
||||
* @param {string} [delim]
|
||||
* @returns {byteArray}
|
||||
*
|
||||
*/
|
||||
fromOct: function(data, delim) {
|
||||
delim = delim || "Space";
|
||||
return data.split(delim).map(val => parseInt(val, 8));
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Parses CSV data and returns it as a two dimensional array or strings.
|
||||
*
|
||||
|
@ -21,6 +21,11 @@ var ByteRepr = {
|
||||
* @default
|
||||
*/
|
||||
HEX_DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "\\x", "None"],
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
OCT_DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF"],
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
@ -53,6 +58,32 @@ var ByteRepr = {
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* To Oct operation.
|
||||
*
|
||||
* @author Matt C [matt@artemisbot.pw]
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runToOct: function(input, args) {
|
||||
var delim = Utils.charRep[args[0] || "Space"];
|
||||
return Utils.toOct(input, delim, 2);
|
||||
},
|
||||
|
||||
/**
|
||||
* From Oct operation.
|
||||
*
|
||||
* @author Matt C [matt@artemisbot.pw]
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
runFromOct: function(input, args) {
|
||||
var delim = Utils.charRep[args[0] || "Space"];
|
||||
return Utils.fromOct(input, delim);
|
||||
},
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
|
Loading…
x
Reference in New Issue
Block a user