Задача из курса CS50
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
/*шифр Вижнера*/
//главная функция
int main(int argc, string argv[])
{
// проверка на количество аргументов в командой строке
if (argc != 2)
{
printf("Usage: /home/cs50/pset2/vigenere <keyword>\n");
return 1;
}
// проверка на то, что в шифре одни буквы из алфавита
string word = argv[1];
int a = 0; // счетчик букв в шифре
for (int i=0; i<strlen(word);i++)
{
if (isalpha(word[i]))
{
a=a+1;
}
}
if (a != strlen(word))
{
printf("Keyword must only contain letters A-Z and a-z\n");
return 1;
}
//вводим исходное слово для шифровки
string p = GetString();
int j = 0;
int key = 0;
for (int i = 0, n = strlen(p); i < n; i++)
{
if (isalpha(p[i]))
{
if (islower(p[i]))
{
if (islower(word[j])) key=word[j]-97;
else key = word[j]-65;
int pi = (p[i]-97+key)%26+97;
printf("%c", pi);
}
else
{
if (islower(word[j])) key=word[j]-97;
else key = word[j]-65;
int pi = (p[i]-65+key)%26+65;
printf("%c", pi);
}
j=(j+1)%3;
}
else printf("%c", p[i]);
}
printf("\n");
return 0;
}