Skip to content

Instantly share code, notes, and snippets.

@Reijaff
Created January 20, 2023 21:17
Show Gist options
  • Select an option

  • Save Reijaff/705051174717949168a6ded88dbf7bf9 to your computer and use it in GitHub Desktop.

Select an option

Save Reijaff/705051174717949168a6ded88dbf7bf9 to your computer and use it in GitHub Desktop.
primitive compile time string obfuscation in zig, stack strings, position independent code
const std = @import("std");
fn _x(comptime string: []const u8) [string.len]u8 {
var encrypted_string: [string.len]u8 = undefined;
var decrypted_string: [string.len]u8 = undefined;
inline for (string) |chr, idx| {
encrypted_string[idx] = chr ^ 0x99;
}
for (encrypted_string) |chr, idx| {
decrypted_string[idx] = chr ^ 0x99;
}
return decrypted_string;
}
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("{s}\n", .{_x("hello my dear friend")});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment