TheBulgarianWolf

Treasure Finder

Mar 25th, 2021
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace TreasureFinder
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.            
  13.             Console.WriteLine("Enter your decryption key: ");
  14.             int[] key = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  15.  
  16.             string mes;
  17.             while ((mes = Console.ReadLine()) != "find")
  18.             {
  19.                 StringBuilder message = new StringBuilder();
  20.  
  21.                 for (int i = 0; i < mes.Length; i++)
  22.                 {
  23.                     message.Append(Convert.ToChar(mes[i] - key[i % key.Length]));
  24.                 }
  25.  
  26.                 string messageAsStr = message.ToString();
  27.  
  28.                 int startIndexOfTreasure = messageAsStr.IndexOf("&") + 1;
  29.                 int treasureLength = messageAsStr.LastIndexOf("&") - startIndexOfTreasure;
  30.  
  31.                 string treasure = messageAsStr.Substring(startIndexOfTreasure, treasureLength);
  32.  
  33.                 int startIndexOfCoordinates = messageAsStr.IndexOf("<") + 1;
  34.                 int coordinatesLength = messageAsStr.IndexOf(">") - startIndexOfCoordinates;
  35.  
  36.                 string coordinates = messageAsStr.Substring(startIndexOfCoordinates, coordinatesLength);
  37.  
  38.                 Console.WriteLine($"Found {treasure} at {coordinates}");
  39.  
  40.                
  41.  
  42.             }
  43.  
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment