Skip to content

Instantly share code, notes, and snippets.

@oma256
Created June 28, 2018 17:35
Show Gist options
  • Save oma256/0e95d66302f11a68609e83d371d986f0 to your computer and use it in GitHub Desktop.
Save oma256/0e95d66302f11a68609e83d371d986f0 to your computer and use it in GitHub Desktop.
#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