凯撒密码实现

#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;
}  
posted @ 2020-11-07 19:09  PamShao  阅读(300)  评论(0编辑  收藏  举报