public static List <CardCodeAndCount> GetDeckFromCode(string code)
        {
            List <CardCodeAndCount> result = new List <CardCodeAndCount>();

            byte[] bytes;
            try
            {
                bytes = Base32.Decode(code);
            }
            catch
            {
                throw new ArgumentException("Invalid deck code");
            }

            List <byte> byteList = bytes.ToList();

            //grab format and version
            //int format = bytes[0] >> 4;
            int version = bytes[0] & 0xF;

            byteList.RemoveAt(0);

            if (version > MaxKnownVersion)
            {
                throw new ArgumentException(
                          "The provided code requires a higher version of this library; please update.");
            }

            for (int i = 3; i > 0; i--)
            {
                int numGroupOfs = Varint.PopVarint(byteList);

                for (int j = 0; j < numGroupOfs; j++)
                {
                    int numOfsInThisGroup = Varint.PopVarint(byteList);
                    int set     = Varint.PopVarint(byteList);
                    int faction = Varint.PopVarint(byteList);

                    for (int k = 0; k < numOfsInThisGroup; k++)
                    {
                        int card = Varint.PopVarint(byteList);

                        string setString     = set.ToString().PadLeft(2, '0');
                        string factionString = IntIdentifierToFactionCode[faction];
                        string cardString    = card.ToString().PadLeft(3, '0');

                        CardCodeAndCount newEntry = new CardCodeAndCount()
                        {
                            CardCode = setString + factionString + cardString, Count = i
                        };
                        result.Add(newEntry);
                    }
                }
            }

            //the remainder of the deck code is comprised of entries for cards with counts >= 4
            //this will only happen in Limited and special game modes.
            //the encoding is simply [count] [card code]
            while (byteList.Count > 0)
            {
                int fourPlusCount   = Varint.PopVarint(byteList);
                int fourPlusSet     = Varint.PopVarint(byteList);
                int fourPlusFaction = Varint.PopVarint(byteList);
                int fourPlusNumber  = Varint.PopVarint(byteList);

                string fourPlusSetString     = fourPlusSet.ToString().PadLeft(2, '0');
                string fourPlusFactionString = IntIdentifierToFactionCode[fourPlusFaction];
                string fourPlusNumberString  = fourPlusNumber.ToString().PadLeft(3, '0');

                CardCodeAndCount newEntry = new CardCodeAndCount()
                {
                    CardCode = fourPlusSetString + fourPlusFactionString + fourPlusNumberString, Count = fourPlusCount
                };
                result.Add(newEntry);
            }

            return(result);
        }
        public static string GetCodeFromDeck(List <CardCodeAndCount> deck)
        {
            string result = Base32.Encode(GetDeckCodeBytes(deck));

            return(result);
        }