zalgo_embed!() { /* proc-macro */ }
Expand description

This macro decodes a string that has been encoded with zalgo_encode and passes the results on to the compiler.

To generate the encoded string used as input you can use the provided program. It can be installed with cargo install zalgo-codec --features binary.

Examples

We can use a function created in encoded source code:

// This line expands to the code
// `fn add(x: i32, y: i32) -> i32 {x + y}`
zalgo_embed!("E͎͉͙͉̞͉͙͆̀́̈́̈́̈̀̓̒̌̀̀̓̒̉̀̍̀̓̒̀͛̀̋̀͘̚̚͘͝");

// Now the `add` function is available
assert_eq!(add(10, 20), 30);

It works on expressions too!

let x = 20;
let y = -10;

// This macro is expanded to the code
// `x + y`
let z = zalgo_embed!("È͙̋̀͘");
assert_eq!(z, x + y);

A more complex example is this program which expands to code that reads the command line input, encodes it, and prints out the result.

use zalgo_codec_common::{zalgo_encode, Error};
use zalgo_codec_macro::zalgo_embed;

fn main() -> Result<(), Error> {
    // This macro expands to
    // let input = std::env::args().collect::<Vec<_>>()[1..].join(" ");
    // let output = zalgo_encode(&input)?;
    // println!("{}", output);
    zalgo_embed!("E͔͉͎͕͔̝͓͔͎͖͇͓͌̀͐̀̀̈́́͒̈̉̎̓̚̚̚̚ͅͅ͏̶͔̜̜̞̞̻͌͌̓̓̿̈̉̑̎̎̽̎͊̚̚ͅͅ͏̛͉͎͔̈̂̀̂̉ͯ͌̀ͅ͏͕͔͕͔̝͚͇͐̀̀́͌͏͎̿̓ͅ͏̛͉͎͕͔̟͉͎͔͎̼͎̼͎̈́̈̆͐̉ͯ͐͒͌́̈̂͛̂̌̀͝ͅ͏̛͕͔͕͔͐̉");
    Ok(())
}

Do the opposite of obfstr: obfuscate a string while coding and deobfuscate it during compile time

const SECRET: &str = zalgo_embed!("Ê̤͏͎͔͔͈͉͓͍̇̀͒́̈́̀̀ͅ͏͍́̂");

assert_eq!(SECRET, "Don't read this mom!");

To do something more like obfstr, use zalgofy!.

Errors

This macro utilizes zalgo_decode internally, and converts its errors into compile errors. E.g. it will most likely result in a compile error if you use this macro on a string that was not generated by zalgo_encode:

// compile error: the given string decodes into an invalid utf-8 sequence of 1 bytes from index 0
zalgo_embed!("Zalgo");