c++简单的异或加密

// encripe_test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//


#include <string>
#include <iostream>

using namespace std;

//int key[] = { 1,2,3,4,5,6,7 };
int key[] = { 3,4,2,5,7,8,11 };
void encryption(string& c, int key[]) {
    int len = c.size();
    for (int i = 0; i < len; i++) {
        c[i] = c[i] ^ key[i % 7];
    }
}
void decode(string& c, int key[]) {
    int len = c.size();
    for (int i = 0; i < len; i++) {
        c[i] = c[i] ^ key[i % 7];
    }
}

int main(int argc, char* argv[]) {
    std::string str = "hello world!";
    std::cout << "原文:" << str << std::endl;
    encryption(str, key);
    std::cout << "加密后密文:" << str << std::endl;
    decode(str, key);
    std::cout << "解密后密文:" << str << std::endl;
    getchar();
    return 0;
}

 

posted @ 2022-03-09 21:27  leochan007  阅读(383)  评论(0编辑  收藏  举报