Created
September 8, 2022 16:15
-
-
Save Reijaff/1c5107be566c0afef8b74cd4fff6804e to your computer and use it in GitHub Desktop.
primitive compile time string obfuscation in zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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