如题所述
static void Main(string[] args)
{
Console.WriteLine("请输入原文:");
string a = Console.ReadLine();
string c = "";
//获取字符串每位的字符将ASCII码加3即可
for (int i = 0; i < a.Length; i++)
{
int b = a[i];
//当为字母为X、Y、或Z时转换为A、B、或C
if ((b + 3) > 90 && b < 97)
{
c += (char)(b + 3 - 26);
}
////当为字母为x、y、或z时转换为a、b、或b
else if ((b + 3) > 122)
{
c += (char)(b + 2 - 25);
}
else
{
c += (char)(b+3);
}
}
Console.WriteLine("密文:" + c);
Console.ReadLine();
}
{
Console.WriteLine("请输入原文:");
string a = Console.ReadLine();
string c = "";
//获取字符串每位的字符将ASCII码加3即可
for (int i = 0; i < a.Length; i++)
{
int b = a[i];
//当为字母为X、Y、或Z时转换为A、B、或C
if ((b + 3) > 90 && b < 97)
{
c += (char)(b + 3 - 26);
}
////当为字母为x、y、或z时转换为a、b、或b
else if ((b + 3) > 122)
{
c += (char)(b + 2 - 25);
}
else
{
c += (char)(b+3);
}
}
Console.WriteLine("密文:" + c);
Console.ReadLine();
}
获取每个字符的ASCII码加3即可实现要求的加密
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-06-21
string str = "ABCED";
string ret = "";
foreach(char ch in str){
ret += (char)((int)ch + 3);
}
Console.Write(ret);// 这个ret就是加密后的了本回答被提问者采纳
string ret = "";
foreach(char ch in str){
ret += (char)((int)ch + 3);
}
Console.Write(ret);// 这个ret就是加密后的了本回答被提问者采纳
第2个回答 2013-06-21
那你想怎么解密... 原文都被加密了... 你怎么将密文解密为原文...
还有,你要用什么加密算法?追问
还有,你要用什么加密算法?追问
不用解密,只用做加密就行啦