cryptography-utils/vigenere.cc
2023-10-24 21:38:29 +02:00

32 lines
517 B
C++

#include <iostream>
int keyvalue(char c)
{
return std::tolower(c) - 'a';
}
int main(int argc, char** argv)
{
char* text;
char* key;
if(argc < 3)
{
std::cout << "Usage: " << argv[0] << " <plain text> <key>" << std::endl;
return 0;
}
text = argv[1];
key = argv[2];
int ki = 0;
for(int pi = 0; text[pi] != 0; ++pi)
{
char c = std::tolower(text[pi]) + keyvalue(key[ki]);
if(c < 'a') c+=26;
if(c > 'z') c-=26;
std::cout << c;
if(key[++ki] == 0) ki = 0;
}
std::cout << std::endl;
return 0;
}