matasano/src/main.zig

52 lines
1.5 KiB
Zig
Raw Normal View History

2025-02-07 21:35:45 +01:00
const std = @import("std");
const b64 = @import("base64.zig");
const hex = @import("hex.zig");
2025-02-08 06:33:30 +01:00
const xor = @import("xor.zig");
2025-02-07 21:35:45 +01:00
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
const stdout = std.io.getStdOut().writer();
if (std.mem.eql(u8, args[1], "b64")) {
if (std.mem.eql(u8, args[2], "-d")) {
const result = try b64.decode(allocator, args[3]);
defer allocator.free(result);
try stdout.print("{s}", .{result});
}
if (std.mem.eql(u8, args[2], "-e")) {
const buf = try hex.decode(allocator, args[3]);
defer allocator.free(buf);
const result = try b64.encode(allocator, buf);
defer allocator.free(result);
try stdout.print("{s}", .{result});
}
}
2025-02-08 06:33:30 +01:00
if (std.mem.eql(u8, args[1], "xor")) {
const in_a = args[2];
const in_b = args[3];
const buf_a = try hex.decode(allocator, in_a);
defer allocator.free(buf_a);
const buf_b = try hex.decode(allocator, in_b);
defer allocator.free(buf_b);
const out = try xor.xor_buffers(allocator, buf_a, buf_b);
defer allocator.free(out);
const out_hex = try hex.encode(allocator, out);
defer allocator.free(out_hex);
try stdout.print("{s}", .{out_hex});
}
2025-02-07 21:35:45 +01:00
}