mirror of
https://github.com/gchq/CyberChef
synced 2024-11-15 09:07:06 +00:00
BCD operations now support BigNumbers
This commit is contained in:
parent
283d3e1e7b
commit
53eba2337c
2 changed files with 9 additions and 8 deletions
|
@ -3750,7 +3750,7 @@ const OperationConfig = {
|
|||
module: "Default",
|
||||
description: "Binary-Coded Decimal (BCD) is a class of binary encodings of decimal numbers where each decimal digit is represented by a fixed number of bits, usually four or eight. Special bit patterns are sometimes used for a sign.",
|
||||
inputType: "string",
|
||||
outputType: "number",
|
||||
outputType: "BigNumber",
|
||||
args: [
|
||||
{
|
||||
name: "Scheme",
|
||||
|
@ -3778,7 +3778,7 @@ const OperationConfig = {
|
|||
"To BCD": {
|
||||
module: "Default",
|
||||
description: "Binary-Coded Decimal (BCD) is a class of binary encodings of decimal numbers where each decimal digit is represented by a fixed number of bits, usually four or eight. Special bit patterns are sometimes used for a sign",
|
||||
inputType: "number",
|
||||
inputType: "BigNumber",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import Utils from "../Utils.js";
|
||||
import BigNumber from "bignumber.js";
|
||||
|
||||
|
||||
/**
|
||||
|
@ -61,14 +62,14 @@ const BCD = {
|
|||
/**
|
||||
* To BCD operation.
|
||||
*
|
||||
* @param {number} input
|
||||
* @param {BigNumber} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runToBCD: function(input, args) {
|
||||
if (isNaN(input))
|
||||
if (input.isNaN())
|
||||
return "Invalid input";
|
||||
if (Math.floor(input) !== input)
|
||||
if (!input.floor().equals(input))
|
||||
return "Fractional values are not supported by BCD";
|
||||
|
||||
const encoding = BCD.ENCODING_LOOKUP[args[0]],
|
||||
|
@ -77,7 +78,7 @@ const BCD = {
|
|||
outputFormat = args[3];
|
||||
|
||||
// Split input number up into separate digits
|
||||
const digits = input.toString().split("");
|
||||
const digits = input.toFixed().split("");
|
||||
|
||||
if (digits[0] === "-" || digits[0] === "+") {
|
||||
digits.shift();
|
||||
|
@ -152,7 +153,7 @@ const BCD = {
|
|||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {number}
|
||||
* @returns {BigNumber}
|
||||
*/
|
||||
runFromBCD: function(input, args) {
|
||||
const encoding = BCD.ENCODING_LOOKUP[args[0]],
|
||||
|
@ -206,7 +207,7 @@ const BCD = {
|
|||
output += val.toString();
|
||||
});
|
||||
|
||||
return parseInt(output, 10);
|
||||
return new BigNumber(output);
|
||||
},
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue