Exemple #1
0
 public bool IsReal()
 {
     return(Checksum == string.Concat(EncryptedName
                                      .Replace("-", "")
                                      .GroupBy(c => c)
                                      .OrderByDescending(g => g.Count())
                                      .ThenBy(g => g.Key)
                                      .Select(g => g.Key)
                                      .Take(5)));
 }
        public bool MatchesChecksum()
        {
            var cleaned = EncryptedName.Replace("-", "");
            var ordered = String.Concat(cleaned.OrderBy(c => c));
            var commons = ordered.GroupBy(x => x).OrderByDescending(x => x.Count()).Take(5);

            var calculated = string.Format("[{0}]", string.Concat(commons.Select(x => x.Key)));

            return(calculated == Checksum);
        }
Exemple #3
0
        public bool IsReal()
        {
            var chars = EncryptedName.
                        Replace("-", "").
                        GroupBy(c => c).
                        OrderByDescending(g => g.Count()).
                        ThenBy(g => g.Key).
                        Select(g => g.Key).
                        Take(5).
                        ToArray();

            var actualChecksum = new string(chars);
            var roomIsReal     = actualChecksum == Checksum;

            return(roomIsReal);
        }
Exemple #4
0
        private string GenerateHash()
        {
            var dictionary = new Dictionary <char, int>();

            foreach (var c in EncryptedName.Replace("-", ""))
            {
                if (dictionary.ContainsKey(c))
                {
                    dictionary[c]++;
                }
                else
                {
                    dictionary.Add(c, 1);
                }
            }
            dictionary = dictionary.OrderByDescending(x => x.Value).ThenBy(x => x.Key)
                         .ToDictionary(x => x.Key, x => x.Value);
            var ret = string.Join("", dictionary.Keys).Substring(0, 5);

            return(ret);
        }
Exemple #5
0
            public RoomRecord(string rawText)
            {
                FullText = rawText.Trim();

                var parts = FullText.Split('-');

                EncryptedName = string.Join('-', parts.Take(parts.Length - 1));

                var suffix      = parts.Last();
                var suffixParts = suffix.Split('[');

                RawSectorId = suffixParts[0];
                Checksum    = suffixParts[1].TrimEnd(']');
                SectorId    = int.Parse(RawSectorId);

                var letters      = EncryptedName.Replace("-", "");
                var letterCounts = new Dictionary <char, int>();

                foreach (var l in letters)
                {
                    if (!letterCounts.ContainsKey(l))
                    {
                        letterCounts[l] = 0;
                    }
                    letterCounts[l] = 1 + letterCounts[l];
                }

                RealChecksum = new string(
                    letterCounts
                    .OrderByDescending(x => x.Value)
                    .ThenBy(x => x.Key)
                    .Select(x => x.Key)
                    .ToArray()
                    )
                               .Substring(0, 5);
                IsReal = RealChecksum == Checksum;

                RealName = IsReal ? Decrypt() : null;
            }