public static CalculationResult StartCalculations(string input, MonoAlphabet alpha, EncoderType encoderType, CodingType codingType, out IMonoAlphabet monoAlphabet) { var result = Empty; var alphabetInfo = ""; if (alpha == MonoAlphabet.Auto) { var autoDetected = Alphabet.DetectMonoFromString(input); alphabetInfo = $"За вхідним повідомленням визначено алфавіт: " + $"{MonoAlphabets.GetName(autoDetected.Item2)}"; monoAlphabet = autoDetected.Item1; } else { alphabetInfo = $"Задано алфавіт: {MonoAlphabets.GetName(alpha)}"; monoAlphabet = Alphabet.GetMono(alpha); } result.CalculationsPipeline.AddRange(new string[] { " -- ", "Початок обчислень...", $"Тип шифрування: {EncodingTypes.GetName(encoderType)}", $"Тип операції: {CodingTypes.GetName(codingType)}", alphabetInfo, $"Повідомлення: {input}" }); return(result); }
public Tuple <AnswerType, string> CheckAnswer( IQuestion currentQuestion, MonoAlphabet mono, PolyAlphabet poly, params object[] args) { IAlphabetEncoder encoder = EncoderFactory .CreateEncoder(currentQuestion.EncodingType) .SetMonoAlphabet(Alphabet.GetMono(mono)) .Configure(args); string answer = String.Empty; switch (currentQuestion.CodingType) { case CodingType.Decoding: answer = encoder.Decode(currentQuestion.Description.Description); if (currentQuestion.Answer.Answer.ToLower() .Equals(answer.ToLower())) { return(new Tuple <AnswerType, string> (AnswerType.Correct, answer)); } break; case CodingType.Encoding: answer = encoder.Encode(currentQuestion.Description.Description); if (currentQuestion.Answer.Answer.ToLower() .Equals(answer.ToLower())) { return(new Tuple <AnswerType, string> (AnswerType.Correct, answer)); } break; } return(new Tuple <AnswerType, string> (AnswerType.NotCorrect, answer)); }
public TrithemiusCalculator SetAlphabet(MonoAlphabet alphabet) { _monoAlphabet = alphabet; return(this); }
public CaesarCalculator SetAlphabet(MonoAlphabet alphabet) { _monoAlphabet = alphabet; return(this); }
public static string GetName(MonoAlphabet type) => _data[type];
public static IMonoAlphabet GetMono(MonoAlphabet alphabetType) => _alphabets[alphabetType];