in reply to Re^3: Rewriting a C# Encryption Function
in thread Rewriting a C# Encryption Function

First off, you shouldn't forget to mention use Encode; -- believe it or not, some folks might still not be aware that "encode" is not a perl built-in function, and/or might not know what module it comes from. (Update: but on closer inspection, I see the OP does know about Encode, so I apologize for the nit-pick.)

Second, you really should not use "utf16" in this case -- better to specify what byte order you really want for the job, because that way, perl won't automatically add the BOM at the start of the string, and you won't have to byte-swap later:

$ perl -MEncode -e '$o=encode("utf16","1234"); print $o' | xxd -g1 0000000: fe ff 00 31 00 32 00 33 00 34 ...1.2.3.4 $ perl -MEncode -e '$o=encode("utf16le","1234"); print $o' | xxd -g1 0000000: 31 00 32 00 33 00 34 00 1.2.3.4. $ perl -MEncode -e '$o=encode("utf16be","1234"); print $o' | xxd -g1 0000000: 00 31 00 32 00 33 00 34 .1.2.3.4