Caesar Cipher(시저 암호) for C언어

2020. 11. 30. 14:55암호학/C언어

시저(Caesar) 암호 = 카이사르 암호 = 케사르 암호

#include <stdio.h>

char symbols[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !?.";

void encrypt_mess(char* b)
{
	int i, j;
	int encrypt_num;
	char ciphertext[200] = "";

	printf("plain text : %s\n", b);

	for (i = 0; i < strlen(b); i++)
	{
		for (j = 0; j < strlen(symbols); j++)
		{
			if (symbols[j] == b[i])
			{
				encrypt_num = (j + 13) % strlen(symbols);
				ciphertext[i] = symbols[encrypt_num];
			}
		}
	}
	printf("cipher text : %s", ciphertext);
}

int main()
{
	char msgs[] = "This is my secret plaintext.";
	
	
	char my_mode[] = "encrypt";
	//printf("%s\n", my_mode);
	//char my_mode[] = "decrypt";
	//printf("%d\n", strcmp(my_mode, "encrypt"));

	if (strcmp(my_mode, "encrypt") == 0)
		printf("mode is encrypt\n");
	
	encrypt_mess(msgs);

	return 0;
}

'암호학 > C언어' 카테고리의 다른 글

sha-1  (0) 2021.05.13
sha-1  (0) 2021.05.12
C언어 / 입력한 문자 거꾸로 출력  (0) 2020.11.29
C언어 / scanf 기본 출력  (0) 2020.11.29
affine Cipher(아핀 암호) for c언어  (0) 2020.11.26