c# - Substitution Cipher Letter Mappings Data Structure -


what data structure better stores following substitution-cipher letter mappings?

abcdefghijklmnopqrstuvwxyz qpalzxmskwoeidjcnvbfhguryt 

i using 2 dictionaries, there must simpler:

char[] alphabet = {'a', 'b', 'c', 'd', 'e',                    'f', 'g', 'h', 'i', 'j',                    'k', 'l', 'm', 'n', 'o',                    'p', 'q', 'r', 's', 't',                    'u', 'v', 'w', 'x', 'y', 'z'}; char[] mappings = {'q', 'p', 'a', 'l', 'z',                    'x', 'm', 's', 'k', 'w',                    'o', 'e', 'i', 'd', 'j',                    'c', 'n', 'v', 'b', 'f',                    'h', 'g', 'u', 'r', 'y', 't'};  dictionary<char, char> encrypt = new dictionary<char, char>(); dictionary<char, char> decrypt = new dictionary<char, char>();  (int = 0; < 26; i++) {     encrypt.add(alphabet[i], mappings[i]);     decrypt.add(mappings[i], alphabet[i]); } 

your approach best. however, try wrapping dictionaries in class, jon skeet here: getting key of value of generic dictionary?


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -