Sample code for 30+ languages & platforms
Zig

Obfuscate String

Demonstrates how to obfuscate and unobfuscate a string.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const sb = try chilkat.StringBuilder.init();
    defer sb.deinit();

    const s = "Hello World!";

    sb.append(s) catch {};
    std.debug.print("{s}\n", .{try sb.getAsString(alloc)});

    // Output is "Hello World!";

    // Obfuscate the string.
    // This is NOT encryption.  It's just a simple obfuscation.
    sb.obfuscate();
    std.debug.print("{s}\n", .{try sb.getAsString(alloc)});

    // Output is 2GsgGhbSQVyG8Vb9

    // -------------------------
    // Unobfuscate.
    const sb2 = try chilkat.StringBuilder.init();
    defer sb2.deinit();
    const s2 = "2GsgGhbSQVyG8Vb9";
    sb2.append(s2) catch {};
    sb2.unobfuscate();

    std.debug.print("{s}\n", .{try sb2.getAsString(alloc)});

    // Output is "Hello World!";
}