There are some times when AppleScript is not a good tool to manipulate text (specially Unicode text). Then, you must make use of some third-party tool, as Perl or Python (via “do shell script”), or the scriptable applications Extra Suites, Smile or TextCommands.
You can use these tools to search/replace Unicode text, encode text (base64, etc.), use regular expressions, convert text to binary, transcode text, etc.
My advice is: if you know-how, first try command-line tools, just for portability. While you can use TextCommands or Smile to convert text to base64 (for example), you can also use the *nix tool “openssl” as well, which is very quick and installed in the system by default.