Implement character frequency histogram for ch. 3
This commit is contained in:
parent
0e4aa9c416
commit
7a18aab19b
|
@ -5,7 +5,7 @@ DEBUG = -0g -ggdb
|
||||||
LINK =
|
LINK =
|
||||||
SRC_DIR = src
|
SRC_DIR = src
|
||||||
OUT_DIR = bin
|
OUT_DIR = bin
|
||||||
TARGETS = base64 fixed-xor
|
TARGETS = base64 fixed-xor char-freq-analize
|
||||||
|
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int8_t ciphertext[] = "\x1b\x37\x37\x33\x31\x36\x3f\x78\x15\x1b\x7f\x2b"
|
||||||
|
"\x78\x34\x31\x33\x3d\x78\x39\x78\x28\x37\x2d\x36"
|
||||||
|
"\x3c\x78\x37\x3e\x78\x3a\x39\x3b\x37\x36";
|
||||||
|
uint8_t byte_freq[256];
|
||||||
|
memset(byte_freq, 0, sizeof(byte_freq));
|
||||||
|
|
||||||
|
// get histogram (count byte occurences)
|
||||||
|
for (i = 0; i < sizeof(ciphertext)-1; ++i) {
|
||||||
|
byte_freq[ciphertext[i]] += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(byte_freq); ++i) {
|
||||||
|
if (byte_freq[i] != 0) {
|
||||||
|
printf("%x occurs %d times\n", i, byte_freq[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue