有时候需要自己弄个简单的加密解密算法。
#include<iostream>
#include<stdio.h>
using namespace std;
const char* encrypt(const char* ip, unsigned int key[], int len)//加密函数
{
//要保证(x + n)% 126 + 32 < 126 所以要保证n < 94
//也就是key数组里面必须为小于94的数
//unsigned int b[]={2,7,18,23,91,5,4};
int i=0;
char* dest = (char*)calloc(strlen(ip), sizeof(char));
while(*ip)
{
int x = (int)(*ip) + key[i % len];
if(x>126){
x = x % 126 + 32;
}
*dest = x;
i++,ip++,dest++;
}
dest -= i;
ip -= i;
printf("[%s=>%s]\n", ip, dest);
return dest;
}
const char* decrypt(const char* src, unsigned int key[], int len){
char* dest = strdup(src);
//int b[]={2,7,18,23,91,5,4};
int i=0;
while(*dest)
{
int x = (int)*dest - key[i % len];
if( x < 32){
x = x - 32 + 126;
}
*dest = x;
i++,dest++;
}
dest -= i;
return dest;
}
int main(){
unsigned int b[]={2,7,18,23,91,5,4};
const char* ss = encrypt("/libdje1.so", b, 7);
printf("%s\n", decrypt(ss, b, 7));
const char * e100 = encrypt("100", b, 7);
const char* e101 = encrypt("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", b, 7);
printf("%s\n", e101);
const char* xx = "1z-,,iixpu|p4w{z(|j4gr|Azmz41j$.cwis6'z^qmpnqxsfmnht%bdjtl%.bsgkl'";
printf("%s\n", decrypt(xx, b, 7));
printf("%s\n", encrypt("&cpu_freq=", b, 7));
const char* cpu_freq = "(j$.\\kvgxO";
printf("%s\n", decrypt(cpu_freq, b, 7));
return 1;
}
评论区