Пример #1
0
        public void Decode(Stream messageStream, string alphabet, StegoPermutationPresentation presentation, StegoPermutation stego)
        {
            Dictionary <T, ulong> string2index = new Dictionary <T, ulong>();

            ulong[] numList    = new ulong[source.Count];
            ulong[] numListInv = new ulong[source.Count];
            ulong[] values     = new ulong[source.Count];

            stego.ProgressChanged(10, 100);

            T[] sortedItems = sortItems(alphabet);

            for (int i = 0; i < sortedItems.Length; i++)
            {
                string2index[sortedItems[i]] = (ulong)i;
            }
            for (int i = 0; i < numList.Length; i++)
            {
                numList[i] = string2index[source[i]];
            }
            for (int i = 0; i < numList.Length; i++)
            {
                numListInv[numList[i]] = (ulong)i;
            }

            stego.ProgressChanged(20, 100);

            BigInteger      message        = new BigInteger(0);
            BigIntegerClass messageWrapper = new BigIntegerClass(message);

            // update presentation control
            SendOrPostCallback updatePresentationResultNumberDelegate = (SendOrPostCallback) delegate
            {
                presentation.UpdateResultNumber(messageWrapper);
            };

            if (presentation.IsVisible)
            {
                presentation.Dispatcher.Invoke(DispatcherPriority.Normal, updatePresentationResultNumberDelegate, null);
            }

            LRArray lr = new LRArray((ulong)source.Count);

            lr.set_all();

            try
            {
                for (int carrierIndex = source.Count - 1; carrierIndex >= 0; carrierIndex--)
                {
                    ulong v = lr.num_SRE(numList[carrierIndex]);
                    values[carrierIndex] = lr.num_SRE(numList[carrierIndex]);
                    lr.get_set_idx_chg((ulong)carrierIndex - v);
                }

                stego.ProgressChanged(30, 100);

                message = 0;
                for (int i = 1; i <= source.Count; i++)
                {
                    message = i * message + values[numListInv[source.Count - i]];

                    stego.ProgressChanged(i, source.Count + 1);

                    if (presentation.IsVisible)
                    {
                        messageWrapper.BigIntegerStruct = message;
                        presentation.Dispatcher.Invoke(DispatcherPriority.Normal, updatePresentationResultNumberDelegate, null);
                        Thread.Sleep(500);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            // convert message to stream
            byte[] messageBytes = message.ToByteArray();
            int    cnt          = messageBytes.Length;

            if (messageBytes[cnt - 1] == 0)
            {
                cnt--;
            }
            messageStream.Write(messageBytes, 0, cnt);
            messageStream.Position = 0;
        }
 public void UpdateResultNumber(BigIntegerClass value)
 {
     this.resultDataContext.Number = value.BigIntegerStruct;
 }