Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Algorithm:
- 1. Start
- 2. Take the String from the user.
- 3. Create index, set index = 0 (Start position of string)
- 4. Create length Counter set lc = 1 (length of Substring)
- 5. While index < length of Password
- 6. While (lc+index) < length of Password
- 7. check if consequtive substrings of length lc are equal.
- 8. If yes print REJECTED and return from main. (exit)
- 9. Else, increment lc
- 10. Increment index
- 11. Print ACCEPTED (loops are done, the string is fine because it was not rejected)
- 12. Exit
- Program:
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- char temp[10];
- const char *substr(int i,int j,char *pass)
- {
- int k=0;
- temp[0] = '\0';
- while(k<j)
- {
- temp[k] = pass[i];
- i++;
- k++;
- }
- temp[k] = '\0';
- return(temp);
- }
- void main()
- {
- int index,lc,plen;
- char password[10],temp_pass1[10],temp_pass2[10];
- printf("\n Enter Your Password: ");
- scanf("%s",password);
- plen = strlen(password);
- for(index = 0;index<plen; index++)
- {
- for(lc = 1;(lc+index)<plen;lc++)
- {
- strcpy(temp_pass1,substr(index,lc,password));
- strcpy(temp_pass2,substr(index+lc,lc,password));
- if(strcmp(temp_pass1,temp_pass2) == 0)
- {
- printf("\n Rejected: %s %s",temp_pass1,temp_pass2);
- getch();
- return;
- }else
- continue;
- }
- }
- printf("\n Accepted");
- getch();
- }
Add Comment
Please, Sign In to add comment