/// <summary>Constructor: create Deck from key phrase. /// Creates a cipher with a key based on the /// specified string.</summary> public PontifexSolitaire(string keyPhrase) { _keyDeck = new Deck(); // Shuffle deck according to key phrase. if (keyPhrase.Length > 0) { char[] keyPhrasechar = keyPhrase.ToCharArray(); Card tempCard; for (int i = 0; i < keyPhrase.Length; i++) { // The Solitaire 'spec' says "Perform the Solitaire operation, but // instead of Step 5, do another count cut based on the first // character of the passphrase" HOWEVER validating against the // test-vectors REQUIRES that the cut is perfomed using the // _current_ character and not always the first. int cut_size = GetCharValue(keyPhrasechar[i]); //[1]); if (cut_size > 0) { // Perform the Solitaire operation, but instead of Step 5. // do another count cut based on the current character // of the passphrase NextKeyStream(); tempCard = _keyDeck.PeekBottom(1); // check card on bottom _keyDeck.CutTop(cut_size); // perform cut _keyDeck.MoveDown(_keyDeck.FindTop(tempCard), _keyDeck.Count() - _keyDeck.FindTop(tempCard)); // put the card back on the bottom } // if (cut_size > 0) } // for i } } // PontifexSolitaire(String)
/// <summary>Constructor: specify Deck</summary> public PontifexSolitaire (Deck useDeck) { _keyDeck = useDeck; }
/// <summary>Constructor: defaults to empty, ordered Deck</summary> public PontifexSolitaire () { _keyDeck = new Deck(); }