将 C++ 代码从一个程序转移到另一个程序
transfering C++ code from one programme to another
所以,我的朋友告诉我他设法构建了自己的 "Enigma Machine",但他使用的程序不适用于我的 Windows 版本。
我昨天安装了 Microsoft 的 visual studio,但无法让他的代码在我的代码上运行。我对编码还很年轻,我希望这里有人能帮助我。我相信问题出在库上,我已经尝试了所有我知道的方法,但我不确定我还需要做些什么,它给了我很多错误,并且忽略了预编译的头文件。
代码如下:
#include "iostream"
#include "cstdlib"
#include "string"
#include "stdafx.h" //I added this library because vstudio asked me to do so..?
#include "algorithm"
using namespace std;
int i, j, l, r1, r2, r3, n1, n2, n3, n4, rII, rIII;
string msg;
int rotor1[26] = { 4,10,12,5,11,6,3,16,21,25,13,19,14,22,24,7,23,20,18,15,0,8,1,17,2,9 };
int rotor2[26] = { 0,9,3,10,18,8,17,20,23,1,11,7,22,19,12,2,16,6,25,13,15,24,5,21,14,4 };
int rotor3[26] = { 1,3,5,7,9,11,2,15,17,19,23,21,25,13,24,4,8,22,6,0,10,12,20,18,16,14 };
int reflec[26] = { 24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19 };
char base[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
void RotorInput() {
cout << "Input initial positions (0 to 25):\n";
cout << "First rotor: ";
cin >> r1;
cout << "Second rotor: ";
cin >> r2;
cout << "Third rotor: ";
cin >> r3;
}
void RotorInitialization() {
rotate(rotor1, rotor1 + r1, rotor1 + 26);
rotate(rotor2, rotor2 + r2, rotor2 + 26);
rotate(rotor2, rotor2 + r2, rotor2 + 26);
}
void MessageInput() {
cout << "Input your message/code:\n";
getline(cin, msg);
getline(cin, msg);
}
void Encription() {
l = msg.size();
for (j = 0; j < l; j++) {
}
for (i = 0; i < l; i++) {
if (msg.at(i) == ' ') {
cout << " ";
}
else {
int x = distance(base, find(base, base + 26, msg.at(i)));
n1 = rotor1[x];
n2 = rotor2[n1];
n3 = rotor3[n2];
n4 = reflec[n3];
n3 = distance(rotor3, find(rotor3, rotor3 + 26, n4));
n2 = distance(rotor2, find(rotor2, rotor2 + 26, n3));
n1 = distance(rotor1, find(rotor1, rotor1 + 26, n2));
cout << base[n1];
rII = (i + r2 + 1) % 26;
rIII = (i + r3 + 1) % 676;
rotate(rotor1, rotor1 + 1, rotor1 + 26);
if (rII == 0) {
rotate(rotor2, rotor2 + 1, rotor2 + 26);
}
else {}
if (rIII == 0) {
rotate(rotor3, rotor3 + 1, rotor3 + 26);
}
else {}
}
}
}
int main()
{
RotorInput();
RotorInitialization();
MessageInput();
Encription();
cout << endl;
system("pause");
return 0;
}
提前致谢!
首先,预编译头包含应该在源文件的第一行。
此外,我会将所有标准库中的 "
替换为 <
或 >
分别替换为开盘价或收盘价。
对于在搜索 google 后最终来到这里的人来说,HEUR/QVM19.1.Malware.Gen 是 360 Total Security(防病毒)误报。只需将 VS 文件夹列入白名单。
我的问题在于我的代码没有以#include "stdafx.h" 开头,而当它以#include "stdafx.h" 开头时,我的病毒将程序标记为恶意软件。这就是所有这些混乱的原因。谢谢大家!
所以,我的朋友告诉我他设法构建了自己的 "Enigma Machine",但他使用的程序不适用于我的 Windows 版本。
我昨天安装了 Microsoft 的 visual studio,但无法让他的代码在我的代码上运行。我对编码还很年轻,我希望这里有人能帮助我。我相信问题出在库上,我已经尝试了所有我知道的方法,但我不确定我还需要做些什么,它给了我很多错误,并且忽略了预编译的头文件。
代码如下:
#include "iostream"
#include "cstdlib"
#include "string"
#include "stdafx.h" //I added this library because vstudio asked me to do so..?
#include "algorithm"
using namespace std;
int i, j, l, r1, r2, r3, n1, n2, n3, n4, rII, rIII;
string msg;
int rotor1[26] = { 4,10,12,5,11,6,3,16,21,25,13,19,14,22,24,7,23,20,18,15,0,8,1,17,2,9 };
int rotor2[26] = { 0,9,3,10,18,8,17,20,23,1,11,7,22,19,12,2,16,6,25,13,15,24,5,21,14,4 };
int rotor3[26] = { 1,3,5,7,9,11,2,15,17,19,23,21,25,13,24,4,8,22,6,0,10,12,20,18,16,14 };
int reflec[26] = { 24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19 };
char base[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
void RotorInput() {
cout << "Input initial positions (0 to 25):\n";
cout << "First rotor: ";
cin >> r1;
cout << "Second rotor: ";
cin >> r2;
cout << "Third rotor: ";
cin >> r3;
}
void RotorInitialization() {
rotate(rotor1, rotor1 + r1, rotor1 + 26);
rotate(rotor2, rotor2 + r2, rotor2 + 26);
rotate(rotor2, rotor2 + r2, rotor2 + 26);
}
void MessageInput() {
cout << "Input your message/code:\n";
getline(cin, msg);
getline(cin, msg);
}
void Encription() {
l = msg.size();
for (j = 0; j < l; j++) {
}
for (i = 0; i < l; i++) {
if (msg.at(i) == ' ') {
cout << " ";
}
else {
int x = distance(base, find(base, base + 26, msg.at(i)));
n1 = rotor1[x];
n2 = rotor2[n1];
n3 = rotor3[n2];
n4 = reflec[n3];
n3 = distance(rotor3, find(rotor3, rotor3 + 26, n4));
n2 = distance(rotor2, find(rotor2, rotor2 + 26, n3));
n1 = distance(rotor1, find(rotor1, rotor1 + 26, n2));
cout << base[n1];
rII = (i + r2 + 1) % 26;
rIII = (i + r3 + 1) % 676;
rotate(rotor1, rotor1 + 1, rotor1 + 26);
if (rII == 0) {
rotate(rotor2, rotor2 + 1, rotor2 + 26);
}
else {}
if (rIII == 0) {
rotate(rotor3, rotor3 + 1, rotor3 + 26);
}
else {}
}
}
}
int main()
{
RotorInput();
RotorInitialization();
MessageInput();
Encription();
cout << endl;
system("pause");
return 0;
}
提前致谢!
首先,预编译头包含应该在源文件的第一行。
此外,我会将所有标准库中的 "
替换为 <
或 >
分别替换为开盘价或收盘价。
对于在搜索 google 后最终来到这里的人来说,HEUR/QVM19.1.Malware.Gen 是 360 Total Security(防病毒)误报。只需将 VS 文件夹列入白名单。
我的问题在于我的代码没有以#include "stdafx.h" 开头,而当它以#include "stdafx.h" 开头时,我的病毒将程序标记为恶意软件。这就是所有这些混乱的原因。谢谢大家!