Esempio n. 1
0
        private string DEC_Step1(System.Collections.Generic.List <int> tmp)
        {
            System.Collections.Generic.Dictionary <int, char> map = new Dictionary <int, char>();
            int key = 0;
            int i   = 0;

            for (i = 0; i < tmp.Count; i++)
            {
                if (tmp[i] == 0)
                {
                    break;
                }
            }
            UniKey k = new UniKey(1, i, new Key(__key));

            for (int j = 0; j < i; j++)
            {
                map.Add(k.Gen(), CONVERT.sym(tmp[j]));
            }
            string res = "";

            for (int j = i + 1; j < tmp.Count; j++)
            {
                if (tmp[j] == 0)
                {
                    break;
                }
                res += map[tmp[j]];
            }
            return(res);
        }
Esempio n. 2
0
        private List <int> DEC_Step5(string str)
        {
            List <int> res = new List <int>();
            string     tmp = str[0] + "" + str[1];

            _map_C = CONVERT.HexToByte(tmp);
            int k   = 0;
            int ras = (str.Length - 2) / 2;

            if (ras % 4 != 0)
            {
                throw new Exception();
            }
            byte[] bs = new byte[ras];
            for (int i = 2; i < str.Length; i += 2)
            {
                tmp     = str[i] + "" + str[i + 1];
                bs[k++] = CONVERT.HexToByte(tmp);
            }
            for (int i = 0; i < ras; i += 4)
            {
                res.Add(BitConverter.ToInt32(bs, i));
            }

            return(res);
        }
Esempio n. 3
0
        private System.Collections.Generic.List <int> ENC_Step1(string str)
        {
            System.Collections.Generic.List <int>             res = new List <int>();
            System.Collections.Generic.Dictionary <char, int> map = new Dictionary <char, int>();
            for (int i = 0; i < str.Length; i++)
            {
                if (!map.ContainsKey(str[i]))
                {
                    map.Add(str[i], 0);
                }
            }
            _map_C = map.Count;
            UniKey k = new UniKey(1, map.Count, _key);

            for (int i = 0; i < map.Count; i++)
            {
                KeyValuePair <char, int> t = map.ElementAt(i);
                int tmo = k.Gen();
                map[t.Key] = tmo;
                res.Add(CONVERT.ord(t.Key));
            }
            res.Add(0);
            for (int i = 0; i < str.Length; i++)
            {
                res.Add(map[str[i]]);
            }
            return(res);
        }
Esempio n. 4
0
        private int Step3_Get_Key()
        {
            int res = 1;

            for (int i = 0; i < __key.Length; i++)
            {
                res *= CONVERT.ord(__key[i]);
            }
            return(res);
        }
Esempio n. 5
0
        private string ENC_Step5(List <int> l)
        {
            string res = CONVERT.ToHex(Convert.ToByte(_map_C));

            for (int i = 0; i < l.Count; i++)
            {
                byte[] t = System.BitConverter.GetBytes(l[i]);
                for (int j = 0; j < t.Length; j++)
                {
                    res += CONVERT.ToHex(t[j]);
                }
            }
            return(res);
        }
Esempio n. 6
0
        public int Gen()
        {
            if (_pos >= _Key.Length)
            {
                _pos = 0;
            }
            int tmp = _prev * _num * CONVERT.ord(_Key[_pos]) + _pos;

            if (tmp < 0)
            {
                tmp *= -1;
            }
            _prev = tmp;
            _num++;
            _pos++;
            return(tmp);
        }
Esempio n. 7
0
        public static string ToHex(byte b)
        {
            string res = CONVERT.ToHexC(b / 16).ToString() + CONVERT.ToHexC(b % 16);

            return(res);
        }
Esempio n. 8
0
 public static byte HexToByte(string str)
 {
     return(Convert.ToByte(CONVERT.HexToByte(str[0]) * 16 + CONVERT.HexToByte(str[1])));
 }