matasano/src/main.zig

32 lines
934 B
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");
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});
}
}
}