随机异或加密源码
程序代码:
#include <iostream> #include <ctime> #include <cstdlib> #include <assert.h> const int M=100; class somes{ private: inline int randnum() { return rand()%99999+1; } inline void randnumInit() { srand((unsigned int)time(0)); } char* Conversion(char* s1,char* s2,int n); char Mi[M]; public: somes(char* s); ~somes() {} inline char* returnMi() { //std::cout << "Mi:len " << strlen(Mi) << std::endl; //std::cout << "Mi:sizeof " << sizeof(Mi) << std::endl; return Mi; } }; somes::somes(char* s) { memset(Mi,0,sizeof(char)*M); randnumInit(); assert(Conversion(Mi,s,randnum())); } char* somes::Conversion(char *s1, char *s2, int n) { int i=0; while (*s2!='\0') { s1[i]=*s2^n; ++i; ++s2; } s1[i]='\0'; return s1; }
[ 本帖最后由 longlong89 于 2010-10-4 22:17 编辑 ]