public void SuccessAdditionTest()
        {
            int additionNumber         = 123;
            FiniteRingElement addition = ring.GetElement(additionNumber);

            Assert.That((elem + addition).Value, Is.EqualTo(20));
        }
        public void NonEqualRingsAdditionTest()
        {
            FiniteRing        otherRing = new FiniteRing(order + 1);
            FiniteRingElement addition  = otherRing.GetElement(15);

            FiniteRingElement result = elem + addition;
        }
Esempio n. 3
0
        public Key generateKeyByLength(long length)
        {
            if (length < 1)
            {
                throw new ArgumentException("Key length must be greater than 0");
            }

            FiniteRingElement[] result = new FiniteRingElement[length];

            long i = 0, l;

            //Fill with repeats
            for (i = 0, l = (long)(length / sequence.LongLength); i < l; ++i)
            {
                for (long j = 0; j < sequence.LongLength; ++j)
                {
                    result[i * sequence.LongLength + j] = sequence[j];
                }
            }

            //Fill remainder
            for (long j = i * sequence.LongLength, k = 0; j < length; ++j, ++k)
            {
                result[j] = sequence[k];
            }

            return(new Key(ring, result));
        }
Esempio n. 4
0
        private FiniteRingElement[] EncodeDigitalRecord(FiniteRingElement[] code, Key key)
        {
            FiniteRingElement[] result = new FiniteRingElement[code.LongLength];
            Key neededKey = key.generateKeyByLength(code.LongLength);

            for (long i = 0, l = code.LongLength; i < l; ++i)
            {
                result[i] = code[i] - neededKey[i];
            }
            return(result);
        }
Esempio n. 5
0
        public void generateKeyByLengthTest()
        {
            int expectedKeyLength = 15;

            FiniteRingElement[] expectedSequence = new FiniteRingElement[expectedKeyLength];

            for (int i = 0; i < expectedKeyLength; ++i)
            {
                expectedSequence[i] = initialSequence[i];
            }

            Assert.That((new Key(ring, initialSequence)).generateKeyByLength(expectedKeyLength),
                        Is.EqualTo(new Key(ring, expectedSequence)));
        }
Esempio n. 6
0
        public char GetLetterByOrder(FiniteRingElement order)
        {
            if (!ring.Contains(order))
            {
                throw new ArgumentOutOfRangeException();
            }

            foreach (KeyValuePair <char, FiniteRingElement> letter in alphabet)
            {
                if (letter.Value.Equals(order))
                {
                    return(letter.Key);
                }
            }

            throw new ArgumentOutOfRangeException();
        }
        public void Analyze(ILogger logger)
        {
            List <KeyValuePair <char, long> > occurrences = GetOftenLetters();
            //List<KeyValuePair<char, long>> template = GetOftenLettersTemplate();


            List <string>     log      = new List <string>();
            FiniteRingElement distance = null;

            log.Add(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            for (int i = 0, l = occurrences.Count; i < l; ++i)
            {
                //distance = FiniteRingElement.Distance(Alphabet.Russian.GetLetterOrder(occurrences[i].Key), Alphabet.Russian.GetLetterOrder(template[i].Key));
                log.Add("Letter " + occurrences[i].Key + " occurrs " + occurrences[i].Value + " times." /* + " Distance form " + template[i].Key + " is " + distance.Value + " means letter " + Alphabet.Russian.GetLetterByOrder(distance)*/);
            }

            log.Add("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

            logger.Log(log);
        }
 public void setUp()
 {
     ring = new FiniteRing(order);
     elem = ring.GetElement(number);
 }