Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <glib.h>
- #include <string.h>
- #include <math.h>
- typedef struct pax {
- char** arr;
- } arrpack;
- char* concat(const char *s1, const char *s2)
- {
- char *result = malloc(strlen(s1) + strlen(s2) + 1);
- strcpy(result, s1);
- strcat(result, s2);
- return result;
- }
- void printAllKLengthRec(arrpack* packer, char set[], char prefix[],
- int n, int k, int* counter)
- {
- if (k == 0)
- {
- int cnt = *counter;
- strcpy(packer->arr[cnt], prefix);
- *counter = *counter + 1;
- return;
- }
- for (int i = 0; i < n; i++)
- {
- char str2[2];
- str2[0] = set[i];
- str2[1] = '\0';
- char* newPrefix = concat(prefix, str2);
- printAllKLengthRec(packer, set, newPrefix, n, k - 1, counter);
- }
- }
- void printAllKLength(arrpack* packer, char set[], int k,int n)
- {
- int counter = 0;
- printAllKLengthRec(packer, set, "", n, k,&counter);
- }
- int main(void)
- {
- char set[52];
- for(int i=0;i<52;i++) {
- if(i<26)
- set[i] = i+'a';
- else
- set[i] = i-26+'A';
- }
- int n=52;
- int k=5;
- arrpack packer;
- size_t combinations = pow(n,k);
- packer.arr = (char **)malloc(combinations*sizeof(char*));
- for (int i=0; i<combinations; i++)
- packer.arr[i] = (char *)malloc(k+1);
- printAllKLength(&packer, set, k, n);
- for(int i=0;i<combinations;i++) {
- packer.arr[i];
- gchar *sha512;
- sha512 = g_compute_checksum_for_string(G_CHECKSUM_SHA512, packer.arr[i], k);
- printf("%s",packer.arr[i]);
- g_free(sha512);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement