Пример #1
0
        /// <summary>
        /// This method ensures that we encrypt with the rigth encoding
        /// We put the recieved string in a array of bytes and convert them. These can easily be coverted back to char
        /// Ensure the encrypted text always starts out with dummy text
        /// Iteration runs through our byte array
        /// Each time it runs through we call our method makecodeofchar and send our asciichar with it
        /// Ensure the encrypted text always ends out with dummy text
        /// </summary>
        /// <param name="inString"></param>
        /// <returns></returns>
        public string CryptString(string inString)
        {
            string   res     = "";
            Encoding enc1252 = CodePagesEncodingProvider.Instance.GetEncoding(1252); // Tells which encoding to use to read the text from the left textbox

            byte[] asciiByte = enc1252.GetBytes(inString);

            res = CTD.MakeDummyString(); // Ensure the encrypted text always starts out with dummy text

            // This is where the actual encryption takes place
            foreach (char asciiChar in asciiByte)
            {
                res += MakeCodeOfChar(asciiChar);
                res += CTD.MakeDummyString();
            }

            return(res);
        }
        /// <summary>
        /// This method ensures that we encrypt with the rigth encoding
        /// We put the recieved string in a array of bytes and convert them. These can easily be coverted back to char
        /// Ensure the encrypted text always starts out with dummy text
        /// Iteration runs through our byte array
        /// Each time it runs through we call our method makecodeofchar and send our asciichar with it
        /// Ensure the encrypted text always ends out with dummy text
        /// </summary>
        /// <param name="inString"></param>
        /// <returns>string</returns>
        public string CryptString(string inString)
        {
            string res       = "";
            string tempDummy = "";
            int    intJump   = 0;

            Encoding enc1252 = CodePagesEncodingProvider.Instance.GetEncoding(1252);

            byte[] asciiByte = enc1252.GetBytes(inString);

            res     = CTD.MakeDummyString(); // Ensure the encrypted text always starts out with dummy text
            intJump = res.Length;

            foreach (char asciiChar in asciiByte)
            {
                res      += MakeCodeOfChar(asciiChar, intJump);
                tempDummy = CTD.MakeDummyString();
                intJump   = tempDummy.Length;
                res      += tempDummy;
            }

            return(res);
        }