-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (63 loc) · 2.45 KB
/
main.cpp
File metadata and controls
75 lines (63 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include "development/include/print_usage.h"
#include "model/include/enigma.h"
int main(int argc, char* argv[])
{
if (argc < 3)
{
printUsage();
return 1;
}
std::string message = argv[1];
std::string operation = argv[2];
std::vector<int> rotorPositions = {0, 0, 0};
std::vector<int> ringSettings = {0, 0, 0};
std::vector<std::pair<char, char>> plugboardSettings;
for (int i = 3; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--rotors" && i + 1 < argc) {
std::string rotorsArg = argv[++i];
sscanf(rotorsArg.c_str(), "%d,%d,%d", &rotorPositions[0], &rotorPositions[1], &rotorPositions[2]);
} else if (arg == "--ring" && i + 1 < argc) {
std::string ringArg = argv[++i];
sscanf(ringArg.c_str(), "%d,%d,%d", &ringSettings[0], &ringSettings[1], &ringSettings[2]);
} else if (arg == "--plugboard" && i + 1 < argc) {
std::string plugArg = argv[++i];
for (size_t j = 0; j < plugArg.size(); j += 3) {
if (j + 1 < plugArg.size() && plugArg[j + 2] == ',') {
plugboardSettings.emplace_back(plugArg[j], plugArg[j + 1]);
}
}
}
}
// mesajı büyük harflere çevir ve boşlukları '-' ile değiştir
std::transform(message.begin(), message.end(), message.begin(), ::toupper);
std::replace(message.begin(), message.end(), ' ', '-');
// Rotor, reflector ve plugboard ayarları
Rotor rotor1("EKMFLGDQVZNTOWYHXUSPAIBRCJ", 'Q', ringSettings[0]);
Rotor rotor2("AJDKSIRUXBLHWTMCQGZNPYFVOE", 'E', ringSettings[1]);
Rotor rotor3("BDFHJLCPRTXVZNYEIWGAKMUSQO", 'V', ringSettings[2]);
Reflector reflector("YRUHQSLDPXNGOKMIEBFZCWVJAT");
Plugboard plugboard;
for (const auto& plug : plugboardSettings) {
plugboard.addPlug(plug.first, plug.second);
}
Enigma enigma({rotor1, rotor2, rotor3}, reflector, plugboard);
enigma.setRotorPositions(rotorPositions);
if (operation == "--encrypt")
{
std::string encryptedMessage = enigma.encrypt(message);
std::cout << "Şifreli mesaj: " << encryptedMessage << std::endl;
}
else if (operation == "--decrypt")
{
std::string decryptedMessage = enigma.encrypt(message);
std::cout << "Çözülen mesaj: " << decryptedMessage << std::endl;
}
else
{
printUsage();
return 1;
}
return 0;
}