cryptography-utils/brute.cc

34 lines
582 B
C++
Raw Normal View History

2023-10-24 13:14:21 +02:00
#include <iostream>
void shift(char* text, int key)
{
std::cout << key << ": ";
for(int i = 0; text[i] != 0; ++i)
{
2023-10-25 12:29:28 +02:00
if(text[i] == ' ')
{
std::cout << ' ';
continue;
}
// has to be int, because the result can sometimes be > 127
int c = std::tolower(text[i])-key;
2023-10-24 13:14:21 +02:00
if(c < 'a') c+=26;
if(c > 'z') c-=26;
std::cout << (char)c;
2023-10-24 13:14:21 +02:00
}
std::cout << std::endl;
}
int main(int argc, char** argv)
{
if(argc < 2)
{
std::cout << "Usage: " << argv[0] << " <ciphertext>" << std::endl;
return 0;
}
for(int i = 1; i < 26; ++i)
{
shift(argv[1], i);
}
return 0;
}