Guest User

Untitled

a guest
Dec 13th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. Algorithm:
  2.  
  3. 1. Start
  4. 2. Take the String from the user.
  5. 3. Create index, set index = 0 (Start position of string)
  6. 4. Create length Counter set lc = 1 (length of Substring)
  7. 5. While index < length of Password
  8. 6. While (lc+index) < length of Password
  9. 7. check if consequtive substrings of length lc are equal.
  10. 8. If yes print REJECTED and return from main. (exit)
  11. 9. Else, increment lc
  12. 10. Increment index
  13. 11. Print ACCEPTED (loops are done, the string is fine because it was not rejected)
  14. 12. Exit
  15.  
  16. Program:
  17.  
  18. #include<stdio.h>
  19. #include<conio.h>
  20. #include<string.h>
  21. char temp[10];
  22. const char *substr(int i,int j,char *pass)
  23. {
  24. int k=0;
  25. temp[0] = '\0';
  26. while(k<j)
  27. {
  28. temp[k] = pass[i];
  29. i++;
  30. k++;
  31. }
  32. temp[k] = '\0';
  33. return(temp);
  34. }
  35. void main()
  36. {
  37. int index,lc,plen;
  38. char password[10],temp_pass1[10],temp_pass2[10];
  39. printf("\n Enter Your Password: ");
  40. scanf("%s",password);
  41. plen = strlen(password);
  42. for(index = 0;index<plen; index++)
  43. {
  44. for(lc = 1;(lc+index)<plen;lc++)
  45. {
  46. strcpy(temp_pass1,substr(index,lc,password));
  47. strcpy(temp_pass2,substr(index+lc,lc,password));
  48.  
  49. if(strcmp(temp_pass1,temp_pass2) == 0)
  50. {
  51. printf("\n Rejected: %s %s",temp_pass1,temp_pass2);
  52. getch();
  53. return;
  54. }else
  55. continue;
  56. }
  57. }
  58. printf("\n Accepted");
  59. getch();
  60. }
Add Comment
Please, Sign In to add comment