commit 9fa92a533c32c17354fee573638b41920f24551f
parent ebd62e982ee37128d8ddbd85b3c1fca17b209106
Author: anna <anna@brokenlove.online>
Date: Fri, 26 Jul 2024 23:01:19 +0200
style fixup
Diffstat:
4 files changed, 37 insertions(+), 41 deletions(-)
diff --git a/.gitignore b/.gitignore
diff --git a/s1/build.sh b/s1/build.sh
@@ -1,8 +1,6 @@
-#!/bin/zsh
-
-source ~/.zshrc
+#!/bin/sh
for filename in *.c; do
echo "compiling $filename"
- cc -o "bin/$(basename $filename .c)" $filename
+ gcc -lba -o "bin/$(basename $filename .c)" $filename
done
diff --git a/s1/c1.c b/s1/c1.c
@@ -4,44 +4,43 @@
static int hex_to_base64(const char* hex, char** b64)
{
- const char b64table[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ const char b64table[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- int length = strlen(hex);
- int block_count = length / 6;
- int res_length = block_count*4;
- int leftover_length = length % 6;
- if(leftover_length%2 == 1) {
- fprintf(stderr, "bad sequence length\n");
- return -1;
- }
+ int length = strlen(hex);
+ int block_count = length / 6;
+ int res_length = block_count*4;
+ int leftover_length = length % 6;
+ if (leftover_length%2 == 1) {
+ fprintf(stderr, "bad sequence length\n");
+ return -1;
+ }
- char * res = (char*)(malloc(sizeof(char)*res_length+2));
+ char * res = (char*)(malloc(sizeof(char)*res_length+2));
- for(int i = 0; i < block_count+(leftover_length != 0); i++) {
- int end_ix = i < block_count ? 6 : leftover_length;
- char block[6+1];
- memcpy(block, hex+(6*i), end_ix);
- block[end_ix] = '\0';
-
- int block_hex = strtol(block, NULL, 16);
- block_hex <<= 4*(6-end_ix);
-
- for(int j = 0; j < 4; j++) {
- char b64 = b64table[(block_hex >> 6*(3-j))& 0x3f];
- res[4*i+j] = j <= end_ix/2 ? b64 : '=';
- }
- }
- *b64 = res;
- return 0;
+ for (int i = 0; i < block_count+(leftover_length != 0); i++) {
+ int end_ix = i < block_count ? 6 : leftover_length;
+ char block[6+1];
+ memcpy(block, hex+(6*i), end_ix);
+ block[end_ix] = '\0';
+
+ int block_hex = strtol(block, NULL, 16);
+ block_hex <<= 4*(6-end_ix);
+
+ for (int j = 0; j < 4; j++) {
+ char b64 = b64table[(block_hex >> 6*(3-j))& 0x3f];
+ res[4*i+j] = j <= end_ix/2 ? b64 : '=';
+ }
+ }
+ *b64 = res;
+ return 0;
}
int main(int argc, char* argv[])
{
- char* b64;
- int ret = hex_to_base64(argv[1], &b64);
- if(ret == 0) {
- printf("%s\n", b64);
- }
- return 0;
+ char* b64;
+ int ret = hex_to_base64(argv[1], &b64);
+ if (ret == 0)
+ printf("%s\n", b64);
+ return 0;
}
diff --git a/s1/c2.c b/s1/c2.c
@@ -1,14 +1,13 @@
-#include <ba/ba.h> /* see my tools repo for this */
+#include <ba.h> /* see my tools repo for this */
int main(int argc, char* argv[]) {
- if(argc != 3) {
+ if(argc != 3)
return -1;
- }
ba* a;
ba* b;
a = ba_from_hex(argv[1]);
b = ba_from_hex(argv[2]);
- if(a == NULL || b == NULL) {
+ if (a == NULL || b == NULL) {
return -1;
}
ba_xor(a, b);