Recently, while reviewing some of the file handling
concepts, an interesting thing clicked my mind, that what if I enter jumbled up
alphabets, and a C program can give me all the possible meaningful words.
Really, this thing sounds awesome. So right at that moment I hanged up my mind,
trying to get solution to this problem. I also stuck on to this problem, as a
mischievous thought came in my mind that during some baby-step hacking of
social engineering, how-so-ever if you manage to get the alphabets involved in
your friend’s facebook password (but not the actual sequence of the alphabets)
then you can easily get the actual password, through this C program, provided
you have a versatile pass-list.
In my source code, I have extensively used file handling
concepts of C. The concept I have used is very easy to understand, I have
not at all involved any major complexity regarding algorithm, except the
function definition, which I used just to compare two strings, although you
could have accomplished this task using pre-defined functions in string.h
header file, but defining your own function is a better option, and it will
also build up your algorithm development capabilities.
I just prompted the user to enter a string, which is
actually the jumbled up characters, and scanned a string from my text file that
contains all the English words, then I compared length of both the strings, and
if both the strings have equal length, then I called the function to compare
the strings. If the strings are identical then I used fprintf
function to again write the correct meaningful English word to another text
file. I repeated this process till I reached the end-of-file which I used to
scan English words. And simply we are done with our job.
SOURCE CODE :-
/***************************************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
int fun(char*,char*);
int main()
{
FILE*p1,*p2;
int
flag=0;
char
name1[130],name2[130];
clrscr();
p1=fopen("d:/c/a.txt","r");
/*a.txt
is a file that contains all the meaningful English words*/
p2=fopen("d:/c/b.txt","w");
/*b.txt is a file that will
contains the English words that can possibly be formed using jumbled characters
entered by user*/
rewind(p1);
rewind(p2);
if(p1&&p2)
{
printf("ENTER
JUMBLED WORDS IN LOWER CASE : ");
scanf("%s",name2);
while(!feof(p1))
{
flag=0;
printf("searching...\n");
fscanf(p1,"%s",name1);
if(strlen(name1)==strlen(name2))
{
flag=fun(name1,name2);
}
if(flag)
{
fprintf(p2,"%s\n",name1);
}
}
}
else
{
printf("FILE
OPERATION WAS UNSUCCESSFUL");
}
getch();
return
1;
}
int fun(char name1[130],char name2[130])
{
int
i,length=strlen(name1),count=0,j,k;
char
temp;
for(i=0,j=length-1;i<length;i++)
{
for(k=0;k<=j;k++)
{
if((name1[i]==name2[k])&&j>=0)
{
count++;
temp=name2[k];
name2[k]=name2[j];
name2[j]=temp;
j--;
break;
}
}
}
if(count==length)
{
printf("%s\n",name1);
return
1;
}
else
{
return
0;
}
}
/*******************************************************************************************/