c++字符串简单加密

c++字符串简单加密View Code

#include "stdafx.h"
#include<iostream>
#include<ctime>

using namespace std;
void Makecode(char *pstr,int *pkey);
void Cutecode(char *pstr,int *pkey);
int _tmain(int argc, _TCHAR* argv[])
{
    int key[]={1,2,3,4,5};//加密字符
    char s[]="www.xiaozhuanggushi.com";
    char *p=s;
    cout<<"加密前:"<<p<<endl;
    Makecode(s,key);//加密
    cout<<"加密后:"<<p<<endl;    
    Cutecode(s,key);//解密
    cout<<"解密后:"<<p<<endl;

    int c;
    cin>>c;    
    return 0;
}
//单个字符异或运算
char MakecodeChar(char c,int key){
    return c=c^key;
}
//单个字符解密
char CutcodeChar(char c,int key){
    return c^key;
}

//加密
void Makecode(char *pstr,int *pkey){
    int len=strlen(pstr);//获取长度
    for(int i=0;i<len;i++)
        *(pstr+i)=MakecodeChar(*(pstr+i),pkey[i%5]);
}

//解密
void Cutecode(char *pstr,int *pkey){
    int len=strlen(pstr);
    for(int i=0;i<len;i++)
        *(pstr+i)=CutcodeChar(*(pstr+i),pkey[i%5]);
}

原文链接: https://www.cnblogs.com/clc2008/archive/2012/03/12/2392495.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    c++字符串简单加密

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/43959

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 下午8:37
下一篇 2023年2月8日 下午8:37

相关推荐