一个简单的代替加密问题:
明表:abcdefghijklmnopqrstuvwxyz0123456789._
密表:klmnopqrstuvwxyz0123457896abcdefghij._
把给定字符串中的在明表中的字符用密表中的字符替换.比如"love"可替换为"vi5o".如何实现比较简单?
明表:abcdefghijklmnopqrstuvwxyz0123456789._
密表:klmnopqrstuvwxyz0123457896abcdefghij._
把给定字符串中的在明表中的字符用密表中的字符替换.比如"love"可替换为"vi5o".如何实现比较简单?
通过键值保存相关替换的数据如dictionary
private Dictionary<char, char> maps = new Dictionary<char, char>(); maps.Add('a', 'k');
maps.Add('b','l');
maps.Add('c','m');
maps.Add('d','n');
maps.Add('e','o');
maps.Add('f','p');
maps.Add('g','q');
maps.Add('h','r');
maps.Add('i','s');
maps.Add('j','t');
maps.Add('k','u');
maps.Add('l','v');
maps.Add('m','w');
... string str = "cjm";
char[] chs = new char[str.Length];
int i = 0;
foreach (char c in str)
{
chs[i++] = maps[c];
} string output = new string(chs);