Advertisement
alexbancheva

PasswordReset_04April2020

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