コード例 #1
0
        public static Decryption keyGet(string filename)
        {
            string     readText   = TextHandler.Reader(filename);
            Decryption decryptKey = new Decryption(null, null, null);
            int        orderCount = readText.IndexOf("cthulhu");
            int        x          = 0;

            int[] orders = new int[decryptKey.characters.Count()];
            while (x < orderCount / 2)
            {
                string orderString  = readText.Substring(0, 2); //reads next two-digit number from text header
                string tempString   = string.Empty;
                int    lengthHolder = tempString.Length;
                int    addZeros     = 0;

                if (orderString.IndexOf("0") == 0)          //check for leading zero on order number
                {
                    orderString = orderString.Substring(1); //if there is a leading zero remove it
                }
                else
                {
                }

                decryptKey.order[x] = Convert.ToInt32(orderString);  //converts order above to int

                //create binary value from order int
                tempString = Convert.ToString(decryptKey.order[x], 2);

                //convert tempString (binary equivalent of order) to 6-digit binary with leading zeroes
                if (tempString.Length == 6)
                {
                }                                //already ok

                else if (tempString.Length < 6)  //add leading zeroes
                {
                    lengthHolder = tempString.Length;
                    for (addZeros = 0; addZeros < (6 - lengthHolder); addZeros++)
                    {
                        tempString = "0" + tempString;
                    }
                }
                decryptKey.binary[x] = tempString;
                tempString           = string.Empty;
                lengthHolder         = 0;
                x++;
                readText = readText.Substring(2);
            }

            return(decryptKey);
        }
コード例 #2
0
        public static string Decrypt(Decryption decryptKey, string[] binaries)
        {
            string plaintextString = string.Empty;

            for (int x = 0; x < binaries.Count(); x++)
            {
                for (int y = 0; y < decryptKey.binary.Count(); y++)
                {
                    bool testBool = binaries[x] == decryptKey.binary[y];
                    if (binaries[x] == decryptKey.binary[y])
                    {
                        plaintextString = plaintextString + decryptKey.characters[y];
                        break;
                    }
                    else
                    {
                    }
                }
            }

            return(plaintextString);
        }