public Session(SessionParameters sessionParameter, TransmissionWord transmissionWord, int currentRoundIndex) { bool validCurrentRoundIndex = currentRoundIndex >= 0 && currentRoundIndex < sessionParameter.RoundCount; Debug.Assert(validCurrentRoundIndex, string.Format("Tried to construct a session with invalid currentRoundIndex {0}", currentRoundIndex)); if (!validCurrentRoundIndex) { return; } m_sessionParameter = sessionParameter; m_TransmissionWord = transmissionWord; m_SyllableChoiceArray = new ICryptoSyllable[sessionParameter.SyllableChoiceAmount]; m_SyllableSearchArray = new ICryptoSyllable[sessionParameter.SyllableSearchedAmount]; // Create transmission flow from parameter SessionParameters sp = m_sessionParameter; m_TransmissionSetup = TransmissionManager.BuildTransmissionSetup(sp.Seed, sp.RoundCount, sp.SyllableSearchedAmount, sp.SyllableChoiceAmount); // Set the active round index to the first entry ActiveRoundIndex = currentRoundIndex; // Start the first round SetRound(ActiveRoundIndex); }
public TransmissionWord(TransmissionWord startWord) { syllableIndices = new byte[startWord.syllableIndices.Length]; for (int i = 0; i < syllableIndices.Length; i++) { syllableIndices[i] = startWord.syllableIndices[i]; } }
/// <summary> /// Construct a new language excerpt /// </summary> /// <param name="word"></param> /// <param name="sourceLanguage">The source language to draw from</param> /// <param name="displayedSyllables">The number of displayed syllables</param> /// <param name="random">The random number generator to use</param> public LanguageExcerpt(TransmissionWord word, ACryptoLanguage sourceLanguage, int displayedSyllables, System.Random random) { SourceLanguage = sourceLanguage; usedSyllableIndices = new byte[displayedSyllables]; for (int i = 0; i < displayedSyllables; i++) { usedSyllableIndices[i] = 255; } List <byte> indexList = new List <byte>(SourceLanguage.syllableCount - word.syllableIndices.Length); for (byte i = 0; i < SourceLanguage.syllableCount; i++) { if (!word.syllableIndices.Contains(i)) { indexList.Add(i); } } var syllableIndex = 0; for (int i = 0; i < word.syllableIndices.Length; i++) { if (!usedSyllableIndices.Contains(word.syllableIndices[i])) { usedSyllableIndices[syllableIndex] = word.syllableIndices[i]; syllableIndex++; } } for (int i = syllableIndex; i < displayedSyllables; i++) { var index = random.Next(indexList.Count); usedSyllableIndices[i] = indexList[index]; indexList.RemoveAt(index); } for (int i = 0; i < word.syllableIndices.Length; i++) { for (byte j = 0; j < usedSyllableIndices.Length; j++) { if (word.syllableIndices[i] == usedSyllableIndices[j]) { word.syllableIndices[i] = j; break; } } } }
public bool IsEqualTo(TransmissionWord other) { if (syllableIndices.Length != other.syllableIndices.Length) { return(false); } for (int i = 0; i < syllableIndices.Length; i++) { if (syllableIndices[i] != other.syllableIndices[i]) { return(false); } } return(true); }
public Session(SessionParameters sessionParameter) { m_sessionParameter = sessionParameter; m_SyllableChoiceArray = new ICryptoSyllable[sessionParameter.SyllableChoiceAmount]; m_SyllableSearchArray = new ICryptoSyllable[sessionParameter.SyllableSearchedAmount]; // Create transmission flow from parameter SessionParameters sp = m_sessionParameter; m_TransmissionSetup = TransmissionManager.BuildTransmissionSetup(sp.Seed, sp.RoundCount, sp.SyllableSearchedAmount, sp.SyllableChoiceAmount); m_TransmissionWord = new TransmissionWord(m_TransmissionSetup.StartWord); Debug.Assert(m_TransmissionSetup.Transmissions.Length == sp.RoundCount, "Transmission setup creation returned tansmission array with wrong length"); // Set the active round index to the first entry ActiveRoundIndex = 0; // Start the first round SetRound(ActiveRoundIndex); }
/// <summary> /// Creates a transmission endpoint /// </summary> /// <param name="random">The random number generator to use</param> /// <returns></returns> public TransmissionEndpoint CreateEndpoint(int wordSyllables, int displaySyllables, System.Random random) { var wordCollection = words.Where(w => w.syllables.Length == wordSyllables).ToArray(); var word = wordCollection[random.Next(wordCollection.Length)]; string msg = "Choosing word"; for (int i = 0; i < word.syllables.Length; i++) { msg += " " + word.syllables[i]; } Debug.Log(msg); var startWord = new TransmissionWord() { syllableIndices = word.syllableIndices }; var humanExcerpt = new LanguageExcerpt(startWord, humanLanguage, displaySyllables, random); return(new TransmissionEndpoint(humanExcerpt, startWord)); }
/// <summary> /// Encrypts a word by converting it from outgoing language to incoming language /// </summary> /// <param name="inWord">The word to translate</param> /// <returns></returns> public TransmissionWord Encrypt(TransmissionWord inWord) { Dictionary <byte, byte> reversion = new Dictionary <byte, byte>(); foreach (var item in Conversion) { reversion.Add(item.Value, item.Key); } var outWord = new TransmissionWord { syllableIndices = new byte[inWord.syllableIndices.Length] }; for (byte i = 0; i < inWord.syllableIndices.Length; i++) { outWord.syllableIndices[i] = reversion[inWord.syllableIndices[i]]; } string msg = "Encrypt from"; for (int i = 0; i < inWord.syllableIndices.Length; i++) { msg += " " + inWord.syllableIndices[i]; } msg += " to"; for (int i = 0; i < outWord.syllableIndices.Length; i++) { msg += " " + outWord.syllableIndices[i]; } UnityEngine.Debug.Log(msg); return(outWord); }
public TransmissionSetup(TransmissionWord start, TransmissionEndpoint end, Transmission[] transmissions) { StartWord = start; EndPoint = end; Transmissions = transmissions; }
public TransmissionEndpoint(LanguageExcerpt humanLanguage, TransmissionWord startWord) { HumanLanguage = humanLanguage; RealWord = startWord; }