1.11
2017-09-24 22:36 xx-- 阅读(426) 评论(0) 编辑 收藏 举报using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _1._1 { class Program { static void Main(string[] args) { int i; string s_text, s_key, s_result=""; char ch; //定义变量 Console.WriteLine("请输入原字符串"); s_text = Console.ReadLine(); //输入s_text Console.WriteLine("请输入秘钥字符串"); s_key = Console.ReadLine(); //输入s_key if (s_text.Length != s_key.Length) //判断长度是否相等 Console.WriteLine("秘钥字符串与原字符串长度必须相等"); else { for (i = 0; i < s_text.Length; i++) //使用for语句及异或运算符 ^ 进行加密 { ch = s_text[i]; s_result += (char)(ch ^ s_key[i]); } Console.WriteLine("加密后字符串为:"); Console.WriteLine(s_result); //输出加密后的结果 Console.WriteLine("按回车键结束"); Console.ReadLine(); } } } }