Beispiel #1
0
        private void GetCipher(CipherCtx ctx, Mode CipherMode)
        {
            if (!CharString.Any(x => x.Equals(ctx.Text)))
            {
                ctx.Cipher = ctx.Text;
                return;
            }

            ctx.TextIndex = CharString.IndexOf(ctx.Text);
            ctx.PassIndex = CharString.IndexOf(ctx.Pass);

            var gc = CipherMode == Mode.Encrypt ? ctx.TextIndex + ctx.PassIndex : ctx.TextIndex - ctx.PassIndex;

            if (gc > CharString.Length)
            {
                gc = gc - (CharString.Length - 1);
            }
            if (gc < 0)
            {
                gc = (CharString.Length - 1) - Math.Abs(gc);
            }

            ctx.CipherIndex = gc;
            ctx.Cipher      = CharString[gc];
        }
Beispiel #2
0
        public string Cipher(string StrVal, string Key, Mode CipherMode = Mode.Encrypt)
        {
            string ky = ReGenerateKey(Key, StrVal.Length);

            CipherDictionary = new List <CipherCtx>();

            for (var i = 0; i < StrVal.Length; i++)
            {
                var gg = new CipherCtx
                {
                    Text = StrVal[i],
                    Pass = ky[i]
                };

                GetCipher(gg, CipherMode);

                CipherDictionary.Add(gg);
            }

            return(new string(CipherDictionary.Select(x => x.Cipher).ToArray()));
        }