Advertisement
Guest User

Untitled

a guest
May 29th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int inc(char *c){
  5. if(c[0]==0) return 0;
  6. if(c[0]=='z'){
  7. c[0]='a';
  8. return inc(c+sizeof(char));
  9. }
  10. c[0]++;
  11. return 1;
  12. }
  13.  
  14. int main(void){
  15. // int n = 3;
  16. // int i,j;
  17. //char *c = (char*)malloc(n+sizeof(char));
  18. // for(i=1;i<=n;i++){
  19. // for(j=0;j<i;j++){
  20. // c[j]='a';
  21. // }
  22. // c[i]=0;
  23. // do {
  24. // printf("%s\n",c);
  25. // } while(inc(c));
  26. // }
  27. // free(c);
  28. int n=3, numberOfNodes = 3, nodeNumber=1;
  29. char *c = (char*)malloc(n+sizeof(char));
  30. char *givenCharSet = {"abc"};
  31. int charSetLength = 0;
  32. int i,j,startingPoint,schrittWeite, incrementPoint;
  33.  
  34. //get length of given input charset
  35. for(i=0;givenCharSet[i]!='\0';i++);
  36. charSetLength = i;
  37.  
  38. //find out where to start brute-forcing from
  39. startingPoint = charSetLength / numberOfNodes * nodeNumber;
  40. schrittWeite = charSetLength / numberOfNodes;
  41.  
  42. //create string to start incrementing from
  43. for(i=0;i < n; i++){
  44. if(i==0){
  45. c[i] = givenCharSet[startingPoint];
  46. continue;
  47. }
  48. c[i] = givenCharSet[0];
  49. }
  50. c[n]='\0';
  51.  
  52. //start brute force
  53. incrementPoint = n - 1;
  54. do{
  55. for(incrementPoint = n-1;incrementPoint >=0;incrementPoint--){
  56. for(j=0;j < charSetLength;j++){
  57. c[incrementPoint] = givenCharSet[j];
  58. printf("%s\n",c);
  59. }
  60. }
  61. }
  62. while(c[0] != givenCharSet[startingPoint+schrittWeite]);
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement