Programming implementation of the EN-Grid encryption Machine (c + +)

Source: Internet
Author: User
Tags reflector

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 + +)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.