add hamming_distance
All checks were successful
Test and Deploy / test (push) Successful in 13s
Test and Deploy / docs (push) Successful in 21s

This commit is contained in:
2024-05-05 17:05:12 -07:00
parent c81c8bfa3c
commit 89a3585c7f
4 changed files with 22 additions and 4 deletions

View File

@ -272,12 +272,16 @@ const unsigned char *repeating_key_xor_s(const char* s, const char* key) {
return repeating_key_xor((unsigned char*)s, strlen(s), (unsigned char*)key, strlen(key));
}
unsigned int hamming_distance(const char *a, const char *b) {
unsigned int hamming_distance_s(const char *a, const char *b) {
size_t sz = strlen(a);
if (sz != strlen(b)) {
return -1;
}
return hamming_distance((unsigned char *)a, (unsigned char *)b, sz);
}
unsigned int hamming_distance(unsigned char *a, unsigned char *b, size_t sz) {
unsigned int hamming = 0;
for (size_t i = 0; i < sz; ++i) {
if (a[i] == b[i]) {