Changeset 781


Ignore:
Timestamp:
Oct 25, 2009, 8:23:12 PM (12 years ago)
Author:
malischewski
Message:

Added sortKey method (returns a key as an array, e.g. "EZEBRA" -> [3,6,4,2,5,1])

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/Transposition/Transposition.cs

    r778 r781  
    620620            return true;
    621621        }
     622               
     623                 public int[] sortKey(String input)
     624        {
     625            String key = input;
     626            Char[] keyChars = key.ToCharArray();
     627            Char[] orgChars = key.ToCharArray();
     628            int[] rank = new int[keyChars.Length];
     629            Array.Sort(keyChars);
     630
     631            for (int i = 0; i < orgChars.Length; i++)
     632            {
     633                rank[i] = (Array.IndexOf(keyChars, orgChars[i])) + 1;
     634                keyChars[Array.IndexOf(keyChars, orgChars[i])] = (char)0;
     635            }
     636
     637            return rank;
     638        }
    622639
    623640        private void Transposition_LogMessage(string msg, NotificationLevel loglevel)
Note: See TracChangeset for help on using the changeset viewer.