Add base64 tool

This commit is contained in:
2026-08-11 11:34:46 +08:00
parent 3976a8d7e7
commit 0292c0ebb2
10 changed files with 170 additions and 15 deletions
+46
View File
@@ -0,0 +1,46 @@
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
int main(int argc, char **argv) {
const char *filename = "a.bin";
int bytes_count = 256;
if (argc > 1)
filename = argv[1];
if (argc > 2)
bytes_count = atoi(argv[2]);
auto hex_file = fopen(filename, "wb");
if (hex_file == NULL) {
return -1;
}
srand(time(NULL));
constexpr int chunk_size = 0x400;
unsigned char buffer[chunk_size];
for (int total_bytes = bytes_count; chunk_size < total_bytes; total_bytes -= chunk_size) {
memset(buffer, 0, chunk_size);
for (int i = 0; i < chunk_size; ++ i) {
buffer[i] = rand() % UCHAR_MAX;
}
fwrite(buffer, chunk_size, 1, hex_file);
}
memset(buffer, 0, chunk_size);
for (int i = 0; i < bytes_count % chunk_size; ++ i) {
buffer[i] = rand() % UCHAR_MAX;
}
fwrite(buffer, bytes_count % chunk_size, 1, hex_file);
fclose(hex_file);
return 0;
}