c语言实现des加密算法的实验报告,DES加密算法C语言实验报告.doc

Word格式

完美整理

DES实验报告

实验目的

实现DES算法。

实验过程

按照DES的算法流程设计,具体实施详见附件。

使用方法

首先输入密钥,八位ASCII长,否则报错。然后输入读入文件名和写入文件名,必须以ASCII编码,否则不能使用。

实验结果

将自身cpp文件进行加密解密,前后文件完全一样。见文件

附录

源代码:

// 滴一欸死.cpp : 定义控制台应用程序的入口点。

//

#include "stdafx.h"

#include

#include

#include

#include

#include

#include "table.h"

/* Constant */

#define ENCRYPT_LENGTH8//length of each unit in encryption

#define DECIPHER_LENGTH 4//length of each unit in decipher

#define MAX320xFFFFFFFF//mask of 32 bits

/* Declaration */

typedef unsigned long longbit64;

typedef unsigned long longbit56;

typedef unsigned long longbit48;

typedef unsigned intbit32;

typedef unsigned intbit28;

/* File stream */

FILE *fin, *fout;

/* For debug */

inline void printBite(bit64 num)

{

while (num)

{

printf("%d", num % 2);

num >>= 1;

}

printf("\n");

}

/* Transfer from char to bit in Encrtption */

inline bit64 ToBit(

char *in// source string

);

/* Transfer from char to bit in Deciphtering */

inline bit64 DeToBit(

char *in// source string

);

/* Transfer from bit to char */

inline void ToBite(

char *out,// out string

bit64 num// source bits

);

/* Permutation */

inline bit64 substitute(

bit64 num,// source bits

const int *table,// Permutation table

size_t len// bits length

);

/* Bit recycle loop to left */

inline bit28 MoveLeft(

bit28 key,// source bits

int len// bits length

);

/* Bit recycle loop to right */

inline bit28 MoveRight(

bit28 key, // source bits

int len// bits length

);

/* Divide bits into two parts */

inline void divide(

bit64 num,// source bits

int len,// length of each bits

bit32 *L,// left out bits

bit32 *R// right out bits

);

/* S box */

inline bit32 SChange(

bit48 num// source bits

);

/* F box */

inline bit32 FChange(

bit32 num,// source bits

bit48 key// secret key

);

/* Key initialization */

inline void SetKey(

char *in// string of key

);

/* Enryption */

inline void DES(

char *message// me

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值