C#利用異或算法實現(xiàn)加密解密
更新時間:2023年01月03日 09:32:27 作者:芝麻粒兒
這篇文章主要為大家詳細介紹了C#如何利用異或算法實現(xiàn)加密解密的功能,文中的示例代碼講解詳細,對我們學(xué)習(xí)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>
/// 必需的設(shè)計器變量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
/// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗體設(shè)計器生成的代碼
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要
/// 使用代碼編輯器修改此方法的內(nèi)容。
/// </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 = "加密設(shè)置";
//
// 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 = "加密后的數(shù)字:";
//
// 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 = "加密前的數(shù)字:";
//
// 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 = "使用異或算法對數(shù)字進行加密解密";
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;
}
到此這篇關(guān)于C#利用異或算法實現(xiàn)加密解密的文章就介紹到這了,更多相關(guān)C#加密解密內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#調(diào)用HTTP POST請求上傳圖片的示例代碼
現(xiàn)在很多B/S系統(tǒng)的開發(fā)都是通過API方式來進行的,一般服務(wù)端會開放一個API接口,客戶端調(diào)用API接口來實現(xiàn)圖片或文件上傳的功能,感興趣的可以了解一下2021-05-05
C#使用ADO.Net連接數(shù)據(jù)庫與DbProviderFactory實現(xiàn)多數(shù)據(jù)庫訪問
這篇文章介紹了C#使用ADO.Net連接數(shù)據(jù)庫與DbProviderFactory實現(xiàn)多數(shù)據(jù)庫訪問的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05
c# 通過內(nèi)存映射實現(xiàn)文件共享內(nèi)存的示例代碼
這篇文章主要介紹了c# 通過內(nèi)存映射實現(xiàn)文件共享內(nèi)存的示例代碼,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-04-04
C#面向?qū)ο缶幊讨幸蕾嚪崔D(zhuǎn)原則的示例詳解
在面向?qū)ο缶幊讨?,SOLID?是五個設(shè)計原則的首字母縮寫,旨在使軟件設(shè)計更易于理解、靈活和可維護。本文將通過實例詳細講講C#面向?qū)ο缶幊讨幸蕾嚪崔D(zhuǎn)原則,需要的可以參考一下2022-07-07
VS2012 未找到與約束ContractName匹配的導(dǎo)出
這篇文章主要介紹了在更新的windows補丁后,Visual Studio 用戶可能無法打開或創(chuàng)建 C++ 或 JavaScript 文件或項目,小編的解決辦法,希望可以幫助到大家2018-04-04

