Ejemplo n.º 1
0
        private string Decrypt(string Input)
        {
            string[] pass = Input.Split('|');
            int      CharsUsed, BytesUsed;

            CharsUsed = int.Parse(pass[pass.Length - 2]);
            BytesUsed = int.Parse(pass[pass.Length - 1]);
            char[] passchar  = new char[CharsUsed];
            byte[] passbytes = new byte[BytesUsed];
            for (int k = 0; k < pass.Length - 2; k++)
            {
                passbytes[k] = byte.Parse((int.Parse(pass[k]) - (9 + (2 * k))).ToString());
            }
            Decoder PassDecoder = new UnicodeEncoding().GetDecoder();
            int     buffer;
            bool    DECComp;

            PassDecoder.Convert(passbytes, 0, BytesUsed, passchar, 0, CharsUsed, true, out buffer, out buffer, out DECComp);
            string passstring = "";

            for (int k = 0; k < passchar.Length; k++)
            {
                passstring += passchar[k];
            }
            return(passstring);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Output data is converted to Unicode - else smileys will be lost
        /// </summary>
        /// <param name="input">string to be encoded from UTF8</param>
        /// <returns>Unicode encoded string</returns>
        public static string EncodeToUnicode16(string input)
        {
            var msgA      = Encoding.UTF8.GetBytes(input);
            var converted = UnicodeEncoding.Convert(Encoding.UTF8, UnicodeEncoding.Unicode, msgA);

            return(Encoding.Unicode.GetString(converted));
        }
Ejemplo n.º 3
0
 public void GetEncoder()
 {
     char[] chars = "abc\u1234\uD800\uDC00defg".ToCharArray();
     byte[] bytes = new UnicodeEncoding().GetBytes(chars);
     byte[] desBytes = new byte[20];
     int buffer;
     int outChars;
     bool completed;
     Encoder encoder = new UnicodeEncoding().GetEncoder();
     encoder.Convert(chars, 0, 10, desBytes, 0, 20, true, out buffer, out outChars, out completed);
     if (completed)
     {
         Assert.Equal(bytes, desBytes);
     }
 }        
Ejemplo n.º 4
0
 public void GetDecoder()
 {
     char[] sourceChars = "abc\u1234\uD800\uDC00defg".ToCharArray();
     char[] destinationChars = new char[10];
     byte[] bytes = new UnicodeEncoding().GetBytes(sourceChars);
     int bytesUsed;
     int charsUsed;
     bool completed;
     Decoder decoder = new UnicodeEncoding().GetDecoder();
     decoder.Convert(bytes, 0, 20, destinationChars, 0, 10, true, out bytesUsed, out charsUsed, out completed);
     if (completed)
     {
         Assert.Equal(sourceChars, destinationChars);
     }
 }
Ejemplo n.º 5
0
 public void GetEncoder()
 {
     char[] chars = EncodingHelpers.GetRandomString(10).ToCharArray();
     byte[] bytes = new UnicodeEncoding().GetBytes(chars);
     byte[] desBytes = new byte[20];
     int buffer;
     int outChars;
     bool completed;
     Encoder encoder = new UnicodeEncoding().GetEncoder();
     encoder.Convert(chars, 0, 10, desBytes, 0, 20, true, out buffer, out outChars, out completed);
     if (completed)
     {
         Assert.Equal(bytes, desBytes);
     }
 }        
Ejemplo n.º 6
0
        public void GetEncoder()
        {
            char[]  chars    = "abc\u1234\uD800\uDC00defg".ToCharArray();
            byte[]  bytes    = new UnicodeEncoding().GetBytes(chars);
            byte[]  desBytes = new byte[20];
            int     buffer;
            int     outChars;
            bool    completed;
            Encoder encoder = new UnicodeEncoding().GetEncoder();

            encoder.Convert(chars, 0, 10, desBytes, 0, 20, true, out buffer, out outChars, out completed);
            if (completed)
            {
                Assert.Equal(bytes, desBytes);
            }
        }
Ejemplo n.º 7
0
        public void GetDecoder()
        {
            char[]  sourceChars      = EncodingHelpers.GetRandomString(10).ToCharArray();
            char[]  destinationChars = new char[10];
            byte[]  bytes            = new UnicodeEncoding().GetBytes(sourceChars);
            int     bytesUsed;
            int     charsUsed;
            bool    completed;
            Decoder decoder = new UnicodeEncoding().GetDecoder();

            decoder.Convert(bytes, 0, 20, destinationChars, 0, 10, true, out bytesUsed, out charsUsed, out completed);
            if (completed)
            {
                Assert.Equal(sourceChars, destinationChars);
            }
        }
Ejemplo n.º 8
0
        public void GetEncoder()
        {
            char[]  chars    = EncodingHelpers.GetRandomString(10).ToCharArray();
            byte[]  bytes    = new UnicodeEncoding().GetBytes(chars);
            byte[]  desBytes = new byte[20];
            int     buffer;
            int     outChars;
            bool    completed;
            Encoder encoder = new UnicodeEncoding().GetEncoder();

            encoder.Convert(chars, 0, 10, desBytes, 0, 20, true, out buffer, out outChars, out completed);
            if (completed)
            {
                Assert.Equal(bytes, desBytes);
            }
        }
Ejemplo n.º 9
0
        public void GetDecoder()
        {
            char[]  sourceChars      = "abc\u1234\uD800\uDC00defg".ToCharArray();
            char[]  destinationChars = new char[10];
            byte[]  bytes            = new UnicodeEncoding().GetBytes(sourceChars);
            int     bytesUsed;
            int     charsUsed;
            bool    completed;
            Decoder decoder = new UnicodeEncoding().GetDecoder();

            decoder.Convert(bytes, 0, 20, destinationChars, 0, 10, true, out bytesUsed, out charsUsed, out completed);
            if (completed)
            {
                Assert.Equal(sourceChars, destinationChars);
            }
        }
Ejemplo n.º 10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Processes the directory entry.
        /// </summary>
        /// <param name="fId">set to <c>true</c> if its an ID entry, <c>false</c> if its a Name
        /// entry.</param>
        /// ------------------------------------------------------------------------------------
        private void ProcessDirectoryEntry(bool fId)
        {
            long nBasePos = m_stream.Position;

            int id;
            int nameRVA;

            if (fId)
            {
                id = m_reader.ReadInt32();
                m_TypeStack.Add(id);
            }
            else
            {
                nameRVA           = m_reader.ReadInt32() & 0x7FFFFFFF;
                m_stream.Position = m_BaseAddress + nameRVA;

                short        nStringLen = m_reader.ReadInt16();
                UTF8Encoding encoding   = new UTF8Encoding();
                byte[]       buffer     = UnicodeEncoding.Convert(new UnicodeEncoding(),
                                                                  encoding, m_reader.ReadBytes(2 * nStringLen));
                string name = new string(encoding.GetChars(buffer));
                m_TypeStack.Add(name);

                m_stream.Position = nBasePos + 4;
            }

            int  value           = m_reader.ReadInt32();
            bool fSubDir         = (value & 0x80000000) != 0;
            int  nVirtualAddress = value & 0x7FFFFFFF;

            m_stream.Position = m_BaseAddress + nVirtualAddress;
            if (fSubDir)
            {
                ProcessResourceDirectoryTable();
            }
            else
            {
                ProcessDataEntry();
            }

            m_TypeStack.RemoveAt(m_TypeStack.Count - 1);
            m_stream.Position = nBasePos + 8;
        }
Ejemplo n.º 11
0
        private string Encrypt(string Input)
        {
            char[]  pass = Input.ToCharArray();
            byte[]  passbytes = new byte[Input.Length * 2];
            int     CharsUsed, BytesUsed;
            bool    ENCComp;
            Encoder PassEncoder = new UnicodeEncoding().GetEncoder();

            PassEncoder.Convert(pass, 0, pass.Length, passbytes, 0, Input.Length * 2, true, out CharsUsed, out BytesUsed, out ENCComp);
            for (int k = 0; k < passbytes.Length; k++)
            {
                passbytes[k] = byte.Parse((int.Parse(passbytes[k].ToString()) + (9 + (2 * k))).ToString());
            }
            string passstring = "";

            for (int k = 0; k < passbytes.Length; k++)
            {
                passstring += passbytes[k].ToString() + '|';
            }
            return(passstring + CharsUsed + '|' + BytesUsed);
        }
Ejemplo n.º 12
0
        void ICommand.Process(MessageInfo message)
        {
            //get template
            char[] template = null;
            Match  match    = regFullWidth.Match(message.Content);

            if (match.Success)
            {
                if (!string.IsNullOrWhiteSpace(match.Groups["template"].Value))
                {
                    byte[] fromBytes = Encoding.UTF8.GetBytes(match.Groups["template"].Value);
                    byte[] toBytes   = UnicodeEncoding.Convert(Encoding.UTF8, Encoding.Unicode, fromBytes);

                    template = UnicodeEncoding.Unicode.GetChars(toBytes);

                    for (int i = 0; i < template.Length; i++)
                    {
                        if (template[i] >= 'a' && template[i] <= 'z')
                        {
                            template[i] = map[(int)template[i] - 97 + 1];
                        }
                        else if (template[i] >= 'A' && template[i] <= 'Z')
                        {
                            template[i] = map[(int)template[i] - 65 + 26 + 1];
                        }
                    }
                }
            }

            if (template != null)
            {
                string response = new string(template);

                tw.RespondMessage(response);
            }
        }