C语言字符串加密解密系统

本文介绍了一个使用C语言编写的简单程序,实现了加密和解密字符的功能,用户可以选择加密输入的字符并查看加密后的结果,或者解密已加密的字符。
摘要由CSDN通过智能技术生成

代码:

#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;
}

运行结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值