Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <iostream>
- char offset(char Ichar, int setting);
- char encryptchar(char Ichar);
- void encrypstring(void);
- class rotor{
- public:
- std::string forwards = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- std::string backwards = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
- int notch;
- int setting;
- // rotor();//make later if i even need to
- // ~rotor();
- };
- rotor rotorR;
- rotor rotorM;
- rotor rotorL;
- rotor reflector;
- rotor plug;
- int main(){
- rotorR.forwards = "EKMFLGDQVZNTOWYHXUSPAIBRCJ";// gotta figureout how to do this
- rotorR.backwards = "UWYGADFPVZBECKMTHXSLRINQOJ";// currently gives compile erros
- }
- void encrypstring(){
- /*
- while (messagle left){//FO
- //get char//FO
- outchar = encryptchar(inchar);
- rotorR.setting++;
- if (rotorR.setting>25){//go from 26 to 0 instead of 27 because circles
- rotorR.setting=rotorR.setting-26;
- }
- if(midsteppedlastturn==true){
- rotorM.setting++;
- if (rotorM.setting>25){
- rotorM.setting=rotorM.setting-26;
- }
- midsteppdlastturn=false;
- }
- if(rotorR.setting == rotorR.notch){
- setM++;
- if (rotorM.setting>25){
- rotorM.setting=rotorM.setting-26;
- }
- midsteppedlastturn=true;
- }
- if(rotorM.setting == rotorM.notch){
- rotorL.setting++;
- if (rotorL.setting>25){
- rotorL.setting=rotorL.setting-26;
- }
- } //probably should have made an overflow function instead of copy pasting the code over and over.
- // put char in string;//FO
- }
- */
- }
- char encryptchar(char Ichar){
- std::cout<<Ichar<< std::endl;
- Ichar = plug.forwards.at(Ichar-65);
- std::cout<<Ichar<< std::endl;
- Ichar= offset(Ichar,rotorR.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = rotorR.forwards.at(Ichar-65);//this is using the rotor
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,rotorR.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,rotorM.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = rotorM.forwards.at(Ichar-65);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,rotorM.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,rotorL.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = rotorL.forwards.at(Ichar-65);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,rotorL.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = reflector.forwards.at(Ichar-65);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,-rotorL.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = rotorL.backwards.at(Ichar-65);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,-rotorL.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,-rotorM.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = rotorM.backwards.at(Ichar-65);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,-rotorM.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,-rotorR.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = rotorR.backwards.at(Ichar-65);
- std::cout<<Ichar<< std::endl;
- Ichar = offset(Ichar,-rotorR.setting);
- std::cout<<Ichar<< std::endl;
- Ichar = plug.backwards.at(Ichar-65);
- std::cout<<Ichar<< std::endl;
- return Ichar;
- }
- char offset(char Ichar, int setting){
- int num = Ichar - 65 + setting;
- if (num>25){
- num=num-26;
- }
- else if (num<0){
- num=num+26;
- };
- return ('A'+num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement