Skip to content

Commit

Permalink
Added new tool hexcharstoraw to create binary file from a hexadecimal…
Browse files Browse the repository at this point in the history
… text file
  • Loading branch information
albertobsd committed Dec 23, 2020
1 parent 24eb4be commit ab292a0
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 60 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 0.1.20201223
- Added new tool hexcharstoraw to create a raw binary file for xpoint from a text-hexadecimal file
- Added option -w to work with raw binary file, this file contains xpoint in binary format fixed to 32 bytes

Version 0.1.20201222
- Fixed some ugly bug in the searchbinary function thanks to Ujang
- Added to stdout the vanitykeys found with -v option
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ default:
gcc -O3 -c keccak/keccak-tiny.c -o keccak.o -D"memset_s(W,WL,V,OL)=memset(W,V,OL)"
gcc -O3 -c keyhunt.c -o keyhunt.o
gcc -o keyhunt keyhunt.o base58.o rmd160.o sha256.o bloom.o murmurhash2.o keccak.o -lgmp -lm -lpthread
gcc -O3 hexcharstoraw.c -o hexcharstoraw
clean:
rm -r *.o

120 changes: 120 additions & 0 deletions hexcharstoraw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
Develop by Luis Alberto
email: [email protected]
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "util.h"

int MAXLENGTHADDRESS = 32;

void quicksort(char *arr, int low, int high);
void swap(char *a,char *b);
int partition (char *arr, int low, int high);

int main(int argc,char **argv) {
char *line_input,*line_output,*aux;
FILE *input,*output;
int len,diff,i,count = 0;
if(argc != 3) {
printf("Usage:\n%s <input hex file> <output binay file>\n",argv[0]);
exit(0);
}
input = fopen(argv[1],"r");
output = fopen(argv[2],"wb");
line_input = malloc(1024);
line_output = malloc(32);
if(input == NULL || output == NULL || line_input== NULL || line_output == NULL ) {
printf("error fopen or malloc\n");
}
while(!feof(input)) {
aux = fgets(line_input,1024,input);
if(aux == line_input) {
trim(line_input,"\t\n\r ");
len = strlen(line_input);
if(len <= 64){
if(isValidHex(line_input)) {
if(len < 64) {
aux = malloc(65);
diff = 64 - len;
strcpy(aux+diff,line_input);
memset(aux,'0',diff);
memcpy(line_input,aux,65);
free(aux);
}
hexs2bin(line_input,line_output);
fwrite(line_output,1,32,output);
count++;
}
else {
printf("Ignoring invalid hexadecimal line: %s\n",line_input);
}
}
else {
printf("Ignoring invalid length line: %s\n",line_input);
}
}
}
fclose(input);
fclose(output);
free(line_input);
output = fopen(argv[2],"rb");
do {
line_input = malloc(count*32);
} while(line_input == NULL);
i = 0;
while(i < count) {
fread(line_input+(i*32),1,32,output);
i++;
}
fclose(output);
output = fopen(argv[2],"wb");
printf("File %s was create with %u records\n",argv[2],count);
printf("Sorting once... \n");
quicksort(line_input,0,count-1);
i = 0;
while(i < count) {
fwrite(line_input+(i*32),1,32,output);
i++;
}
fclose(output);
printf("ready\n");
free(line_output);
return 0;
}


void swap(char *a,char *b) {
char t[MAXLENGTHADDRESS];
memcpy(t,a,MAXLENGTHADDRESS);
memcpy(a,b,MAXLENGTHADDRESS);
memcpy(b,t,MAXLENGTHADDRESS);
}

int partition (char *arr, int low, int high) {
char *pivot = arr + (high*MAXLENGTHADDRESS); // pivot
//printf("Pivot : %s\n",pivot);
int j,i = (low - 1); // Index of smaller element
for (j = low; j < high; j++) {
// If current element is smaller than the pivot
if (memcmp(arr + (j*MAXLENGTHADDRESS),pivot,MAXLENGTHADDRESS) < 0) {
i++; // increment index of smaller element
swap(arr + (i*MAXLENGTHADDRESS), arr + (j*MAXLENGTHADDRESS));
}
}
swap(arr + ((i+1)*MAXLENGTHADDRESS), arr + (high*MAXLENGTHADDRESS));
return (i + 1);
}

void quicksort(char *arr, int low, int high) {
int pi;
if (low < high) {
//printf("quicksort from %i to %i\n",low,high);
pi = partition(arr, low, high);
quicksort(arr, low, pi - 1);
quicksort(arr, pi + 1, high);
}
}
145 changes: 86 additions & 59 deletions keyhunt.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct tothread {
char *rpt; //rng per thread
};

const char *version = "0.1.20201222";
const char *version = "0.1.20201223";
const char *EC_constant_N = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141";
const char *EC_constant_P = "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f";
const char *EC_constant_Gx = "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798";
Expand Down Expand Up @@ -100,6 +100,7 @@ int FLAGVANITY = 0;
int FLAGMODE = 1;
int FLAGCRYPTO = 0;
int FLAGALREADYSORTED = 0;
int FLAGRAWDATA = 0;

int len_vanity;
int bitrange;
Expand Down Expand Up @@ -128,7 +129,7 @@ int main(int argc, char **argv) {
mpz_init_set_str(EC.n, EC_constant_N, 16);
mpz_init_set_str(G.x , EC_constant_Gx, 16);
mpz_init_set_str(G.y , EC_constant_Gy, 16);
while ((c = getopt (argc, argv, "ehRb:c:f:g:m:n:r:s:t:v:")) != -1) {
while ((c = getopt (argc, argv, "ehRwb:c:f:g:m:n:r:s:t:v:")) != -1) {
switch(c) {
case 'h':
FLAGHELP = 1;
Expand All @@ -140,16 +141,17 @@ int main(int argc, char **argv) {
printf("\t\teth option is under develop sorry :(\n");
printf("-e\t\tThe file is already Sorted descendent. This skip the sorting process.\n");
printf("\t\tYour file MUST be sordted if no you are going to lose collisions\n");
printf("-f filename\tSpecify filename with addresses or xpoint\n");
printf("-g debugcount\tJust for the stats, mark as counted every debugcount keys \n");
printf("-f file\tSpecify filename with addresses or xpoint\n");
printf("-g count\tJust for the stats, mark as counted every debugcount keys \n");
printf("-m mode\t\tmode of search for cryptos. < xpoint , address > default: address (more slow)\n");
printf("-n uptoN\tCheck for N secuential numbers before the random chossen this only work with -R option\n");
//printf("-o file\t\tSet the file to sav\n");
printf("-r SR:EN\tStarRange:EndRange, the end range can be omited for search from start range to N-1 ECC value\n");
printf("-R\t\tRandom/Secuential this is the default behaivor, can't use this with range option -r\n");
printf("-s ns\t\tNumber of seconds for the stats output, 0 to omit output.\n");
printf("-t tn\t\tThreads number, must be positive integer\n\n");
printf("-t tn\t\tThreads number, must be positive integer\n");
printf("-v va\t\tSearch for vanity Address, only with -m address\n");
printf("-w\t\tMark the input file as RAW data xpoint fixed 32 byte each point. Valid only with -m xpoint\n");
printf("\t\tUse the hexcharstoraw tool to create a raw file from your current hexadecimal file\n");
printf("\nExample\n\n");
printf("%s -t 16 -r 00000001:FFFFFFFF -s 0\n\n",argv[0]);
printf("This line run the program with 16 threads from the range 00000001 to FFFFFFFF without stats output\n\n");
Expand Down Expand Up @@ -296,6 +298,9 @@ int main(int argc, char **argv) {
NTHREADS = 1;
}
printf((NTHREADS > 1) ? "Setting %u threads\n": "Setting %u thread\n",NTHREADS);
break;
case 'w':
FLAGRAWDATA = 1;
break;
default:
printf("Unknow opcion %c\n",c);
Expand Down Expand Up @@ -354,24 +359,35 @@ int main(int argc, char **argv) {
exit(0);
}
N =0;
aux = malloc(1000);
while(!feof(fd)) {
hextemp = fgets(aux,1000,fd);
if(hextemp == aux) {
trim(aux," \t\n\r");
//printf("reading %s\n",aux);
r = strlen(aux);
if(r > 10) { //Any length for invalid Address?
if(r > MAXLENGTHADDRESS) {
MAXLENGTHADDRESS = r;
}
N++;
}
if(FLAGRAWDATA) {
aux = malloc(32);
while(!feof(fd)) {
if(fread(aux,1,32,fd) == 32) {
N++;
}
}
}
free(aux);
free(aux);
}
else {
aux = malloc(1000);
while(!feof(fd)) {
hextemp = fgets(aux,1000,fd);
if(hextemp == aux) {
trim(aux," \t\n\r");
//printf("reading %s\n",aux);
r = strlen(aux);
if(r > 10) { //Any length for invalid Address?
if(r > MAXLENGTHADDRESS) {
MAXLENGTHADDRESS = r;
}
N++;
}
}
}
free(aux);
}
fseek(fd,0,SEEK_SET);
if(FLAGMODE == 0) {
if(FLAGMODE == 0 || FLAGRAWDATA) {
MAXLENGTHADDRESS = 32;
}
do {
Expand Down Expand Up @@ -412,49 +428,60 @@ int main(int argc, char **argv) {
}
}
else {
aux = malloc(3*MAXLENGTHADDRESS);
while(i < N) {
memset(aux,0,3*MAXLENGTHADDRESS);
hextemp = fgets(aux,3*MAXLENGTHADDRESS,fd);
if(hextemp == aux) {
trim(aux," \t\n\r");
lenaux = strlen(aux);
memset(DATABUFFER + (i*MAXLENGTHADDRESS),0,MAXLENGTHADDRESS);
if(isValidHex(aux)) {
if(lenaux <= 64) {
if(lenaux < 64) {
aux2 = calloc(3*MAXLENGTHADDRESS,1);
lendiff = 64 - lenaux;
memcpy(aux2+lendiff,aux,lenaux);
memset(aux2,'0',lendiff);
memcpy(aux,aux2,3*MAXLENGTHADDRESS);
free(aux2);
}
if(hexs2bin(aux,DATABUFFER + (i*MAXLENGTHADDRESS))) {
bloom_add(&bloom, DATABUFFER + (i*MAXLENGTHADDRESS),MAXLENGTHADDRESS);
if(FLAGRAWDATA) {
aux = malloc(MAXLENGTHADDRESS);
while(i < N) {
if(fread(aux,1,MAXLENGTHADDRESS,fd) == 32) {
memcpy(DATABUFFER + (i*MAXLENGTHADDRESS),aux,MAXLENGTHADDRESS);
bloom_add(&bloom, aux,MAXLENGTHADDRESS);
}
i++;
}
}
else {
aux = malloc(3*MAXLENGTHADDRESS);
while(i < N) {
memset(aux,0,3*MAXLENGTHADDRESS);
hextemp = fgets(aux,3*MAXLENGTHADDRESS,fd);
if(hextemp == aux) {
trim(aux," \t\n\r");
lenaux = strlen(aux);
memset(DATABUFFER + (i*MAXLENGTHADDRESS),0,MAXLENGTHADDRESS);
if(isValidHex(aux)) {
if(lenaux <= 64) {
if(lenaux < 64) {
aux2 = calloc(3*MAXLENGTHADDRESS,1);
lendiff = 64 - lenaux;
memcpy(aux2+lendiff,aux,lenaux);
memset(aux2,'0',lendiff);
memcpy(aux,aux2,3*MAXLENGTHADDRESS);
free(aux2);
}
if(hexs2bin(aux,DATABUFFER + (i*MAXLENGTHADDRESS))) {
bloom_add(&bloom, DATABUFFER + (i*MAXLENGTHADDRESS),MAXLENGTHADDRESS);
}
else {
printf("error hexs2bin\n");
}
}
else {
printf("error hexs2bin\n");
printf("Omiting line : %s\n",aux);
}
}
else {
printf("Omiting line : %s\n",aux);
}
}
else {
printf("Ignoring invalid hexvalue %s\nAre you sure that your file are X points?",aux);
}
i++;
}
else {
printf("Omiting line : %s\n",aux);
}
}
}
else {
printf("Ignoring invalid hexvalue %s\nAre you sure that your file are X points?",aux);
}
i++;
}
else {
printf("Omiting line : %s\n",aux);
}
}
}
}
free(aux);
fclose(fd);
printf("bloomfilter completed\n");

if(FLAGALREADYSORTED) {
printf("File mark already sorted, skipping sort proccess\n");
printf("%i values were loaded\n",N);
Expand All @@ -465,7 +492,6 @@ int main(int argc, char **argv) {
printf("%i values were loaded and sorted\n",N);
}


init_doublingG(&G);

if(FLAGRANGE == 0) {
Expand Down Expand Up @@ -1221,6 +1247,7 @@ int partition (char *arr, int low, int high) {
void quicksort(char *arr, int low, int high) {
int pi;
if (low < high) {
//printf("quicksort from %i to %i\n",low,high);
pi = partition(arr, low, high);
quicksort(arr, low, pi - 1);
quicksort(arr, pi + 1, high);
Expand Down

0 comments on commit ab292a0

Please sign in to comment.