Advertisement
BerLonRazSof

PasswordReset_ExamApril2020_V2

Apr 5th, 2020
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace PasswordReset_ExamApril2020
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string password = Console.ReadLine();
  12.             StringBuilder newRawPassword = new StringBuilder();
  13.             while (true)
  14.             {
  15.                 string[] command = Console.ReadLine().Split();
  16.  
  17.                 if (command[0] == "Done")
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 if (command[0] == "TakeOdd")
  23.                 {
  24.  
  25.                     for (int i = 1; i < password.Length; i +=2)
  26.                     {
  27.                         newRawPassword.Append(password[i]);
  28.                     }
  29.  
  30.                     Console.WriteLine(newRawPassword);
  31.                 }
  32.                 else if (command[0] == "Cut")
  33.                 {
  34.                     string cut = newRawPassword.ToString().Substring(int.Parse(command[1]), int.Parse(command[2]));
  35.                     int index = newRawPassword.ToString().IndexOf(cut);
  36.                     newRawPassword = newRawPassword.Remove(index, cut.Length);
  37.                     Console.WriteLine(newRawPassword);
  38.                 }
  39.                 else if (command[0] == "Substitute")
  40.                 {
  41.                     if (newRawPassword.ToString().Contains(command[1]))
  42.                     {
  43.                         newRawPassword = newRawPassword.Replace(command[1], command[2]);
  44.                         Console.WriteLine(newRawPassword);
  45.                     }
  46.                     else
  47.                     {
  48.                         Console.WriteLine("Nothing to replace!");
  49.                     }
  50.                 }
  51.                    
  52.             }
  53.  
  54.             Console.WriteLine($"Your password is: {newRawPassword}");
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement