代码:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<Windows.h>
#include<string.h>
unsigned int g_Count = 0;
void color(short x)
{
if (x >= 0 && x <= 15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
void menu()
{
color(0);
system("cls");
color(1);
printf("|-------★<<<<<<< 加密&解密 >>>>>>> ★------|\n");
color(10);
printf("|-------★ 0.要求用户进行输入加密的字符 ★------|\n");
printf("|-------★ 1.会显示加密字符新的加密字符 ★------|\n");
printf("|-------★ 2.会对刚加密的文件夹进行解密 ★------|\n");
printf("|-------★ 3.退出当前的程序设计应用程序 ★------|\n");
}
enum Commond_str
{
Encryption = 0,
New_Encryption = 1,
Decode = 2,
Exit = 3,
};
/*
会显示加密字符新的加密字符
方案一功能:将字符串中每个字符加上它在字符所在的位置(默认最开始的字符为"1"开始)+偏移量⒌
*/
void new_Encryption(int Count, char* len, char* decode_str)
{
int i = 0;
Count = strlen(len);
for (i = 0; i < Count; i++)
{
decode_str[i] = len[i] + i + 5;
}
printf("%s\n", decode_str);
}
int main(void)
{
unsigned int Count = 0, Commond = 0;
char password[10] = { 0 };
char encypt_str[20] = { 0 };//加密字符
char decode_str[40] = { 0 };//解密字符
int numbers = 0;
menu();
while (1)
{
printf("No.%d:Please input Command:", g_Count++);
scanf("%d", &Commond);
switch (Commond)
{
case Encryption:scanf("%s", encypt_str); printf("Your input encypt_str:%s\n", encypt_str); break;
case New_Encryption:new_Encryption(Count, encypt_str, decode_str); break;//第一种方案
case Decode:printf("encypt_str:%s\n", encypt_str); break;//注:解密以后的字符就是加密
case Exit:system("pause"); break;
}
if (Commond == Exit)
break;
}
return 0;
}
运行结果: