Exemple #1
0
        public async void WaitForCommand(string[] args = null)
        {
            try
            {
                List <string> cmdlets;
                if (args == null || args.Length == 0)
                {
                    var cmd = Ask();
                    if (cmd == null)
                    {
                        return;
                    }

                    cmdlets = new List <string>(cmd.Split(' '));
                }
                else
                {
                    cmdlets = new List <string>(args);
                }

                Jector jector;

                var type = GetJectorType(cmdlets[0]);

                //make the jector:
                var jectorBuilder = new JectorBuilder().WithType(type);

                var response = Ask("Do you want to ensure a successful write?", true);

                //if (response == null) return;

                if (response == "y")
                {
                    jectorBuilder.WithRequiredSuccess();
                }

                response = Ask("Do you want to use the default end of file marker?", true);
                //if (response == null) return;

                if (response == "n")
                {
                    response = Ask("What end of file marker would you like to use?", false, true);
                    //if (response == null) return;

                    jectorBuilder.WithEOF(response);
                }

                jector = jectorBuilder.Build();

                if (cmdlets[1].ToLower() == "inject")
                {
                    await Inject(jector);
                }
                else if (cmdlets[1].ToLower() == "eject")
                {
                    await Eject(jector);
                }

                Aretha.SoulSucceeded(Soul.Anubis);
            }
            catch (Exception ex)
            {
                Aretha.SoulFailed(Soul.Anubis, ex);
                return;
            }
        }
Exemple #2
0
        public async void WaitForCommand(string[] args = null)
        {
            List <string> cmdlets;

            string cmd;

            if (args == null || args.Length == 0)
            {
                cmd = Ask();
                if (cmd == null)
                {
                    return;
                }

                cmdlets = new List <string>(cmd.Split(' '));
            }
            else
            {
                cmdlets = new List <string>(args);
                StringBuilder sb = new();

                for (int i = 0; i < cmdlets.Count; i++)
                {
                    sb.Append(cmdlets[i]);

                    if (i != cmdlets.Count - 1)
                    {
                        sb.Append(' ');
                    }
                }

                cmd = sb.ToString();
            }

            while (true)
            {
                try
                {
                    if (cmdlets[0] == "back")
                    {
                        Aretha.SoulSucceeded(Soul.Horus);
                        return;
                    }
                    else if (cmdlets[0] == "use")
                    {
                        switch (cmdlets[1])
                        {
                        case "vigenere":
                        case "caesar":
                        case "playfair":
                            await new HorusClassical().OnSession(cmdlets[1]);
                            break;

                        case "crypto-file":
                            await new HorusFile().OnSession();
                            break;

                        case "crypto-container":
                            await new HorusContainer().OnSession();
                            break;

                        case "enigma-machine":
                            await new HorusEnigma().OnSession();
                            break;

                        default:
                            throw new InvalidOperationException("Unknown operation");
                        }
                    }
                    else if (cmdlets[0] == "hash")
                    {
                        var input = Ask(isCase: true);
                        Speak(Horus.Horus.GetHash(input));
                    }
                    else if (cmdlets[0] == "id")
                    {
                        if (cmdlets.Count == 1)
                        {
                            Speak(Horus.Horus.GenerateId(IdKind.Guid));
                        }
                        else
                        {
                            int max = 12;
                            if (cmdlets.Count > 2)
                            {
                                if (!int.TryParse(cmdlets[2], out max))
                                {
                                    throw new InvalidOperationException("Value for length must be number");
                                }
                            }

                            IdKind kind = cmdlets[1] switch
                            {
                                "standard" => IdKind.Standard,
                                "date-time" => IdKind.DateTime,
                                "guid" => IdKind.Guid,
                                "random" => IdKind.Random,
                                "hash" => IdKind.Hash,
                                _ => throw new InvalidOperationException("Unkown ID Kind")
                            };

                            Speak(Horus.Horus.GenerateId(kind, max));
                        }
                    }

                    cmdlets = new List <string>(Ask().Split(' '));
                }
                catch (Exception ex)
                {
                    Aretha.SoulFailed(Soul.Horus, ex);
                    return;
                }
            }
        }