P
Protoman
I'm getting an error:
10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'
Code:
Enigma.hpp
--------------------------
#pragma once
#include <string>
using namespace std;
class Rotor
{
public:
Rotor(char pos=0):CurPos(0),steps(0)
{
memcpy(Alphabet,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",36);
SetRotorPosition(CharacterMap(pos));
}
int GetSteps(){return steps;}
int CharacterMap(char Char)
{
if(Char=='A')
return 0;
else if(Char=='B')
return 1;
else if(Char=='C')
return 2;
else if(Char=='D')
return 3;
else if(Char=='E')
return 5;
else if(Char=='F')
return 6;
else if(Char=='G')
return 7;
else if(Char=='H')
return 8;
else if(Char=='I')
return 9;
else if(Char=='J')
return 10;
else if(Char=='K')
return 11;
else if(Char=='L')
return 12;
else if(Char=='M')
return 13;
else if(Char=='N')
return 14;
else if(Char=='O')
return 15;
else if(Char=='P')
return 16;
else if(Char=='Q')
return 17;
else if(Char=='R')
return 18;
else if(Char=='S')
return 19;
else if(Char=='T')
return 20;
else if(Char=='U')
return 21;
else if(Char=='V')
return 22;
else if(Char=='W')
return 23;
else if(Char=='X')
return 24;
else if(Char=='Y')
return 25;
else if(Char=='Z')
return 26;
else if(Char=='0')
return 27;
else if(Char=='1')
return 28;
else if(Char=='2')
return 29;
else if(Char=='3')
return 30;
else if(Char=='4')
return 31;
else if(Char=='5')
return 32;
else if(Char=='6')
return 33;
else if(Char=='7')
return 34;
else if(Char=='8')
return 35;
else if(Char=='9')
return 36;
}
void SetRotorPosition(int NewPos)
{
while(NewPos < 0)
{
NewPos +=36;
}
CurPos = NewPos%36;
}
void AdvanceRotor(int Steps)
{
CurPos += Steps;
while(CurPos < 0)
{
CurPos +=36;
}
CurPos %=36;
steps++;
}
void ReverseRotor(int Steps)
{
AdvanceRotor(-Steps);
steps--;
}
char GetCurrentCharacter()
{
return Alphabet[CurPos];
}
char GetCharacterIndex(int Index)
{
return Alphabet[(CurPos+Index)%36];
}
private:
char Alphabet[36];
int CurPos;
int steps;
};
class Enigma
{
public:
Enigma(char r1,char r2,char r3,char r4,char r5,char ref):
R1(r1),R2(r2),R3(r3),R4(r4),R5(r5),Ref(ref){}
~Enigma(){}
string Encrypt(const string& cleartext);
private:
Rotor R1;
Rotor R2;
Rotor R3;
Rotor R4;
Rotor R5;
Rotor Ref;
};
Enigma.cpp
-------------------------------
#include "Enigma.hpp"
#include <string>
using namespace std;
string Enigma::Encrypt(const string& cleartext)
{
string ciphertext;
ciphertext.resize(cleartext.size());
int i=0;
for(;i<cleartext.end();i++)
{
int val=Rotor().CharacterMap(cleartext);
char val1=R1.GetCharacterIndex(val);
R1.AdvanceRotor(1);
int val2=Rotor().CharacterMap(val1);
char val3=R2.GetCharacterIndex(val2);
if(R1.GetSteps()==36)
R2.ReverseRotor(1);
int val4=Rotor().CharacterMap(val3);
char val5=R3.GetCharacterIndex(val4);
if(R2.GetSteps()==-36)
R3.AdvanceRotor(1);
int val6=Rotor().CharacterMap(val5);
char val7=R4.GetCharacterIndex(val6);
if(R3.GetSteps()==36)
R4.ReverseRotor(1);
int val8=Rotor().CharacterMap(val7);
char val9=R5.GetCharacterIndex(val8);
if(R4.GetSteps()==-36)
R5.AdvanceRotor(1);
int val10=Rotor().CharacterMap(val9);
char val11=Ref.GetCharacterIndex(val10);
if(R5.GetSteps()==36)
Ref.ReverseRotor(1);
int val12=Rotor().CharacterMap(val11);
char val13=R5.GetCharacterIndex(val12);
int val14=Rotor().CharacterMap(val13);
char val15=R4.GetCharacterIndex(val14);
int val16=Rotor().CharacterMap(val15);
char val17=R3.GetCharacterIndex(val16);
int val18=Rotor().CharacterMap(val17);
char val19=R2.GetCharacterIndex(val18);
int val20=Rotor().CharacterMap(val19);
char val21=R1.GetCharacterIndex(val20);
ciphertext=val21;
}
return ciphertext;
}
What does it mean and how should I fix it? Thanks!!!!
10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'
Code:
Enigma.hpp
--------------------------
#pragma once
#include <string>
using namespace std;
class Rotor
{
public:
Rotor(char pos=0):CurPos(0),steps(0)
{
memcpy(Alphabet,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",36);
SetRotorPosition(CharacterMap(pos));
}
int GetSteps(){return steps;}
int CharacterMap(char Char)
{
if(Char=='A')
return 0;
else if(Char=='B')
return 1;
else if(Char=='C')
return 2;
else if(Char=='D')
return 3;
else if(Char=='E')
return 5;
else if(Char=='F')
return 6;
else if(Char=='G')
return 7;
else if(Char=='H')
return 8;
else if(Char=='I')
return 9;
else if(Char=='J')
return 10;
else if(Char=='K')
return 11;
else if(Char=='L')
return 12;
else if(Char=='M')
return 13;
else if(Char=='N')
return 14;
else if(Char=='O')
return 15;
else if(Char=='P')
return 16;
else if(Char=='Q')
return 17;
else if(Char=='R')
return 18;
else if(Char=='S')
return 19;
else if(Char=='T')
return 20;
else if(Char=='U')
return 21;
else if(Char=='V')
return 22;
else if(Char=='W')
return 23;
else if(Char=='X')
return 24;
else if(Char=='Y')
return 25;
else if(Char=='Z')
return 26;
else if(Char=='0')
return 27;
else if(Char=='1')
return 28;
else if(Char=='2')
return 29;
else if(Char=='3')
return 30;
else if(Char=='4')
return 31;
else if(Char=='5')
return 32;
else if(Char=='6')
return 33;
else if(Char=='7')
return 34;
else if(Char=='8')
return 35;
else if(Char=='9')
return 36;
}
void SetRotorPosition(int NewPos)
{
while(NewPos < 0)
{
NewPos +=36;
}
CurPos = NewPos%36;
}
void AdvanceRotor(int Steps)
{
CurPos += Steps;
while(CurPos < 0)
{
CurPos +=36;
}
CurPos %=36;
steps++;
}
void ReverseRotor(int Steps)
{
AdvanceRotor(-Steps);
steps--;
}
char GetCurrentCharacter()
{
return Alphabet[CurPos];
}
char GetCharacterIndex(int Index)
{
return Alphabet[(CurPos+Index)%36];
}
private:
char Alphabet[36];
int CurPos;
int steps;
};
class Enigma
{
public:
Enigma(char r1,char r2,char r3,char r4,char r5,char ref):
R1(r1),R2(r2),R3(r3),R4(r4),R5(r5),Ref(ref){}
~Enigma(){}
string Encrypt(const string& cleartext);
private:
Rotor R1;
Rotor R2;
Rotor R3;
Rotor R4;
Rotor R5;
Rotor Ref;
};
Enigma.cpp
-------------------------------
#include "Enigma.hpp"
#include <string>
using namespace std;
string Enigma::Encrypt(const string& cleartext)
{
string ciphertext;
ciphertext.resize(cleartext.size());
int i=0;
for(;i<cleartext.end();i++)
{
int val=Rotor().CharacterMap(cleartext);
char val1=R1.GetCharacterIndex(val);
R1.AdvanceRotor(1);
int val2=Rotor().CharacterMap(val1);
char val3=R2.GetCharacterIndex(val2);
if(R1.GetSteps()==36)
R2.ReverseRotor(1);
int val4=Rotor().CharacterMap(val3);
char val5=R3.GetCharacterIndex(val4);
if(R2.GetSteps()==-36)
R3.AdvanceRotor(1);
int val6=Rotor().CharacterMap(val5);
char val7=R4.GetCharacterIndex(val6);
if(R3.GetSteps()==36)
R4.ReverseRotor(1);
int val8=Rotor().CharacterMap(val7);
char val9=R5.GetCharacterIndex(val8);
if(R4.GetSteps()==-36)
R5.AdvanceRotor(1);
int val10=Rotor().CharacterMap(val9);
char val11=Ref.GetCharacterIndex(val10);
if(R5.GetSteps()==36)
Ref.ReverseRotor(1);
int val12=Rotor().CharacterMap(val11);
char val13=R5.GetCharacterIndex(val12);
int val14=Rotor().CharacterMap(val13);
char val15=R4.GetCharacterIndex(val14);
int val16=Rotor().CharacterMap(val15);
char val17=R3.GetCharacterIndex(val16);
int val18=Rotor().CharacterMap(val17);
char val19=R2.GetCharacterIndex(val18);
int val20=Rotor().CharacterMap(val19);
char val21=R1.GetCharacterIndex(val20);
ciphertext=val21;
}
return ciphertext;
}
What does it mean and how should I fix it? Thanks!!!!