Exemplo n.º 1
0
    private string Translate(string inputString, TranlateDirection translateDirection)
    {
        int[] explandedNumericKey = SetLengthOfNumericKey(inputString, NumericKey);

        int[] inputNumeric = GetIntsFromString(inputString);

        int[] translatedNumeric = ApplyKey(inputNumeric, explandedNumericKey, translateDirection);

        return(GetStringFromInts(translatedNumeric));
    }
Exemplo n.º 2
0
    private int[] ApplyKey(int[] message, int[] key, TranlateDirection translateDirection)
    {
        int multiplier =
            translateDirection == TranlateDirection.Encode
            ? 1
            : -1;

        return(Enumerable.Range(0, message.Length)
               .Select(i => message[i] + (multiplier * key[i]))
               .ToArray());
    }