📄 wjcdestest.cpp
字号:
// 3-Des test
#include "WjcDes.h"
#include "stdio.h"
#include "string.h"
#include "memory.h"
#include <string.h>
#include <stdio.h>
#define N 100
void main()
{
/////////代码由于从txt读数据到字符串,默认的字符个数为N,但是一般输入小于N,所以出现溢出,运行后会出现
///////报错,但是不影响程序加密,加密完将2.txt文件拷贝到解密程序文件夹,直接可解密
///////PART1:从1.txt中读取要加密的数据,数据大小为N,定义成宏,可以修改
FILE *stream;
// char string[] = "This is a test";
char msg[N];
stream = fopen("1.txt", "r+");
/* write a string into the file */
// fwrite(string, strlen(string), 1, stream);
/* seek to the start of the file */
fseek(stream, 0, SEEK_SET);
/* read a string from the file */
//fgets(msg, strlen(string)+1, stream);
fgets(msg, N, stream);
//////PART2,设定key,并且将1.txt的数据读入des加密函数
char key[]={0,2,0,0,9,3,5,1,9,8,0,0,9,1,7},buf[N];
char str[N];
for (int i=0;i<=N-1;i++)
{
str[i]=0;
}
for (int j=0;j<=N-1;j++)
{
str[j]=msg[j];
}
memset(buf, 0, sizeof(buf));
strcpy(buf, str);
puts("\nBefore encrypting");
puts(buf);
Des_Go(buf, buf, sizeof(str), key, sizeof(key), ENCRYPT);
puts("\nAfter encrypting");
puts(buf);
// Des_Go(buf, buf, sizeof(str), key, sizeof(key), DECRYPT);
// puts("\nAfter decrypting");
// puts(buf);
// getchar();
//////////////////////////////////////////
//////PART3:完成加密,输出为2.txt
/* open a file for update */
stream = fopen("2.txt", "w+");
/* write a string into the file */
fwrite(buf, strlen(buf), 1, stream);
/* seek to the start of the file */
fseek(stream, 0, SEEK_SET);
/* read a string from the file */
fgets(msg, strlen(buf)+1, stream);
/* display the string */
printf("%s", msg);
fclose(stream);
getchar();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -