mirror of
https://github.com/albertobsd/keyhunt.git
synced 2025-03-17 21:31:49 +01:00
I get mixed result about the speed performance: - bP Table creation is 4 or 5 times faster - address and rmd160 get the same speed. WHY? - xpoint get less speed. WTF? - bsgs not implemented yet. I need to move every mode to his own funtion to see if the xpoint speed get the double speed as spected. If nothing of this works, i will only keep the changes about the bP table creation (the only good change at the momment)
168 lines
3.1 KiB
C
168 lines
3.1 KiB
C
#include <cstring>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
|
|
#include "util.h"
|
|
|
|
|
|
char *ltrim(char *str, const char *seps) {
|
|
size_t totrim;
|
|
if (seps == NULL) {
|
|
seps = "\t\n\v\f\r ";
|
|
}
|
|
totrim = strspn(str, seps);
|
|
if (totrim > 0) {
|
|
size_t len = strlen(str);
|
|
if (totrim == len) {
|
|
str[0] = '\0';
|
|
}
|
|
else {
|
|
memmove(str, str + totrim, len + 1 - totrim);
|
|
}
|
|
}
|
|
return str;
|
|
}
|
|
|
|
char *rtrim(char *str, const char *seps) {
|
|
int i;
|
|
if (seps == NULL) {
|
|
seps = "\t\n\v\f\r ";
|
|
}
|
|
i = strlen(str) - 1;
|
|
while (i >= 0 && strchr(seps, str[i]) != NULL) {
|
|
str[i] = '\0';
|
|
i--;
|
|
}
|
|
return str;
|
|
}
|
|
|
|
char *trim(char *str, const char *seps) {
|
|
return ltrim(rtrim(str, seps), seps);
|
|
}
|
|
|
|
int indexOf(char *s,const char **array,int length_array) {
|
|
int index = -1,i,continuar = 1;
|
|
for(i = 0; i <length_array && continuar; i++) {
|
|
if(strcmp(s,array[i]) == 0) {
|
|
index = i;
|
|
continuar = 0;
|
|
}
|
|
}
|
|
return index;
|
|
}
|
|
|
|
char *nextToken(Tokenizer *t) {
|
|
if(t->current < t->n) {
|
|
t->current++;
|
|
return t->tokens[t->current-1];
|
|
}
|
|
else {
|
|
return NULL;
|
|
}
|
|
}
|
|
int hasMoreTokens(Tokenizer *t) {
|
|
return (t->current < t->n);
|
|
}
|
|
|
|
void stringtokenizer(char *data,Tokenizer *t) {
|
|
char *token;
|
|
t->tokens = NULL;
|
|
t->n = 0;
|
|
t->current = 0;
|
|
trim(data,"\t\n\r :");
|
|
token = strtok(data," \t:");
|
|
while(token != NULL) {
|
|
t->n++;
|
|
t->tokens = (char**) realloc(t->tokens,sizeof(char*)*t->n);
|
|
if(t->tokens == NULL) {
|
|
printf("Out of memory\n");
|
|
exit(0);
|
|
}
|
|
t->tokens[t->n - 1] = token;
|
|
token = strtok(NULL," \t");
|
|
}
|
|
}
|
|
|
|
void freetokenizer(Tokenizer *t) {
|
|
if(t->n > 0) {
|
|
free(t->tokens);
|
|
}
|
|
memset(t,0,sizeof(Tokenizer));
|
|
}
|
|
|
|
|
|
/*
|
|
Aux function to get the hexvalues of the data
|
|
*/
|
|
char *tohex(char *ptr,int length){
|
|
char *buffer;
|
|
int offset = 0;
|
|
unsigned char c;
|
|
buffer = (char *) malloc((length * 2)+1);
|
|
for (int i = 0; i <length; i++) {
|
|
c = ptr[i];
|
|
sprintf((char*) (buffer + offset),"%.2x",c);
|
|
offset+=2;
|
|
}
|
|
buffer[length*2] = 0;
|
|
return buffer;
|
|
}
|
|
|
|
int hexs2bin(char *hex, unsigned char *out) {
|
|
int len;
|
|
char b1;
|
|
char b2;
|
|
int i;
|
|
|
|
if (hex == NULL || *hex == '\0' || out == NULL)
|
|
return 0;
|
|
|
|
len = strlen(hex);
|
|
if (len % 2 != 0)
|
|
return 0;
|
|
len /= 2;
|
|
|
|
memset(out, 'A', len);
|
|
for (i=0; i<len; i++) {
|
|
if (!hexchr2bin(hex[i*2], &b1) || !hexchr2bin(hex[i*2+1], &b2)) {
|
|
return 0;
|
|
}
|
|
out[i] = (b1 << 4) | b2;
|
|
}
|
|
return len;
|
|
}
|
|
|
|
int hexchr2bin(const char hex, char *out) {
|
|
if (out == NULL)
|
|
return 0;
|
|
|
|
if (hex >= '0' && hex <= '9') {
|
|
*out = hex - '0';
|
|
} else if (hex >= 'A' && hex <= 'F') {
|
|
*out = hex - 'A' + 10;
|
|
} else if (hex >= 'a' && hex <= 'f') {
|
|
*out = hex - 'a' + 10;
|
|
} else {
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
void addItemList(char *data, List *l) {
|
|
l->data = (char**) realloc(l->data,sizeof(char*)* (l->n +1));
|
|
l->data[l->n] = data;
|
|
l->n++;
|
|
}
|
|
|
|
int isValidHex(char *data) {
|
|
char c;
|
|
int len,i,valid = 1;
|
|
len = strlen(data);
|
|
for(i = 0 ; i < len && valid ;i++ ) {
|
|
c = data[i];
|
|
valid = ( (c >= '0' && c <='9') || (c >= 'A' && c <='F' ) || (c >= 'a' && c <='f' ) );
|
|
}
|
|
return valid;
|
|
}
|