Skip to content

Instantly share code, notes, and snippets.

@pazdera
Created August 3, 2011 17:54
Show Gist options
  • Select an option

  • Save pazdera/1123306 to your computer and use it in GitHub Desktop.

Select an option

Save pazdera/1123306 to your computer and use it in GitHub Desktop.

Revisions

  1. pazdera revised this gist Aug 18, 2011. 1 changed file with 16 additions and 16 deletions.
    32 changes: 16 additions & 16 deletions brute_force_string.c
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,20 @@
    /*
    * Basic string generation for brute-force attacks
    * Copyright (C) 2011 Radek Pazdera
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program. If not, see <http://www.gnu.org/licenses/>.
    */
    * Basic string generation for brute-force attacks
    * Copyright (C) 2011 Radek Pazdera
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program. If not, see <http://www.gnu.org/licenses/>.
    */

    #include <string.h>
    #include <stdio.h>
  2. pazdera revised this gist Aug 18, 2011. 1 changed file with 66 additions and 34 deletions.
    100 changes: 66 additions & 34 deletions brute_force_string.c
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,20 @@
    /*
    * Basic string generation for brute-force attacks
    * Copyright (C) 2011 Radek Pazdera
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program. If not, see <http://www.gnu.org/licenses/>.
    */
    * Basic string generation for brute-force attacks
    * Copyright (C) 2011 Radek Pazdera
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program. If not, see <http://www.gnu.org/licenses/>.
    */

    #include <string.h>
    #include <stdio.h>
    @@ -37,6 +37,46 @@ struct charlist
    charlist_t* next;
    };

    /* Return new initialized charlist_t element.
    *
    * Elements are initialized
    * @return charlist_t
    */
    charlist_t* new_charlist_element()
    {
    charlist_t* element;

    if ((element = malloc(sizeof(charlist_t))) != 0)
    {
    element->character = 0;
    element->next = NULL;
    }
    else
    {
    perror("malloc() failed.");
    }

    return element;
    }

    /* Free memory allocated by charlist.
    *
    * @param list Pointer at the first element.
    * @return void
    */
    void free_charlist(charlist_t* list)
    {
    charlist_t* current = list;
    charlist_t* next;

    while (current != NULL)
    {
    next = current->next;
    free(current);
    current = next;
    }
    }

    /* Print the charlist_t data structure.
    *
    * Iterates through the whole list and prints all characters
    @@ -58,8 +98,8 @@ void print_charlist(charlist_t* list)

    /* Get next character sequence.
    *
    * It treat characters as numbers (0-255). It tries to increment
    * character at the first position. If it fails, new character is
    * It treats characters as numbers (0-255). Function tries to increment
    * character in the first position. If it fails, new character is
    * added to the back of the list.
    *
    * It's basicaly a number with base = 256.
    @@ -69,39 +109,31 @@ void print_charlist(charlist_t* list)
    */
    void next(charlist_t* list)
    {
    if (list->next == NULL)
    list->character++;
    if (list->character == 0)
    {
    if ((list->next = malloc(sizeof(charlist_t))) != 0)
    if (list->next == NULL)
    {
    list->next->character = 0;
    list->next->next = NULL;
    list->next = new_charlist_element();
    }
    else
    {
    perror("malloc() fail");
    }
    }
    else
    {
    list->character++;
    if (list->character == 0)
    {
    list->character++;
    next(list->next);
    }
    }
    }

    int main()
    {
    charlist_t* sequence = malloc(sizeof(charlist_t));
    sequence->character = 0;
    sequence->next = NULL;
    charlist_t* sequence;
    sequence = new_charlist_element();

    while (1)
    {
    next(sequence);
    print_charlist(sequence);
    }

    free_charlist(sequence);
    }

  3. pazdera revised this gist Aug 4, 2011. 1 changed file with 16 additions and 16 deletions.
    32 changes: 16 additions & 16 deletions brute_force_string.c
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,20 @@
    /*
    * Basic string generation for brute-force attacks
    * Copyright (C) 2011 Radek Pazdera
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program. If not, see <http://www.gnu.org/licenses/>.
    */
    * Basic string generation for brute-force attacks
    * Copyright (C) 2011 Radek Pazdera
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program. If not, see <http://www.gnu.org/licenses/>.
    */

    #include <string.h>
    #include <stdio.h>
  4. pazdera created this gist Aug 3, 2011.
    107 changes: 107 additions & 0 deletions brute_force_string.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,107 @@
    /*
    * Basic string generation for brute-force attacks
    * Copyright (C) 2011 Radek Pazdera
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program. If not, see <http://www.gnu.org/licenses/>.
    */

    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>

    /* I chose to use an one way linked list data structure
    * to avoid restrictions on the generated string length.
    * The thing is, the list must be converted to string so
    * it could be used. This conversion have to happen in
    * each cycle and causes unnecessary slowdown.
    *
    * Faster solution would be to implement the generation
    * directly on some staticaly allocated string with fixed
    * size (20 characters are more than enough).
    */
    typedef struct charlist charlist_t;
    struct charlist
    {
    unsigned char character;
    charlist_t* next;
    };

    /* Print the charlist_t data structure.
    *
    * Iterates through the whole list and prints all characters
    * in the list including any '\0'.
    *
    * @param list Input list of characters.
    * @return void
    */
    void print_charlist(charlist_t* list)
    {
    charlist_t* next = list;
    while (next != NULL)
    {
    printf("%d ", next->character);
    next = next->next;
    }
    printf("\n");
    }

    /* Get next character sequence.
    *
    * It treat characters as numbers (0-255). It tries to increment
    * character at the first position. If it fails, new character is
    * added to the back of the list.
    *
    * It's basicaly a number with base = 256.
    *
    * @param list A pointer to charlist_t.
    * @return void
    */
    void next(charlist_t* list)
    {
    if (list->next == NULL)
    {
    if ((list->next = malloc(sizeof(charlist_t))) != 0)
    {
    list->next->character = 0;
    list->next->next = NULL;
    }
    else
    {
    perror("malloc() fail");
    }
    }
    else
    {
    list->character++;
    if (list->character == 0)
    {
    list->character++;
    next(list->next);
    }
    }
    }

    int main()
    {
    charlist_t* sequence = malloc(sizeof(charlist_t));
    sequence->character = 0;
    sequence->next = NULL;

    while (1)
    {
    next(sequence);
    print_charlist(sequence);
    }
    }