From 791969e67b01fb497af2575484e3ddd9c8a609af Mon Sep 17 00:00:00 2001 From: amerihsan Date: Thu, 26 Sep 2019 23:55:21 +0300 Subject: [PATCH] caeser by amer ihsan --- caeser by amerihsan.txt | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 caeser by amerihsan.txt diff --git a/caeser by amerihsan.txt b/caeser by amerihsan.txt new file mode 100644 index 0000000..df31637 --- /dev/null +++ b/caeser by amerihsan.txt @@ -0,0 +1,43 @@ +#include +#include +#include +#include +int main(int argc, char **argv) +{ + int i; + string plaintext; + if (argc != 2) //check for one command line + { + printf("Usage: ./caesar key \n"); + return 1; + } + int k = atoi(argv[1]); + if (k < 0)//check for the key to be positive + { + printf("Usage: ./caesar key \n"); + } + plaintext = get_string("plantext : ");//to input the plantext + printf("ciphertext:"); + for (i = 0 ; i < strlen(plaintext); i++) + { + + if (isupper(plaintext[i]))//check for upper car + { + printf("%c", (plaintext[i] - 'A' + k) % 26 + 'A'); + + } + else if (islower(plaintext[i])) + { + printf("%c", (plaintext[i] - 'a' + k) % 26 + 'a'); + } + else + { + + printf("%c", plaintext[i]); + } + } + printf("\n"); + +} + +