Fix types in frequency_score
This commit is contained in:
parent
cd7c584e6f
commit
a47bcc8f9e
4 changed files with 6 additions and 6 deletions
|
@ -14,10 +14,10 @@ int main(int argc, char *argv[]) {
|
||||||
unsigned char buf[512] = {0};
|
unsigned char buf[512] = {0};
|
||||||
size_t len = hex_to_bytes(buf, argv[1]);
|
size_t len = hex_to_bytes(buf, argv[1]);
|
||||||
|
|
||||||
unsigned char cur[512];
|
char cur[512];
|
||||||
double min_score = INFINITY;
|
double min_score = INFINITY;
|
||||||
unsigned char key;
|
char key;
|
||||||
unsigned char best[512];
|
char best[512];
|
||||||
// Test for keys from A to z
|
// Test for keys from A to z
|
||||||
for (char c = 65; c < 127; ++c) {
|
for (char c = 65; c < 127; ++c) {
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ int main(int argc, char *argv[]) {
|
||||||
unsigned char buf[512] = {0};
|
unsigned char buf[512] = {0};
|
||||||
len = hex_to_bytes(buf, line);
|
len = hex_to_bytes(buf, line);
|
||||||
|
|
||||||
unsigned char cur[512] = {'\0'};
|
char cur[512] = {'\0'};
|
||||||
for (char c = 32; c < 127; ++c) {
|
for (char c = 32; c < 127; ++c) {
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
cur[i] = buf[i] ^ c;
|
cur[i] = buf[i] ^ c;
|
||||||
|
|
2
utils.c
2
utils.c
|
@ -50,7 +50,7 @@ char *bytes_to_base64(char *out, const unsigned char in[static 1], size_t len) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
double frequency_score(unsigned char *buf, size_t len) {
|
double frequency_score(const char *buf, size_t len) {
|
||||||
static const double english_freqs[27] = {
|
static const double english_freqs[27] = {
|
||||||
0.08167, 0.01492, 0.02782, 0.04253, 0.12702, 0.02228, 0.02015, // A-G
|
0.08167, 0.01492, 0.02782, 0.04253, 0.12702, 0.02228, 0.02015, // A-G
|
||||||
0.06094, 0.06966, 0.00153, 0.00772, 0.04025, 0.02406, 0.06749, // H-N
|
0.06094, 0.06966, 0.00153, 0.00772, 0.04025, 0.02406, 0.06749, // H-N
|
||||||
|
|
2
utils.h
2
utils.h
|
@ -6,7 +6,7 @@
|
||||||
unsigned char hex_to_byte(const char c);
|
unsigned char hex_to_byte(const char c);
|
||||||
size_t hex_to_bytes(unsigned char *out, const char hex[static 1]);
|
size_t hex_to_bytes(unsigned char *out, const char hex[static 1]);
|
||||||
char *bytes_to_base64(char *out, const unsigned char in[static 1], size_t len);
|
char *bytes_to_base64(char *out, const unsigned char in[static 1], size_t len);
|
||||||
double frequency_score(unsigned char *buf, size_t len);
|
double frequency_score(const char *buf, size_t len);
|
||||||
unsigned int hamming(const char *s1, const char *s2);
|
unsigned int hamming(const char *s1, const char *s2);
|
||||||
|
|
||||||
#endif /* UTILS_H */
|
#endif /* UTILS_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue