#include<iostream>
#include<ctime>

using namespace std;

//加密
void encode(char *pstr, int *pkey){
    int len = strlen(pstr);//获取长度
    for (int i = 0; i < len; i++)
        *(pstr + i) = *(pstr + i) ^ i;
}

//解密
void decode(char *pstr, int *pkey){
    int len = strlen(pstr);
    for (int i = 0; i < len; i++)
        *(pstr + i) = *(pstr + i) ^ i;
}


int main()
{
    int key[] = { 1, 2, 3, 4, 5 };//加密字符
    char s[] = "123456";
    char *p = s;
    cout << "加密前:" << p << endl;
    encode(s, key);//加密
    cout << "加密后:" << p << endl;
    decode(s, key);//解密
    cout << "解密后:" << p << endl;

    int c;
    cin >> c;
    return 0;
}

 

转载于:https://www.cnblogs.com/kaishan1990/p/7055240.html

更多推荐