當前位置:編程學習大全網 - 編程軟體 - C++密碼編程

C++密碼編程

#include<iostream>

//#include <afxcoll.h>

//#include<algorithm>

#include <windows.h>

#include<string>

using namespace std;

void main()

{

int i=0,key[7]={4,9,6,2,8,7,3};

char ch;

string pass,text;

cout<<"請輸入明文:"<<endl;

//----------------------加密過程

for(ch;((ch=cin.get())!='\n');)

{

ch=ch+key[i++];

if(i>6||ch=='\n')

i=0;

if(ch>122||ch<32)

ch=ch%122+32;

pass=pass+ch;

}

cout<<"密文是:\n"<<pass<<endl;

//----------------------解密過程

char *strs=new char[pass.length()];//將字符串轉換為字符數組

strs[pass.length()]='\0';

pass.copy(strs,pass.length(),0);

i=0;

for(int j=0;j<pass.length();j++)

{

ch=strs[j];

ch-=key[i++];

if(i>6||ch=='\n')

i=0;

if(ch<32) // 由於妳的加密算法並不是壹壹對應,即不壹定可逆,需要擴展

{ ch=ch-32;

ch=ch+122;

}

text=text+ch;

}

cout<<"解密後是:\n"<<text<<endl;

delete[]strs;

}

  • 上一篇:數控編程怎麽刀補?
  • 下一篇:在VC環境下,如何編程從二維數組A的每壹行中選取最大值組成壹維數組B,並輸出數組B .
  • copyright 2024編程學習大全網