Created
June 28, 2018 17:35
-
-
Save oma256/0e95d66302f11a68609e83d371d986f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include < conio.h > | |
#include < string.h > | |
#include < stdio.h > | |
#include <clocale> | |
void main() { | |
setlocale(LC_CTYPE, "russian"); | |
char p[50], key[15]; | |
int i, n, j; | |
printf("Введите текст для шифрования: "); | |
gets(p); | |
printf("\n"); | |
printf("Введите ключ: "); | |
gets(key); | |
n = strlen(p); | |
printf("\n"); | |
printf("Зашифрованный текст: "); | |
for (i = 0, j = 0; i < n; i++, j++) | |
{ | |
if (p[i] <= 'A' && p[i] >= 'Z') | |
{ | |
printf("%c", (((p[i] - 'A') + (key[j] - 'A') % 26) + 'A')); | |
} | |
if (p[i] <= 'a' && p[i] >= 'z') | |
{ | |
printf("%c", (((p[i] - 'a') + (key[j] - 'a') % 26) + 'a')); | |
} | |
else if (p[i] >= 'A' && p[i] <= 'Z') | |
{ | |
printf("%c", (((p[i] - 'A') + (key[j] - 'A') % 26) + 'A')); | |
} | |
else if (p[i] >= 'a' && p[i] <= 'z') | |
{ | |
printf("%c", (((p[i] - 'a') + (key[j] - 'a') % 26) + 'a')); | |
} | |
else | |
{ | |
printf("%c", p[i]); | |
} | |
} | |
printf("\n"); | |
printf("Расшифрованный текст: "); | |
puts(p); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment