twofish icon indicating copy to clipboard operation
twofish copied to clipboard

stringToByteArray() [utils.strToUTF8Arr()] assumes Javascript strings are UTF-32 not UTF-16

Open GeneThomas opened this issue 6 years ago • 0 comments

Thanks for the Javacsript TwoFish implementation, the world needs ciphers we can trust, butt here is a fault however in the support methods stringToByteArray() and byteArrayToString()

stringToByteArray() takes a Javascript string an produces an array of utf-8 bytes. The code is assuming Javascript strings are UTF-32 not UTF-16: e.g: 😮 FACE WITH OPEN MOUTH is "\uD83D\uDE2E" in Javascript, when turned into UTF-8 it should be [f0 9f 98 ae] see https://www.fileformat.info/info/unicode/char/01F62E/index.htm, not [ed a0 bd ed b8 ae] that is produced at the moment, encoding "\uD83D" and "\uDE2E" separately.

.html that shows the fault atached, I had to put in inside a .zip to attach it to gituhub.

twofish-utf8-fault.html.zip

The methods should probably have utf-8 in the names.

GeneThomas avatar Oct 03 '19 03:10 GeneThomas