C#利用異或算法實(shí)現(xiàn)加密解密
實(shí)踐過(guò)程
效果

代碼
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è)計(jì)器變量。
/// </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è)計(jì)器生成的代碼
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要
/// 使用代碼編輯器修改此方法的內(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 = "使用異或算法對(duì)數(shù)字進(jìn)行加密解密";
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#利用異或算法實(shí)現(xiàn)加密解密的文章就介紹到這了,更多相關(guān)C#加密解密內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#調(diào)用HTTP POST請(qǐng)求上傳圖片的示例代碼
現(xiàn)在很多B/S系統(tǒng)的開(kāi)發(fā)都是通過(guò)API方式來(lái)進(jìn)行的,一般服務(wù)端會(huì)開(kāi)放一個(gè)API接口,客戶端調(diào)用API接口來(lái)實(shí)現(xiàn)圖片或文件上傳的功能,感興趣的可以了解一下2021-05-05
C#使用ADO.Net連接數(shù)據(jù)庫(kù)與DbProviderFactory實(shí)現(xiàn)多數(shù)據(jù)庫(kù)訪問(wèn)
這篇文章介紹了C#使用ADO.Net連接數(shù)據(jù)庫(kù)與DbProviderFactory實(shí)現(xiàn)多數(shù)據(jù)庫(kù)訪問(wèn)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05
c# 應(yīng)用事務(wù)的簡(jiǎn)單實(shí)例
這篇文章介紹了c# 應(yīng)用事務(wù)的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-09-09
C# PictureBox圖片控件實(shí)現(xiàn)圖片交換
在c#中可以使用PictureBox控件來(lái)呈現(xiàn)圖像,本文主要介紹了C# PictureBox實(shí)現(xiàn)圖片交換,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06
c# 通過(guò)內(nèi)存映射實(shí)現(xiàn)文件共享內(nèi)存的示例代碼
這篇文章主要介紹了c# 通過(guò)內(nèi)存映射實(shí)現(xiàn)文件共享內(nèi)存的示例代碼,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-04-04
C#面向?qū)ο缶幊讨幸蕾嚪崔D(zhuǎn)原則的示例詳解
在面向?qū)ο缶幊讨?,SOLID?是五個(gè)設(shè)計(jì)原則的首字母縮寫(xiě),旨在使軟件設(shè)計(jì)更易于理解、靈活和可維護(hù)。本文將通過(guò)實(shí)例詳細(xì)講講C#面向?qū)ο缶幊讨幸蕾嚪崔D(zhuǎn)原則,需要的可以參考一下2022-07-07
VS2012 未找到與約束ContractName匹配的導(dǎo)出
這篇文章主要介紹了在更新的windows補(bǔ)丁后,Visual Studio 用戶可能無(wú)法打開(kāi)或創(chuàng)建 C++ 或 JavaScript 文件或項(xiàng)目,小編的解決辦法,希望可以幫助到大家2018-04-04

