示例#1
0
        public Rc4(int key)
        {
            key = key < 0 ? 0 : key;
            var nKey = new[] { (byte)key };

            if (key > byte.MaxValue)
            {
                nKey = key > ushort.MaxValue ? Modern.CypherInt(key) : Modern.CypherShort((ushort)key);
            }
            Initialize(nKey);
        }
示例#2
0
        private void ModernCypherShortBtn_Click(object sender, EventArgs e)
        {
            ushort value;

            if (ushort.TryParse(ModernShortInputTxt.Text, out value))
            {
                ModernShortOutputTxt.Text = HMessage.ToString(Modern.CypherShort(value));
            }
            else
            {
                MessageBox.Show(NotUInt16, TanjiError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private void ReconstructList(bool stringsOnly)
        {
            BeginUpdate();
            for (int i = 0; i < _chunks.Count; i++)
            {
                object chunk = _chunks[i];
                if (!(chunk is string) && stringsOnly)
                {
                    continue;
                }
                string encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, chunk));
                Items[i].SubItems[2].Text = encoded;

                var value = chunk as string;
                if (value != null)
                {
                    string encodedLength = string.Empty;
                    if ((Destination == HDestination.Server && Protocol == HProtocol.Ancient) || Protocol == HProtocol.Modern)
                    {
                        ushort valueLength = (ushort)value.Length;
                        byte[] data        = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength);
                        encodedLength = HMessage.ToString(data) + " | ";
                    }

                    Items[i].ToolTipText = string.Format("Type: String\nValue: {0}\n{1}Encoded: {2}", value, string.Format("Length: {0}{1}\n", encodedLength, value.Length), encoded);
                }
                else
                {
                    Items[i].ToolTipText = Items[i].ToolTipText.Replace(Items[i].ToolTipText.GetChild("Encoded: ", '\n'), encoded);
                }
            }
            EndUpdate();
        }
示例#4
0
        public void ReplaceSelected(object value)
        {
            _lastHeader = 0;
            int index = SelectedIndices[0];

            if (value.Equals(_chunks[index]))
            {
                return;
            }

            _chunks[index] = value;
            ListViewItem curItem = Items[index];
            string       type    = value is string? "String" : value is int? "Integer" : "Boolean";
            string       encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, value));

            curItem.SubItems[0].Text = type;
            curItem.SubItems[1].Text = value.ToString();
            curItem.SubItems[2].Text = encoded;
            string encodedLength = string.Empty;

            if (value is string)
            {
                if ((Destination == HDestination.Server && Protocol == HProtocol.Ancient) || Protocol == HProtocol.Modern)
                {
                    ushort valueLength = (ushort)value.ToString().Length;
                    byte[] data        = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength);
                    encodedLength = HMessage.ToString(data) + " | ";
                }
            }
            curItem.ToolTipText = string.Format("Type: {0}\nValue: {1}\n{2}Encoded: {3}", type, value, string.Format("Length: {0}{1}\n", encodedLength, value.ToString().Length), encoded);
        }
示例#5
0
        public void AppendChunk(string value)
        {
            _chunks.Add(value);

            string encodedLength = string.Empty;
            string encoded       = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, value));

            if (Destination == HDestination.Server || Protocol == HProtocol.Modern)
            {
                ushort valueLength = (ushort)value.Length;
                byte[] data        = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength);
                encodedLength = HMessage.ToString(data) + " | ";
            }
            AddItemChunk("String", value, encoded, string.Format("Length: {0}{1}\n", encodedLength, value.Length));
        }