I believe you see the "imitation of the Game", will be very curious about the encryption method of the Second World War, I am no exception, so a program to achieve the Engma encryption machine, the biggest feature of the machine is a reflexive, as long as the initial setting is consistent, then it is reflexive, such as input A, after the encryption B, Under the same settings, input B will definitely output a.
A detailed introduction can be seen here:
http://www.zhihu.com/question/28397034
The following I realized is a simplified version, no power strip (if added to is also very simple, just need to replace the specified letter can be, here for brevity not added)
#include <string>#include <iostream>using namespace STD;stringEnigma (stringInput) {intCodeintn[6] = { -,2,5,4,Ten, at};//define 6 rotors intNsize=6;stringOutput for(inti =0; I < input.size (); i++) {if(input[i]=="') {output+="';Continue;} Code = input[i]-' A '; for(intj =0; J < nsize;j++) {code = (code + N[J])% -; }if(code%2==0) code++;Elsecode--;//Reflector If even +1, odd-1, the reflector as long as the letter 22 can be paired. for(intj = nsize-1; J >=0; j--) {code = Code-n[j];if(code<0) code= -+code; } n[0]++; for(intj =0; J < nsize-1; J + +) {if(n[j]>= -) {n[j +1]++; N[J] =0; }} n[nsize-1] = n[nsize-1] % -; Output + = code+' A '; }returnOutput;}intMain () {stringtext="Hey Hey HelloWorld";stringMiwen=enigma (text);cout<<"Ciphertext:"<< miwen<< Endl;cout<<"Clear text:"<< Enigma (Miwen) << Endl;return 0;}
Programming implementation of the EN-Grid encryption Machine (c + +)