Ejemplo n.º 1
0
        public void ShouldEncryptDecryptBackToSameValue(string label, string alphabet, string word, BitString tweak, BitString key)
        {
            var wordNumeralString = NumeralString.ToNumeralString(word, alphabet);

            var encryptResult = _subject.ProcessPayload(new FfxModeBlockCipherParameters()
            {
                Direction = BlockCipherDirections.Encrypt,
                Iv        = tweak,
                Key       = key,
                Payload   = NumeralString.ToBitString(wordNumeralString),
                Radix     = alphabet.Length
            });

            var decryptResult = _subject.ProcessPayload(new FfxModeBlockCipherParameters()
            {
                Direction = BlockCipherDirections.Decrypt,
                Iv        = tweak,
                Key       = key,
                Payload   = encryptResult.Result,
                Radix     = alphabet.Length
            });

            Assert.AreEqual(
                NumeralString.ToAlphabetString(alphabet, alphabet.Length, wordNumeralString),
                NumeralString.ToAlphabetString(alphabet, alphabet.Length, NumeralString.ToNumeralString(decryptResult.Result))
                );
        }
Ejemplo n.º 2
0
        public void ShouldDecryptAlphabetStringsCorrectly(string label, string alphabet, string word, BitString tweak, BitString key, string expectedResult)
        {
            var wordNumeralString           = NumeralString.ToNumeralString(word, alphabet);
            var expectedResultNumeralString = NumeralString.ToNumeralString(expectedResult, alphabet);

            var result = _subject.ProcessPayload(new FfxModeBlockCipherParameters()
            {
                Direction = BlockCipherDirections.Decrypt,
                Iv        = tweak,
                Key       = key,
                Payload   = NumeralString.ToBitString(expectedResultNumeralString),
                Radix     = alphabet.Length
            });

            Assert.AreEqual(
                NumeralString.ToAlphabetString(alphabet, alphabet.Length, wordNumeralString),
                NumeralString.ToAlphabetString(alphabet, alphabet.Length, NumeralString.ToNumeralString(result.Result))
                );
        }
Ejemplo n.º 3
0
 public void ShouldToAlphabetString(string alphabet, int[] numbers, string expectation)
 {
     Assert.AreEqual(expectation, NumeralString.ToAlphabetString(alphabet, alphabet.Length, new NumeralString(numbers)));
 }