Advertisement
Guest User

Enigma thins updated

a guest
Jan 19th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <iostream>
  4. char offset(char Ichar, int setting);
  5. char encryptchar(char Ichar);
  6. void encrypstring(void);
  7.  
  8. class rotor{
  9. public:
  10.     std::string forwards = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  11.     std::string backwards = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
  12.     int notch;
  13.     int setting;
  14.  
  15.   //  rotor();//make later if i even need to
  16.   //  ~rotor();
  17. };
  18.  
  19.  rotor rotorR;
  20.  rotor rotorM;
  21.  rotor rotorL;
  22.  rotor reflector;
  23.  rotor plug;
  24.  
  25.  
  26. int main(){
  27.  
  28.   rotorR.forwards = "EKMFLGDQVZNTOWYHXUSPAIBRCJ";// gotta figureout how to do this
  29.   rotorR.backwards = "UWYGADFPVZBECKMTHXSLRINQOJ";// currently gives compile erros
  30.  
  31.  
  32. }
  33.  
  34.  
  35. void encrypstring(){
  36.   /*
  37.   while (messagle left){//FO
  38.     //get char//FO
  39.     outchar = encryptchar(inchar);
  40.     rotorR.setting++;
  41.     if (rotorR.setting>25){//go from 26 to 0 instead of 27 because circles
  42.       rotorR.setting=rotorR.setting-26;
  43.     }
  44.     if(midsteppedlastturn==true){
  45.       rotorM.setting++;
  46.       if (rotorM.setting>25){
  47.         rotorM.setting=rotorM.setting-26;
  48.       }
  49.       midsteppdlastturn=false;
  50.     }
  51.     if(rotorR.setting == rotorR.notch){
  52.       setM++;
  53.       if (rotorM.setting>25){
  54.         rotorM.setting=rotorM.setting-26;
  55.       }
  56.       midsteppedlastturn=true;
  57.     }
  58.     if(rotorM.setting == rotorM.notch){
  59.       rotorL.setting++;
  60.       if (rotorL.setting>25){
  61.         rotorL.setting=rotorL.setting-26;
  62.       }
  63.     } //probably should have made an overflow function instead of copy pasting the code over and over.
  64.     // put char in string;//FO
  65.   }
  66.   */
  67.  
  68.  
  69. }
  70.  
  71. char encryptchar(char Ichar){
  72.  
  73.   std::cout<<Ichar<< std::endl;
  74.   Ichar = plug.forwards.at(Ichar-65);
  75.   std::cout<<Ichar<< std::endl;
  76.   Ichar=  offset(Ichar,rotorR.setting);
  77.   std::cout<<Ichar<< std::endl;
  78.   Ichar =  rotorR.forwards.at(Ichar-65);//this is using the rotor
  79.   std::cout<<Ichar<< std::endl;
  80.   Ichar = offset(Ichar,rotorR.setting);
  81.   std::cout<<Ichar<< std::endl;
  82.   Ichar = offset(Ichar,rotorM.setting);
  83.   std::cout<<Ichar<< std::endl;
  84.   Ichar =  rotorM.forwards.at(Ichar-65);
  85.   std::cout<<Ichar<< std::endl;
  86.   Ichar = offset(Ichar,rotorM.setting);
  87.   std::cout<<Ichar<< std::endl;
  88.   Ichar = offset(Ichar,rotorL.setting);
  89.   std::cout<<Ichar<< std::endl;
  90.   Ichar = rotorL.forwards.at(Ichar-65);
  91.   std::cout<<Ichar<< std::endl;
  92.   Ichar = offset(Ichar,rotorL.setting);
  93.   std::cout<<Ichar<< std::endl;
  94.   Ichar = reflector.forwards.at(Ichar-65);
  95.   std::cout<<Ichar<< std::endl;
  96.   Ichar = offset(Ichar,-rotorL.setting);
  97.   std::cout<<Ichar<< std::endl;
  98.   Ichar = rotorL.backwards.at(Ichar-65);
  99.   std::cout<<Ichar<< std::endl;
  100.   Ichar = offset(Ichar,-rotorL.setting);
  101.   std::cout<<Ichar<< std::endl;
  102.   Ichar = offset(Ichar,-rotorM.setting);
  103.   std::cout<<Ichar<< std::endl;
  104.   Ichar = rotorM.backwards.at(Ichar-65);
  105.   std::cout<<Ichar<< std::endl;
  106.   Ichar = offset(Ichar,-rotorM.setting);
  107.   std::cout<<Ichar<< std::endl;
  108.   Ichar = offset(Ichar,-rotorR.setting);
  109.   std::cout<<Ichar<< std::endl;
  110.   Ichar = rotorR.backwards.at(Ichar-65);
  111.   std::cout<<Ichar<< std::endl;
  112.   Ichar = offset(Ichar,-rotorR.setting);
  113.   std::cout<<Ichar<< std::endl;
  114.   Ichar = plug.backwards.at(Ichar-65);
  115.   std::cout<<Ichar<< std::endl;
  116.  
  117.   return Ichar;
  118.  
  119. }
  120.  
  121. char offset(char Ichar, int setting){
  122.   int num = Ichar - 65 + setting;
  123.   if (num>25){
  124.     num=num-26;
  125.   }
  126.   else if (num<0){
  127.     num=num+26;
  128.   };  
  129.   return ('A'+num);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement