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: To Base 16, From Hex and To Hex give same outputs for different inputs #1479

Closed
pacorrop opened this issue Nov 17, 2022 · 4 comments
Labels

Comments

@pacorrop
Copy link

Describe the bug
The title is self explanatory.

To Reproduce
For an input of 512 the output is incorrectly 0x2000 https://gchq.github.io/CyberChef/#recipe=To_Base(16)From_Hex('Auto')To_Hex('Space',0)&input=NTEy
For an input of 8192 the output is correctly 0x2000 https://gchq.github.io/CyberChef/#recipe=To_Base(16)From_Hex('Auto')To_Hex('Space',0)&input=ODE5Mg

Expected behaviour
512 in hex is 02 00, not 20 00

Screenshots
N/A

Desktop (if relevant, please complete the following information):
N/A

Additional context
N/A

@pacorrop pacorrop added the bug label Nov 17, 2022
@mikecat
Copy link
Contributor

mikecat commented Nov 17, 2022

You can mitigate this by adding an operation to add a padding zero if the data has odd number of digits.

To Base, Find / Replace, From Hex, To Hex - CyberChef

@pacorrop
Copy link
Author

pacorrop commented Nov 18, 2022

Thanks for your prompt reply!

Whereas this works, it does not look good. Just showing an idempotent function like From Hex and then To Hex gives also zero padding issues:
From Hex -> To Hex. Input 032f, output is 03 2f (correc): https://gchq.github.io/CyberChef/#recipe=From_Hex('Auto')To_Hex('Space',0)&input=MDMyZg
From Hex -> To Hex. Input 32f, output is 32 0f (for some reason, the 0 is padded at the lsb): https://gchq.github.io/CyberChef/#recipe=From_Hex('Auto')To_Hex('Space',0)&input=MzJm

Using regex expressions to solve this is a bit of overwhelming as a user. Maybe insert this regex function on the affected function (From Hex, To Hex) in the backend?

@mikecat
Copy link
Contributor

mikecat commented Nov 18, 2022

"To/From Base" is for converting presentation of integers.
"To/From Hex" is for encoding/decoding bytes as hexadeximal strings.

I don't think it is good for "To Base" to add an extra (trailing) zero by default.
Also, if "To Hex" were changed to emit "32 f" for this latter case, it will also output "32 f" for an input "320f" and the output becomes differ from the input.

If you want identical output as input, I think it is good not to apply any operations.

@pacorrop
Copy link
Author

pacorrop commented Nov 18, 2022

I see. You are right, I did not know the formatting of any step and indeed the regex step does the job.

Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants