write a algorithm to reversethe required elements of password to get the actual password,so that file can be opened
#include <stdio.h>
#include <string.h>
void generatePermutation(char * , int , int );
int main() {
char str[] = "password"; // your characters
int n = strlen(str);
printf("All the permutations of the string are: \n");
generatePermutation(str,0,n);
return 0;
}
void generatePermutation(char *str, const int start, int end) {
char temp;
for(int i = start; i < end-1; ++i){
for(int j = i+1; j < end; ++j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
generatePermutation(str , i+1 ,end);
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
printf("%s\n",str);
}
Comments
Leave a comment