你好,凯撒算法的原理很简单,就是对字母进行移位,比如最常用的右移3位。
比如字符'a'变成'd',字母'Z'变成'C'。
以下是一个凯撒算法加解密的示例程序,楼主可以参考:
// Copyright @ quark
// Date: 2010-10-23
using System;
namespace BaiduTest
{
public class KaiSa
{
public static string Encrypt(string text)
{
string encrptString = string.Empty;
foreach (char c in text)
{
if (char.IsLetter(c))
{
char newChar = (char)(c + 3);
if (!char.IsLetter(newChar))
{
newChar -= (char)26;
}
encrptString += newChar;
}
else
{
encrptString+=c;
}
}
return encrptString;
}
public static string Decrypt(string text)
{
string decrptString = string.Empty;
foreach (char c in text)
{
if (char.IsLetter(c))
{
char newChar = (char)(c - 3);
if (!char.IsLetter(newChar))
{
newChar += (char)26;
}
decrptString += newChar;
}
else
{
decrptString += c;
}
}
return decrptString;
}
}
class Program
{
public static void Main(string[] args)
{
string testString = "xyz XYZ ABC abc Hello, World!";
Console.WriteLine("原文:{0}", testString);
string encryptStr = KaiSa.Encrypt(testString);
Console.WriteLine("秘文:{0}", encryptStr);
string decryptStr = KaiSa.Decrypt(encryptStr);
Console.WriteLine("明文:{0}", decryptStr);
Console.ReadKey();
}
}
}
告诉我邮箱 我把程序发给你
http://www.pudn.com/downloads113/sourcecode/crypt/detail475059.html这有个,你下载看看
http://wenku.baidu.com/view/5f25993143323968011c92d6.html这个是百度文库的,希望能帮到你~我也不太会这个
先看看这个:
http://hi.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/b62441fa541839294f4aea9f.html
有问题可以留言。
都大了,我就不答了吧