Skip to content

Bug report: Substitute producing invalid results with punctuation #2009

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

Open
ryantheleach opened this issue Apr 1, 2025 · 2 comments
Open
Labels

Comments

@ryantheleach
Copy link

Describe the bug
When using substitution, cyberchef is unable to produce the following decrypted ciphertext.

.-_ should become, _.- but instead becomes _-_ and warns that the ciphertext and plaintext are different.

To Reproduce
Steps to reproduce the behaviour or a link to the recipe / input used to cause the bug:

https://gchq.github.io/CyberChef/#recipe=Substitute('.-_','_.-',true)&input=Li1f

Expected behaviour

I expect the output _.-

Screenshots

Image

@gouldcs
Copy link

gouldcs commented Apr 30, 2025

This is not a bug, the plaintext input has a dash between two characters, which per the tool documentation is used to describe a range of bytes. To get the result you want, you need to escape the special character (-) by prefixing it with a \. The plaintext should be .\-_ and the cipher text can remain the same because the dash is at the end, not between two characters.

Here is the recipe with the expected output:

https://gchq.github.io/CyberChef/#recipe=Substitute('.%5C%5C-_','_.-',true)&input=Li1f

@gouldcs
Copy link

gouldcs commented Apr 30, 2025

A substitution cipher allowing you to specify bytes to replace with other byte values. This can be used to create Caesar ciphers but is more powerful as any byte value can be substituted, not just letters, and the substitution values need not be in order.

Enter the bytes you want to replace in the Plaintext field and the bytes to replace them with in the Ciphertext field.

Non-printable bytes can be specified using string escape notation. For example, a line feed character can be written as either \n or \x0a.

Byte ranges can be specified using a hyphen. For example, the sequence 0123456789 can be written as 0-9.

Note that blackslash characters are used to escape special characters, so will need to be escaped themselves if you want to use them on their own (e.g.\\).

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