Sample code for 30+ languages & platforms
Zig

Quoted-Printable Encode/Decode a String

See more Encryption Examples

_LANGUAGE_ example to quoted-printable encode and decode 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();

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const crypt = try chilkat.Crypt2.init();
    defer crypt.deinit();

    // Here's a string in Icelandic using non us-ascii chars:
    const s = "Ég get etið gler án þess að meiða mig.";

    crypt.setCryptAlgorithm("none");
    crypt.setEncodingMode("quoted-printable");

    // Quoted-printable encode/decode the iso-8859-1
    // representation of the string.  Notice how each
    // Icelandic char is represented by 1 byte:
    crypt.setCharset("iso-8859-1");
    var qp: [:0]const u8 = try crypt.encryptStringENC(alloc, s);
    std.debug.print("iso-8859-1:\n", .{});
    std.debug.print("{s}\n", .{qp});
    var decoded: [:0]const u8 = try crypt.decryptStringENC(alloc, qp);
    std.debug.print("{s}\n", .{decoded});

    // Now do the same using utf-8. Notice how each
    // Icelandic char is represented by 2 bytes in utf-8:
    crypt.setCharset("utf-8");
    qp = try crypt.encryptStringENC(alloc, s);
    std.debug.print("utf-8:\n", .{});
    std.debug.print("{s}\n", .{qp});
    decoded = try crypt.decryptStringENC(alloc, qp);
    std.debug.print("{s}\n", .{decoded});
}