Skip to content

Instantly share code, notes, and snippets.

@Reijaff
Created September 8, 2022 16:15
Show Gist options
  • Select an option

  • Save Reijaff/1c5107be566c0afef8b74cd4fff6804e to your computer and use it in GitHub Desktop.

Select an option

Save Reijaff/1c5107be566c0afef8b74cd4fff6804e to your computer and use it in GitHub Desktop.
primitive compile time string obfuscation in zig
const std = @import("std");
fn encrypt(comptime string: []const u8) []const u8{
var new_string: [string.len]u8 = undefined;
for (string) |chr, idx|{
new_string[idx] = chr ^ 0xff;
}
return &new_string;
}
fn decrypt(comptime string: []const u8) []const u8{
var new_string: [string.len]u8 = undefined;
for (string) |chr, idx|{
new_string[idx] = chr ^ 0xff;
}
return &new_string;
}
fn _x(comptime s:[]const u8) []const u8{
return decrypt(comptime encrypt(s));
}
pub fn main() !void{
const stdout = std.io.getStdOut().writer();
try stdout.print("{s}\n", .{_x("hello, world!")});
try stdout.print("{s}\n", .{_x("bravo")});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment