#include <iostream>#include<cstdio>using namespacestd;voidInit_pass_table (Char(&code_table) [ -][ -]){//(cannot be used as a one-dimensional array to see other Problems)code_table[0][0]='0'; for(intI=0;i< -; i++) {code_table[0][1+i]='a'+i; } for(intI=0;i< -; i++) {code_table[1+i][0]='a'+i; } for(intI=0;i< -; i++){ for(intj=0;j< -; j + +){ if(i+j> -) {code_table[i+1][j+1]='a'+j+i- -; } ElseCode_table[i+1][j+1]='a'+j+i; } }}voidInput_text (intAChar* Text) {//Enter clear text, ciphertext, or Password;//this method is not used; I forgot to delete it.Cin.sync (); //for (int I=0;i<a;i++) {Cin.Get(text,a+1);//There may be a problem here;//cin>>text[i];}intText_input (Chara[ +]) {gets (a); intD=0; for(intI=0; a[i]!=' /'; i++){ //cout<<a[i]<< ";d++; } returnd;}voidMake_pass_test (intDCharAintEChar* b,Charc[ -][ -],intFlag) {//generate ciphertext; A is plaintext; B is the secret key .//cout<<c<<endl; /*int symbol=d; int ming_num=0; Char new_mingwen[d]; For (int i=0;i<d;i++) {//clear text To remove the length of the space; if (a[i]== ") {continue; } ming_num++; } cout<< "effective length of clear text" <<ming_num<<endl; For (int I=0;i<symbol;i++) {new_mingwen[i]=a[i]; }//cout<<new_mingwen<<endl; Cout<<sizeof (new_mingwen) <<endl;//has not been updated; for (int i=0;i<symbol;i++) {//new_mingwen[] spaces are removed, fortunately, the bottom and secret key table; if (new_mingwen[i]== ") {for (int j=i;j<d-1;j++) {new_mingwen[j]=new_mingwen [j+1]; } symbol--; }} if (e>ming_num) {cout<< "error" <<endl; }*/ Charnew_miyao[d]; intcf=0; if(e<d) {//The secret key is made sing Woo (plaintext or Ciphertext) one by one corresponding form; for(intI=0; i<d;i++){ if(a[i]==' ') {new_miyao[i]=a[i]; CF++; Continue; } Else{ inth=i-cf; while(h>=E) {h-=e; } new_miyao[i]=b[h]; } } //cout<<new_miyao<<endl; } if(flag==1){ for(intI=0; I<d;i++) {//one by one corresponds in the table value; if(a[d]==' ') {cout<<' '; Continue; } cout<<c[(int) (a[i]- the)][(int) (new_miyao[i]- the)]; } cout<<endl; } if(flag==2){//the comparison table finds clear text; for(intI=0; i<d;i++){ if(new_miyao[i]==' ') {cout<<' '; Continue; } for(intj=0;j< -; j + +){ if(c[(int) (new_miyao[i]- the) {][j]==a[i]) {//find the corresponding plaintext letter;cout<<c[1][j]; break; } }} cout<<endl; }}intmain () {Charcode_table[ -][ -]={0}; Init_pass_table (code_table); intchoose; while(1) {cout<<"Choose encode or decode (Enter ' 1 ' stand for encode; ' 2 '-decode):"<<endl; cout<<"If you want out, please Enter ' 3 ';"<<endl; CIN>>choose; if(choose==1){ intinput_size,key_size; cout<<"Please enter clear text (can contain spaces)"<<endl; Charmingwen[ +]; Gets (mingwen); Input_size=Text_input (mingwen); cout<<"Please enter a secret key"<<endl; Charmiyao[ +]; Key_size=Text_input (miyao); Make_pass_test (input_size,mingwen,key_size,miyao,code_table,1); } Else if(choose==2){ intinput_size,key_size; cout<<"Please enter ciphertext (can contain spaces)"<<endl; Charmiwen[ +]; Gets (miwen); Input_size=Text_input (miwen); cout<<"Please enter a secret key"<<endl; Charmiyao[ +]; Key_size=Text_input (miyao); Make_pass_test (input_size,miwen,key_size,miyao,code_table,2); } Else if(choose==3){ break; } } return 0;}
Virginia Password encryption, decryption algorithm (crack not yet);