C#利用異或算法實(shí)現(xiàn)加密解密
更新時間:2023年01月03日 09:32:27 作者:芝麻粒兒
這篇文章主要為大家詳細(xì)介紹了C#如何利用異或算法實(shí)現(xiàn)加密解密的功能,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
實(shí)踐過程
效果
代碼
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 = "使用異或算法對數(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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#9.0新特性詳解——頂級程序語句(Top-Level Programs)
這篇文章主要介紹了C#9.0新特性詳解——頂級程序語句(Top-Level Programs)的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下2020-12-12c# WinForm制作圖片編輯工具(圖像拖動、縮放、旋轉(zhuǎn)、摳圖)
這篇文章主要介紹了c# WinForm制作圖片編輯工具(可實(shí)現(xiàn)圖像拖動、縮放、旋轉(zhuǎn)、摳圖),幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-03-03C#遞歸應(yīng)用之實(shí)現(xiàn)JS文件的自動引用
這篇文章主要為大家詳細(xì)介紹了C#如何利用遞歸實(shí)現(xiàn)JS文件的自動引用的功能,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,需要的可以參考一下2023-03-03.Net(c#)漢字和Unicode編碼互相轉(zhuǎn)換實(shí)例
下面小編就為大家?guī)硪黄?Net(c#)漢字和Unicode編碼互相轉(zhuǎn)換實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02