C#利用异或算法实现加密解密

作者:芝麻粒儿 时间:2022-08-15 14:48:51 

实践过程

效果

C#利用异或算法实现加密解密

代码

public partial class Form1 : Form
{
   public Form1()
   {
       InitializeComponent();
   }

private void button1_Click(object sender, EventArgs e)
   {
       try
       {
           if (textBox1.Text != "")
           {
               textBox2.Text = (Convert.ToInt32(textBox1.Text) ^ 123).ToString();
           }
       }
       catch { }
   }

private void button2_Click(object sender, EventArgs e)
   {
       try
       {
           if (textBox2.Text != "")
           {
               textBox1.Text = (Convert.ToInt32(textBox2.Text) ^ 123).ToString();
           }
       }
       catch { }
   }
}
partial class Form1
{
   /// <summary>
   /// 必需的设计器变量。
   /// </summary>
   private System.ComponentModel.IContainer components = null;

/// <summary>
   /// 清理所有正在使用的资源。
   /// </summary>
   /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
   protected override void Dispose(bool disposing)
   {
       if (disposing && (components != null))
       {
           components.Dispose();
       }
       base.Dispose(disposing);
   }

#region Windows 窗体设计器生成的代码

/// <summary>
   /// 设计器支持所需的方法 - 不要
   /// 使用代码编辑器修改此方法的内容。
   /// </summary>
   private void InitializeComponent()
   {
       this.groupBox1 = new System.Windows.Forms.GroupBox();
       this.textBox2 = new System.Windows.Forms.TextBox();
       this.label3 = new System.Windows.Forms.Label();
       this.button2 = new System.Windows.Forms.Button();
       this.button1 = new System.Windows.Forms.Button();
       this.textBox1 = new System.Windows.Forms.TextBox();
       this.label2 = new System.Windows.Forms.Label();
       this.groupBox1.SuspendLayout();
       this.SuspendLayout();
       //
       // groupBox1
       //
       this.groupBox1.Controls.Add(this.textBox2);
       this.groupBox1.Controls.Add(this.label3);
       this.groupBox1.Controls.Add(this.button2);
       this.groupBox1.Controls.Add(this.button1);
       this.groupBox1.Controls.Add(this.textBox1);
       this.groupBox1.Controls.Add(this.label2);
       this.groupBox1.Location = new System.Drawing.Point(6, 4);
       this.groupBox1.Name = "groupBox1";
       this.groupBox1.Size = new System.Drawing.Size(282, 112);
       this.groupBox1.TabIndex = 6;
       this.groupBox1.TabStop = false;
       this.groupBox1.Text = "加密设置";
       //
       // textBox2
       //
       this.textBox2.Location = new System.Drawing.Point(115, 49);
       this.textBox2.Name = "textBox2";
       this.textBox2.Size = new System.Drawing.Size(143, 21);
       this.textBox2.TabIndex = 6;
       //
       // label3
       //
       this.label3.AutoSize = true;
       this.label3.Location = new System.Drawing.Point(24, 52);
       this.label3.Name = "label3";
       this.label3.Size = new System.Drawing.Size(89, 12);
       this.label3.TabIndex = 7;
       this.label3.Text = "加密后的数字:";
       //
       // button2
       //
       this.button2.Location = new System.Drawing.Point(183, 76);
       this.button2.Name = "button2";
       this.button2.Size = new System.Drawing.Size(75, 25);
       this.button2.TabIndex = 3;
       this.button2.Text = "解密";
       this.button2.UseVisualStyleBackColor = true;
       this.button2.Click += new System.EventHandler(this.button2_Click);
       //
       // button1
       //
       this.button1.Location = new System.Drawing.Point(101, 76);
       this.button1.Name = "button1";
       this.button1.Size = new System.Drawing.Size(75, 25);
       this.button1.TabIndex = 2;
       this.button1.Text = "加密";
       this.button1.UseVisualStyleBackColor = true;
       this.button1.Click += new System.EventHandler(this.button1_Click);
       //
       // textBox1
       //
       this.textBox1.Location = new System.Drawing.Point(115, 19);
       this.textBox1.Name = "textBox1";
       this.textBox1.Size = new System.Drawing.Size(143, 21);
       this.textBox1.TabIndex = 1;
       //
       // label2
       //
       this.label2.AutoSize = true;
       this.label2.Location = new System.Drawing.Point(24, 22);
       this.label2.Name = "label2";
       this.label2.Size = new System.Drawing.Size(89, 12);
       this.label2.TabIndex = 5;
       this.label2.Text = "加密前的数字:";
       //
       // Form1
       //
       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
       this.ClientSize = new System.Drawing.Size(296, 123);
       this.Controls.Add(this.groupBox1);
       this.MaximizeBox = false;
       this.MinimizeBox = false;
       this.Name = "Form1";
       this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
       this.Text = "使用异或算法对数字进行加密解密";
       this.groupBox1.ResumeLayout(false);
       this.groupBox1.PerformLayout();
       this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.GroupBox groupBox1;
   private System.Windows.Forms.Button button2;
   private System.Windows.Forms.Button button1;
   private System.Windows.Forms.TextBox textBox1;
   private System.Windows.Forms.Label label2;
   private System.Windows.Forms.TextBox textBox2;
   private System.Windows.Forms.Label label3;
}

来源:https://blog.csdn.net/qq_27489007/article/details/128436987

标签:C#,异或,加密,解密
0
投稿

猜你喜欢

  • C#/Java连接sqlite与使用技巧

    2021-07-10 08:34:05
  • 教你怎么用Java操作Redis

    2023-07-07 22:17:53
  • Java给JFrame窗口设置热键的方法实现

    2022-01-24 13:32:20
  • 如何在Java SpringBoot项目中配置动态数据源你知道吗

    2021-07-23 11:10:08
  • SpringBoot 读取yml文件的多种方式汇总

    2023-08-03 13:10:43
  • 基于socket和javaFX简单文件传输工具

    2022-11-04 12:37:42
  • log4j使用教程详解(怎么使用log4j2)

    2022-06-18 23:48:47
  • C#设置自定义文件图标实现双击启动(修改注册表)

    2023-08-21 08:43:46
  • MyBatis的 config.xml标签

    2021-07-18 02:01:34
  • 利用java实现邮箱群发功能

    2021-07-11 21:55:23
  • HashMap原理及手写实现部分区块链特征

    2023-10-15 03:27:27
  • Java Main 函数启动不退出的解决方案

    2022-03-24 14:25:03
  • Spring MVC中使用Controller如何进行重定向

    2022-05-12 04:09:35
  • SpringBoot接入支付宝支付的方法步骤

    2022-02-16 05:34:16
  • Java URL自定义私有网络协议

    2021-08-11 02:21:06
  • java编写的文件管理器代码分享

    2023-11-20 13:28:52
  • mybatis快速入门学习教程新手注意问题小结

    2023-08-23 18:52:38
  • C#实现基于任务的异步编程模式

    2023-01-08 19:21:15
  • java内存优化的方法总结

    2022-12-01 22:25:20
  • Flutter开发技巧ListView去除水波纹方法示例

    2021-12-27 14:15:24
  • asp之家 软件编程 m.aspxhome.com