Add Text/Integer Converter operation#2213
Conversation
|
Produces (not entirely) unexpected results when the input comprises characters outside the normal ASCII set, and in particular round-tripping won't work. Eg for input "aΓa" (Γ being capital gamma from the ancient Greek UTF set), the output for the recipe This is inherent in the difference between "characters" and "character codes" so I don't see there's any way to "fix" this and maintain the desired functionality so I suggest adding something to the description to the effect that the input string must be pure ASCII for the output to be consistent. |
… Latin-1 accepted
|
Rather than saying "don't do it" in the description for code points > 255 whilst giving a result which might puzzle the user, I decided to throw an informative error to make it clear they weren't supported. ASCII + Larin-1 only also adde to the description. I considered converting input strings to UTF-8, but that's making an assumption about how any real world algotithm would treat Unicode text. Who knows - it might pack it as UTF-16. A UTF-8 or UTF-16 option could be added later as an enhancement if a use case arose. Incidentally, I couldn't make a test for a failure case work, but since I couldn't find another test doing that to take as a pattern, it may be that I was doing it wrong. Or it may be (perish the thought) that the testing infrastructure has a bug. But evidently, testing failure cases doesn't seem to be a priority for you. |
|
Error case test added to counter aspersions about testing failure cases not being a priority. :-) (I agree that the way of doing this is not entirely intuitive, and indeed in this case I wrote the test first and added the output once I worked out what would actually happen. And searching for them to copy isn't easy as there isn't a pattern to search for that's obviously different from a normal test) |
GCHQDeveloper581
left a comment
There was a problem hiding this comment.
Looks good! (and adding a soft failure for the non-Latin use case is much better than my suggestion of documenting that it won't work).
Thanks for your contribution.
Yay! Thanks for the merge. |
|
Every day is a school day, and Claude wins a coconut! Looking here: CyberChef/tests/lib/TestRegister.mjs Lines 87 to 127 in a19261d we can see Claude is entirely correct. However because of the nature of the if statements used it tends to work even if you don't specify expectedError = True (and since the difference between "normal" and "error" output is generally pretty obvious the simpler version is good enough for most purposes. Furthermore there is only one test in the entire codebase that actually makes correct use of this: CyberChef/tests/operations/tests/Base85.mjs Lines 42 to 51 in a19261d (and no, being relatively new to this codebase myself, I didn't know this until ... now). |
Description
Converts between text strings and large integers (decimal or hexadecimal), interpreting text as big-endian byte sequences.
Changes
TextIntegerConverter.mjsoperationCategories.jsonto include Text/Integer Converter in Data format categoryFunctionality
Bidirectional conversion between text and numeric representations:
Examples:
Character limitations:
Use Cases
Features
Dependencies
Depends on BigIntUtils PR #2205
This operation uses
parseBigIntfrom the shared BigIntUtils library.Satisfies
Feature Request #2141
This operation uses
parseBigIntfrom the shared BigIntUtils library.Testing
npm run build