Scream Cipher Translator
I have just completed my first project. It can be found in the Projects section or via this link.
It is inspired by the xkcd comic called Scream Cipher and by the intention to try a WebAssembly module as shown in this Applied Go guide called WebAssembly in 5 Minutes.
I could have done it just with JavaScript, but I wanted to work with the WebAssembly technology because it looks like it could perform really powerful things much more efficiently. Nevertheless, I have the impression that if you really want efficiency, you should try to do it in Rust instead of Go (but Go is also very nice).
When I completed the WebAssembly guide, everything worked perfectly because it is a really simple example. But when I wanted to move it to my case, things changed.
First of all, I had two boxes instead of one, so I needed two event listeners. Then I realized the id input was not a very good id name because we also have an input event type as parameter for the function addEventListener.
In the HTML, there was a line that did not pass the W3C validator:
<script defer>
This is because the use of defer requires a separate file. I could separate the script or just remove the defer. I did this last thing because it seems to work, but maybe a separate script file would be more elegant.
Then I had to make sure that when updating a field, the other one would not be updated automatically. This was done by making sure the event isTrusted (i.e., generated by the user).
It was not difficult, but tedious, to find all the characters mentioned in the comic. And when I had them all, I realized some were not considered just one character, so the rune-by-rune processing I had before would not work now. After changing it to string search and replace (strings.ReplaceAll), it worked.
Or that is what I thought. The comic image had an HTML title that was also a ciphered message, and it did not work. The reason was that two characters might look the same but actually are not. Or they are the same, but one is represented with two characters instead of just one. To solve this, I had to add more cases to make sure that, at least, that message could be solved.
Most likely, this project could be improved by considering more discrepancies between characters. I could also add a style to the HTML so it would look more beautiful. But this is out of the project’s scope.