public static string EncryptString(List <string> parsedString, KeyGen encKey) { string encryptedString = string.Empty; string orderString = string.Empty; //Create the order lead tag for (int y = 0; y < encKey.order.Count(); y++) { if (Convert.ToString(encKey.order[y]).Length < 2) { orderString = "0" + Convert.ToString(encKey.order[y]); } else if (Convert.ToString(encKey.order[y]).Length == 2) { orderString = Convert.ToString(encKey.order[y]); } else { //Console.WriteLine("Bad order length"); break; } encryptedString = encryptedString + orderString; orderString = string.Empty; } //Create the message start tag encryptedString = encryptedString + "cthulhu"; //Encrypt the characters in the parsed string foreach (string c in parsedString) { for (int x = 0; x < encKey.order.Count(); x++) { if (c == encKey.characters[x]) { encryptedString = encryptedString + encKey.binary[x] + " "; break; } else { } } } return(encryptedString); }
public static KeyGen ExistingKey(int[] keyOrder) { KeyGen completedKey = new KeyGen(null, null, null); int charCount = completedKey.characters.Count(); if (keyOrder.Count() != charCount) { throw new IndexOutOfRangeException(); } for (int x = 0; x < charCount; x++) { completedKey.order[x] = keyOrder[x]; completedKey.binary[x] = Convert.ToString(keyOrder[x], 2); } return(completedKey); }
public static KeyGen EncryptRand(KeyGen target) { int charCount = target.characters.Count(); Random rng = new Random(); int x = 0; while (x < charCount) { bool orderCheck = true; string tempString = string.Empty; int addZeros = 0; int lengthHolder = 0; if (x == 0) { target.order[x] = rng.Next(1, charCount + 1); tempString = Convert.ToString(target.order[x], 2); if (tempString.Length == 6) { } else if (tempString.Length < 6) { lengthHolder = tempString.Length; for (addZeros = 0; addZeros < (6 - lengthHolder); addZeros++) { tempString = "0" + tempString; } } target.binary[x] = tempString; tempString = string.Empty; lengthHolder = 0; x++; } else if (x > 0) { int nextValue = rng.Next(1, charCount + 1); for (int y = 0; y < charCount; y++) { if (target.order[y] == nextValue) { orderCheck = false; break; } else { } } if (orderCheck == true) { target.order[x] = nextValue; tempString = Convert.ToString(target.order[x], 2); if (tempString.Length == 6) { } else if (tempString.Length < 6) { lengthHolder = tempString.Length; for (addZeros = 0; addZeros < (6 - lengthHolder); addZeros++) { tempString = "0" + tempString; } } target.binary[x] = tempString; tempString = string.Empty; lengthHolder = 0; x++; } else { } } } return(target); }