Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<!-- Bug report: --> Binary to decimal not working as expected #366

Closed
hex64dbg opened this issue Sep 15, 2018 · 3 comments
Closed

<!-- Bug report: --> Binary to decimal not working as expected #366

hex64dbg opened this issue Sep 15, 2018 · 3 comments

Comments

@hex64dbg
Copy link

hex64dbg commented Sep 15, 2018

Summary

If you try to convert more then 8 bits to decimal, it isn't working as expected.
For exemple :
Input : "111111111" (9 bits total)
Ouput : "255 1"
Expected output : "511"
What happend is that the first 8 bits were converted to 255 than the last one was converted to 1.

https://gchq.github.io/CyberChef/#recipe=From_Binary('Space')To_Decimal('Space')&input=MTExMTExMTEx

@OllieJC
Copy link
Contributor

OllieJC commented Sep 25, 2018

So this is because most operations output a byte array, including From Binary so 111111111 becomes 0xFF,0x01 then To Decimal converts each to 255,1

This is as far as I've got to a fix using byte arrays. and it kind of works.. with binary as an input you need an additional Swap endianness operation to turn 111111111 into 0x01,0xFF then the below code works (otherwise 111111111 gets interpreted as 0xFF1 / 4081).

src/core/operations/ToDecimal.mjs (full change here: OllieJC@5693d1e)

run(input, args) {
    const delim = Utils.charRep(args[0]);
    if (args[1]) {
        var res = "";
        for (var i = 0; i < input.length; i++) {
            res += input[i].toString(16);
        }
        return parseInt(res,16).toString();
    } else {
        return input.join(delim);
    }
}

edit: previous code did bit-shifting but that only works up to int32, above works int64

@n1474335
Copy link
Member

As @OllieGeek says, the 'From Binary' operation works on byte arrays, so the maximum binary value is 255. What you're looking for is 'From Base' which deals with numbers:

https://gchq.github.io/CyberChef/#recipe=From_Base(2)&input=MTExMTExMTEx

@OllieJC
Copy link
Contributor

OllieJC commented Sep 26, 2018

Ah nice @n1474335 - I didn't know From Base existed :)

BRAVO68WEB pushed a commit to BRAVO68WEB/CyberChef that referenced this issue May 29, 2022
Closes gchq#366. This issue was caused by item IDs not being regenerated after the previous move, causing the second part of the move operation (delete previous) to fail. It was fixed by calling regenerate item IDs after item removal
BRAVO68WEB pushed a commit to BRAVO68WEB/CyberChef that referenced this issue May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants