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
Post a Comment