【c++範例】字串位移加密程式

by - 清晨5:29


#include <iostream>
#include <fstream>
using namespace std;
char* encode(char*);
char* decode(char*);
int main(void)
{
  char ch,str[80];
  cout<<"請輸入字串:";
  gets(str);
  cout<<"您要 1)加密 2)解密 :";
  cin>>ch;
  if(ch == '1') {
    cout<<"After encode : ";
    cout<<encode(str);
  } else if (ch == '2') {
    cout<<"After decode :";
    cout<<decode(str);
  } else
    cout<<"Unknown input";
  return 0;
}
char* encode(char *str)
{
      char *r=str;
      while(*str) {
        *str = *str + 13;
        str++;
      }  
      return r;
}
char* decode(char *str)
{
      char *r=str;
      while(*str) {
        *str = *str - 13;
        str++;
      }
      return r;
}

你可能會喜歡

0 意見