I’d appreciate suggestions on how I can convert ASCII control characters, which are supplied via an HTML text box, to their hexadecimal or binary representations.
Currently, my web app, takes the ASCII control character string and converts the values, for example, if ^C is entered the value 5e43 is returned which represents “^” and “6”, not control-c which is represented as 02 in hex.
The idea I had was to run a regex against the input to check for control characters with something like: ^[\w]{1} and then return values from a predefined table that matches the regex.
You can directly read from in with
(. *in* read)though how the characters get to you is going to be dependent on a lot of things, most specifically the case that the browser is likely to encode them for http transport before you even get started.I maintain a secure terminal proxy that has to handle all combinations of control characters so I thought I would pass on a few notes:
The best way is to write a small program that reads from the keyboard one character at a time and then start mashing the keyboard and see what you can come up with.
Here I will read a character from in twice and hit home the first time and end the second
So clearly one character is not enough to distinguish these two keys, how about two characters?
This next example won’t run in the repl because the repl tries to “handle” control character for you, so you will have to make a new project
lein new escadd this code thenlein uberjarandjava -jar esc-1.0.0-SNAPSHOT-standalone.jarRunning it and hitting these two keys produces this:
Here is esc–end
And the ctrl character grand prize winner thus far esc–right-arrow
taking the prize at six bytes.