此程序分两部分,第一部分为主程序,另一部分为函数库
本程序中用int[]表示char的2进制形式,如a=int[8]{0,1,1,0,0,0,0,1}
下面副程序 本程序在C# 2005下通过。。
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
#endregion
namespace DES_2nd
{
partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Func.Func F = new Func.Func(); // 初始化函数库
private void button1_Click(object sender, EventArgs e)
{
char[] tempmchar = mbox.Text.ToCharArray(); //原始明文
int mod = tempmchar.Length % 8; //扩展明文为8的倍数
char[] mchar = new char[tempmchar.Length + (8 - mod)];
for (int i = 0; i < tempmchar.Length; i++)
{
mchar[i] = tempmchar[i];
}
for (int i = tempmchar.Length; i < mchar.Length; i++)
{
mchar[i] = ;
}
char[] kchar = kbox.Text.ToCharArray();//获得64位密钥
char[] cchar = new char[mchar.Length];//初始化密文数组
int[][] keys = F.makekey(kchar);//由makekey函数通过64位密钥计算16个48位密钥
int div = mchar.Length / 8;//每8个为一组对明文分组
&