Skip to content

Instantly share code, notes, and snippets.

@Reijaff
Reijaff / string_to_hash_djb2.zig
Created January 20, 2023 21:32
convert string to djb2 hash at compile time in zig
const std = @import("std");
fn hash_string_djb2(comptime string: []const u8) u64 {
var hash: u64 = 5381;
inline for (string) |chr| {
hash = ((hash << 5) + hash) + chr;
}
return hash;
@Reijaff
Reijaff / stack_string.zig
Created January 20, 2023 21:22
convert string to stack string at compile time in zig
const std = @import("std");
fn stack_string(comptime string: []const u8) [string.len]u8{
var new_string: [string.len]u8 = undefined;
inline for (string) |chr, idx|{
new_string[idx] = chr;
}
return new_string;
@Reijaff
Reijaff / string_obfuscation_stackstring.zig
Created January 20, 2023 21:17
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;
}
@Reijaff
Reijaff / comptime_rand.zig
Created September 9, 2022 11:14
primitive compile time random number generation in zig
const std = @import("std");
const RndGen = std.rand.DefaultPrng;
fn rand_at_comptime() u32 {
var rnd = RndGen.init(1337);
var a = rnd.random().int(u32);
return a;
}
@Reijaff
Reijaff / string_obfuscation.zig
Created September 8, 2022 16:15
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;