commit c8a608907b0ee385f5be45728c3a960fdd060688
parent 772a79bfbb99aa54f35b41d118375f9a153cfb63
Author: superpozycja <anna@superpozycja.net>
Date: Sat, 22 Feb 2025 19:25:39 +0100
style fixes
Diffstat:
6 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/lib/analysis.c b/lib/analysis.c
@@ -3,7 +3,7 @@
unsigned long score_letter(char c)
{
/* this is approximate, however this shouldnt really make a difference
- * unless you have multiple ciphertexts very close to each other as
+ * unless you have multiple ciphertexts very close to each other as
* far as the score is concerned - meaning this is enough to weed out
* junk (nonenglish) byte sequences */
unsigned long freqs[] = {
@@ -11,7 +11,7 @@ unsigned long score_letter(char c)
22, 20, 61, 70, 1,
8, 40, 24, 67, 75,
19, 1, 60, 63, 91,
- 28, 10, 24, 2, 20,
+ 28, 10, 24, 2, 20,
1};
c = tolower(c);
@@ -109,7 +109,7 @@ static float get_i_c_m(ba *ct, unsigned int m)
chunk->len = ct->len / m;
chunk->val = (uint8_t *) malloc(sizeof(uint8_t) * chunk->len);
-
+
for (j = 0, k = 0; j < chunk->len && k + i < ct->len; j++, k += m)
chunk->val[j] = ct->val[k + i];
res += index_of_coincidence(chunk);
@@ -126,7 +126,7 @@ unsigned int guess_vigenere_keylen(ba *ct)
max = 0;
for (m = 1; m < 40; m++) {
float avg;
-
+
avg = get_i_c_m(ct, m);
if (avg > max) {
max = avg;
diff --git a/lib/ba.c b/lib/ba.c
@@ -1,6 +1,6 @@
#include "ba.h"
-ba* ba_from_hex(char* hex)
+ba* ba_from_hex(char* hex)
{
uint8_t* b_val;
size_t b_len;
@@ -58,7 +58,7 @@ ba* ba_from_string(char *s)
return b;
}
-ba* ba_from_hex_n(char* hex, unsigned int n)
+ba* ba_from_hex_n(char* hex, unsigned int n)
{
uint8_t* b_val;
size_t offset;
@@ -101,24 +101,24 @@ ba* ba_from_hex_n(char* hex, unsigned int n)
return b;
}
-void ba_fprint(ba* b, FILE* stream, int prec)
+void ba_fprint(ba* b, FILE* stream, int prec)
{
int len;
- int i;
+ int i;
len = (prec > b->len) || prec == 0 ? b->len : prec;
for (i = 0; i < len; i++)
fprintf(stream, "%02x", (b->val)[i]);
}
-void ba_fprint_ascii(ba* b, FILE* stream, int prec)
+void ba_fprint_ascii(ba* b, FILE* stream, int prec)
{
int len;
int i;
len = (prec > b->len) || prec == 0 ? b->len : prec;
for (i = 0; i < len; i++)
- if (isprint((b->val)[i]))
+ if (isprint((b->val)[i]))
fprintf(stream, "%c", (b->val)[i]);
else if (b->val[i] == 0x0a)
fprintf(stream, "\n");
@@ -126,7 +126,7 @@ void ba_fprint_ascii(ba* b, FILE* stream, int prec)
fprintf(stream, "\\b%02x", (b->val)[i]);
}
-void ba_xor(ba* a, ba* b)
+void ba_xor(ba* a, ba* b)
{
int len;
int i;
@@ -149,7 +149,7 @@ int ba_copy(ba *dst, ba *src)
}
-void ba_free(ba* b)
+void ba_free(ba* b)
{
free(b->val);
free(b);
diff --git a/lib/ba.h b/lib/ba.h
@@ -12,7 +12,7 @@
typedef struct {
size_t len;
uint8_t *val;
-} ba;
+} ba;
ba* ba_from_hex(char *hex);
ba* ba_from_hex_n(char *hex, unsigned int n);
diff --git a/src/s1/c1.c b/src/s1/c1.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <util.h>
-int main(int argc, char* argv[])
+int main(int argc, char* argv[])
{
char* b64;
int ret;
diff --git a/src/s1/c3.c b/src/s1/c3.c
@@ -1,7 +1,7 @@
#include <ba.h>
#include <analysis.h>
-int main(int argc, char* argv[])
+int main(int argc, char* argv[])
{
ba *ct;
diff --git a/src/s1/c4.c b/src/s1/c4.c
@@ -31,6 +31,7 @@ int main(int argc, char* argv[])
return -1;
p = fopen(argv[1], "r");
+
maxscore = 0;
best = (ba *) malloc(sizeof(ba));