Demo entry 5288171

Caesar's code (improved)

   

Submitted by Zoe Chou on Jun 14, 2016 at 14:19
Language: C. Code size: 981 Bytes.

#include <stdio.h>

int main()
{
	char plaintext[100];
	char ciphertext[100];
	int n;
	int i = 0;

	printf("Please input the number of stagger letters:");
	scanf("%d", &n);
	fflush(stdin);

	printf("Please enter your plaintext:");
	gets_s(plaintext);

	for (i = 0; plaintext[i] != '\0'; i++)
	{
		if(plaintext[i] >= 'a' && plaintext[i] <= 'z' - n)
			ciphertext[i] = plaintext[i] + n;
		else if (plaintext[i]>'z' - n && plaintext[i] <= 'z')
		  ciphertext[i] = plaintext[i] + n - 26;
		else if (plaintext[i] == ' ')
		  ciphertext[i] = '*';
		else
		  ciphertext[i] = plaintext[i];

		switch (plaintext[i])
		{
		case'A':ciphertext[i] = '4'; break;
		case'B':ciphertext[i] = '8'; break;
		case'E':ciphertext[i] = '3'; break;
		case'I':ciphertext[i] = '1'; break;
		case'O':ciphertext[i] = '0'; break;
		case'S':ciphertext[i] = '5'; break;
		}
	}
	ciphertext[i] = '\0';
	printf("Your ciphertext is: %s", ciphertext);
	getchar();
	return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).