#include<stdio.h>
#include<stdlib.h>
void main()
{
//复制一个文件,需要输入两个数据。 一个是被复制的文件,一个是需要复制到哪里。
//加密程序其实已经完成了70%。
char
l_in_path[200] = { 0 };
char l_out_path[200] = { 0 };
char l_pass[50] =
{ 0 };
int l_tools = NULL;
printf("请输入源文件路径:");
scanf("%s",
l_in_path);
printf("请输入新文件路径:");
scanf("%s",
l_out_path);
printf("请输入密码:");
scanf("%s", l_pass);
printf("输入1为加密,输入2为解密:");
scanf("%d",
&l_tools);
if (l_tools != 1 && l_tools != 2)
{
printf("功能输入选择错误
");
return;
}
FILE * l_fp_read =
fopen(l_in_path, "rb");
FILE * l_fp_write = fopen(l_out_path,
"wb");
if (l_fp_read != NULL && l_fp_write !=
NULL) {
if (l_tools == 1) {
char l_temp =
fgetc(l_fp_read);
while (feof(l_fp_read) == 0) {
l_temp = l_temp +
40;
fputc(l_temp, l_fp_write);
l_temp =
fgetc(l_fp_read);
}
}
else {
char l_temp =
fgetc(l_fp_read);
while (feof(l_fp_read) == 0) {
l_temp = l_temp -
40;
fputc(l_temp, l_fp_write);
l_temp =
fgetc(l_fp_read);
}
}
}
fclose(l_fp_read);
fclose(l_fp_write);
printf("已复制成功
");
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void
main() {
//复制一个文件,需要输入两个数据。
一个是被复制的文件,一个是需要复制到哪里。
//加密程序其实已经完成了70%。
char l_in_path[200] = { 0
};
char l_out_path[200] = { 0 };
char l_pass[50] = { 0 };
int
l_tools = NULL;
printf("请输入源文件路径:");
scanf("%s",
l_in_path);
printf("请输入新文件路径:");
scanf("%s",
l_out_path);
printf("请输入密码:");
scanf("%s", l_pass);
printf("输入1为加密,输入2为解密:");
scanf("%d",
&l_tools);
if (l_tools != 1 && l_tools != 2)
{
printf("功能输入选择错误
");
return;
}
FILE * l_fp_read = fopen(l_in_path, "rb");
FILE * l_fp_write =
fopen(l_out_path, "wb");
int l_length = strlen(l_pass);
int l_count =
0;
if (l_fp_read != NULL && l_fp_write != NULL) {
if (l_tools ==
1) {
char l_temp = fgetc(l_fp_read);
while (feof(l_fp_read) == 0)
{
l_temp = l_temp ^ l_pass[l_count];
l_temp = l_temp +
l_count;
l_count++;
if (l_count == l_length) {
l_count =
0;
}
fputc(l_temp, l_fp_write);
l_temp =
fgetc(l_fp_read);
}
}
else {
char l_temp =
fgetc(l_fp_read);
while (feof(l_fp_read) == 0) {
l_temp = l_temp -
l_count;
l_temp = l_temp ^ l_pass[l_count];
l_count++;
if
(l_count == l_length) {
l_count = 0;
}
fputc(l_temp,
l_fp_write);
l_temp = fgetc(l_fp_read);
}
}
}
fclose(l_fp_read);
fclose(l_fp_write);
if (l_tools == 1)
{
printf("已加密成功
");
}
else {
printf("已解密成功
");
}
system("pause");
}