当前位置:网站首页>凯撒密码实现

凯撒密码实现

2020-11-07 20:19:00 PamShao

#include <stdio.h>

int main()
{
	// 凯撒加密,明文中字母按字母表左移或者右移三位,这里右移
	char input[6] = "hello";
	char output[6];
	int key = 3;
	int i,j;
	for (i = 0; i < 5; i++)
	{
		int a = input[i];
		a += 3;
		output[i] = (char)a;
	}
	output[i] = '\0';
	printf("加密后:%s\n", output);

	for (j = 0; j < 5; j++)
	{
		int b = output[j];
		b -= 3;
		input[j] = (char)b;
	}
	input[j] = '\0';
	printf("解密后:%s", input);
	return 0;
}  

版权声明
本文为[PamShao]所创,转载请带上原文链接,感谢
https://www.cnblogs.com/pam-sh/p/13941980.html