mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
added some support functions
This commit is contained in:
parent
64a5b048e5
commit
d5e33fb209
2 changed files with 29 additions and 0 deletions
|
@ -1145,6 +1145,12 @@ void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hex_xor(uint8_t *d, uint8_t *x, int n) {
|
||||||
|
while(n--) {
|
||||||
|
d[n] ^= x[n];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return parity bit required to match type
|
// return parity bit required to match type
|
||||||
uint8_t GetParity(const uint8_t *bits, uint8_t type, int length) {
|
uint8_t GetParity(const uint8_t *bits, uint8_t type, int length) {
|
||||||
int x;
|
int x;
|
||||||
|
@ -1474,3 +1480,22 @@ void sb_append_char(smartbuf *sb, unsigned char c) {
|
||||||
sb->ptr[sb->idx] = c;
|
sb->ptr[sb->idx] = c;
|
||||||
sb->idx++;
|
sb->idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t get_highest_frequency(const uint8_t *d, uint8_t n) {
|
||||||
|
|
||||||
|
uint8_t frequency[256] = {0};
|
||||||
|
uint8_t highest = 0;
|
||||||
|
uint8_t v = 0;
|
||||||
|
|
||||||
|
// Count the frequency of each byte
|
||||||
|
for(uint8_t i = 0; i < n; i++) {
|
||||||
|
frequency[d[i]]++;
|
||||||
|
|
||||||
|
if (frequency[d[i]] > highest) {
|
||||||
|
highest = frequency[d[i]];
|
||||||
|
v = d[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PrintAndLogEx(DEBUG, "highest occurance... %u xor byte... 0x%02X", highest, v);
|
||||||
|
return v;
|
||||||
|
}
|
|
@ -133,6 +133,8 @@ int binstr_2_binarray(uint8_t *target, char *source, int length);
|
||||||
void bytes_2_binstr(char *target, const uint8_t *source, size_t sourcelen);
|
void bytes_2_binstr(char *target, const uint8_t *source, size_t sourcelen);
|
||||||
void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src);
|
void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src);
|
||||||
|
|
||||||
|
void hex_xor(uint8_t *d, uint8_t *x, int n);
|
||||||
|
|
||||||
uint8_t GetParity(const uint8_t *bits, uint8_t type, int length);
|
uint8_t GetParity(const uint8_t *bits, uint8_t type, int length);
|
||||||
void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);
|
void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);
|
||||||
void wiegand_add_parity_swapped(uint8_t *target, uint8_t *source, uint8_t length);
|
void wiegand_add_parity_swapped(uint8_t *target, uint8_t *source, uint8_t length);
|
||||||
|
@ -179,4 +181,6 @@ struct smartbuf {
|
||||||
size_t idx;
|
size_t idx;
|
||||||
} typedef smartbuf;
|
} typedef smartbuf;
|
||||||
void sb_append_char(smartbuf *sb, unsigned char c);
|
void sb_append_char(smartbuf *sb, unsigned char c);
|
||||||
|
|
||||||
|
uint8_t get_highest_frequency(const uint8_t *d, uint8_t n);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue