strenc

A library to automatically encrypt all string constants in your programs

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:24

Installation

nimble install strenc
choosenim install strenc
git clone https://github.com/nim-meta/strenc

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
strenc - - - - - - -

Source

Repository https://github.com/nim-meta/strenc
Homepage https://github.com/nim-meta/strenc
Registry Source nimble_official

README

nim-strenc

This is a Nim library for automatic encryption (currently via XOR with a different key for each string generated at compile-time) of string literals. You can install it from Nimble via

nimble install strenc

and then just use it like so:

import strenc
# After importing the module you don't have to do anything else to activate encryption
echo "hello world"
echo "how are you?"

In compiled C code (or in any other backend, strenc works with all of them, although with the JS backend it'll be much easier for "interested" people to get the original contents back) strings will look like this:

STRING_LITERAL(TM__huvhZYSc4ExMXNTyiw83eQ_2, "as{xz2d\177cr{", 11);
STRING_LITERAL(TM__huvhZYSc4ExMXNTyiw83eQ_3, "kov\036^NX\032BWL\011", 12);

If you wish to disable all hints for places where the encryption was applied, add hint("Pattern", false) to your .nims config file, or, if you use .cfg, --hint[Pattern]:off

Please do not forget to strip your binaries if you want this library to be useful! Otherwise it'll be much easier to find the code which does string decryption.

How does it work?

This library uses one of the lesser known Nim features - term-rewriting macros. They allow to implicitly rewrite code at compile-time by using different kinds of patterns. You can read more in the manual here.

Why?

Because it's fun and this library can actually help you to protect string data in the application from not-so-experienced "haxxors".

Do not forget that a person with enough programming and/or reverse-engineering knowledge will still be able to get the original content of all encrypted strings!