petarkobakov

Reset password

Jul 29th, 2020 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace Password_Reset
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string password = Console.ReadLine();
  11. string [] command = Console.ReadLine().Split();
  12. string operation = command[0];
  13.  
  14. while (operation != "Done")
  15. {
  16. if (operation == "TakeOdd")
  17. {
  18. StringBuilder rawPassword = new StringBuilder();
  19.  
  20. for (int i = 1; i < password.Length; i += 2)
  21. {
  22. rawPassword = rawPassword.Append(password[i]);
  23. }
  24.  
  25. password = rawPassword.ToString();
  26. Console.WriteLine(password);
  27. }
  28. else if (operation == "Cut")
  29. {
  30. int index = int.Parse(command[1]);
  31. int length = int.Parse(command[2]);
  32. int test = index + length;
  33.  
  34. if (test<=password.Length)
  35. {
  36. string substr = password.Substring(index, length);
  37. int subIndex = password.IndexOf(substr);
  38. password = password.Remove(subIndex, substr.Length);
  39. Console.WriteLine(password);
  40. }
  41.  
  42. }
  43.  
  44. else if (operation == "Substitute")
  45. {
  46.  
  47. string substring = command[1];
  48. string substitude = command[2];
  49.  
  50. if (password.Contains(substring))
  51. {
  52. password = password.Replace(substring,substitude);
  53.  
  54. Console.WriteLine(password);
  55. }
  56. else
  57. {
  58. Console.WriteLine("Nothing to replace!");
  59. break;
  60. }
  61.  
  62. }
  63.  
  64. command = Console.ReadLine().Split();
  65. operation = command[0];
  66. }
  67.  
  68. Console.WriteLine("Your password is: " + password);
  69.  
  70.  
  71. }
  72. }
  73. }
  74.  
Add Comment
Please, Sign In to add comment