単純復号化
4688 ワード
import android.util.Base64;
public class Simplede {
public static byte[] doencrypt(byte[] data, byte[] keyData) {
int keyIndex = 0;
for (int x = 0; x < data.length; x++) {
data[x] = (byte) (data[x] ^ keyData[keyIndex]);
if (++keyIndex == keyData.length) {
keyIndex = 0;
}
}
return data;
}
public static String encrypt(String strOld, String strKey) {
byte[] data=doencrypt(strOld.getBytes(), strKey.getBytes());
return Base64.encodeToString(data, Base64.DEFAULT);
}
public static String decrypt(String strOld, String strKey) {
byte[] mingwen=Base64.decode(strOld.getBytes(), Base64.DEFAULT);
byte[] data=doencrypt(mingwen, strKey.getBytes());
return new String(data);
}
public static void main(String[] args) {
String key="10241314";
String seed="test ";
for(int i=0;i<30;i++)
{
seed=seed+i;
System.out.println(seed);
// :
String data=encrypt(seed,key);
System.out.println(data);
// :
System.out.println(decrypt(data,key));
}
}
}
Java for cpp
public class SimpledeForCPP {
/*
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
unsigned char* myobfuscate(unsigned char *s) {
unsigned char key, mod, len;
int i;
unsigned char* d;
key = s[0];
mod = 0x66;
len = strlen((const char*)s);
d = (unsigned char *)malloc(len + 1);
// zero terminate the string
memset(d, 0x00, len + 1);
for (i = 0; i < len; i++) {
d[i] = s[i] ^ mod;
}
d[len] = 0;
return d;
}
// '\x12' , x, X
static unsigned char mystr[]="\xc\x7\x10\x7\x7\x8\x2\x14\x9\xf\x2";
static unsigned char mychinese[]="\xb0\xb6\xa8\xa2\x12\x3\x15\x12\xc\x7\x10\x7\x7\x8\x2\x14\x9\xf\x2\xa8\xb4\xa6\xd2\xb1\xb2\x2c\x7\x10\x7\x46\x5\x16\x16\xda\xb5\xa5\xba";
int main(int argc, char *argv[])
{
printf("%s
",deobfuscate(proc_kallsyms));
printf("%s
",myobfuscate(mystr));
printf("%s
",myobfuscate(mychinese));
getch();
return 0;
}
*/
public static void main(String[] args) throws Exception {
StringBuffer sb=new StringBuffer();
byte[] data=" testjavaandroid Java cpp ".getBytes("GBK");
byte[] buffer=new byte[data.length];
for (int x = 0; x < data.length; x++) {
buffer[x] = (byte) (data[x] ^ 0x66);
int v = buffer[x] & 0xFF;
sb.append("\\x"+Integer.toHexString(v));
}
//System.out.println(new String(buffer));
System.out.println(sb.toString());
}
}
cpp string
char* simpleed(char *str,const char *pwd)
{
int j0=0;
int j=-1;
int len=0;
//
while(pwd[++j0]);
len=strlen(str);
char* code=new char[len+1];
for (unsigned int i=0;i<strlen(str);i++)
{
if(j>=j0)
{
j=0;
}else{
j++;
}
printf("index=%d
",j);
code[i]=str[i]^pwd[j];/* fp2 */
}
code[len]='\0';
return code;
}
int main( int argc, char* argv[] )
{
char* str="abcdefghijklmn test";
const char *pwd="1024key";
printf("%s
",str);
str=simpleed(str,pwd);
printf("%s
",str);
OutputDebugStringA(str);
str=simpleed(str,pwd);
printf("%s
",str);
OutputDebugStringA(str);
getch();
return 0;
}
char* simpleed(char *str,const char *pwd)
{
int j0=0;
int j=-1;
int len=0;
//
while(pwd[++j0]);
len=strlen(str);
char* code=new char[len+1];
for (unsigned int i=0;i<len;i++)
{
if(j>=j0)
{
j=0;
}else{
j++;
}
//printf("index=%d
",j);
code[i]=str[i]^0x77;/* fp2 */
}
code[len]='\0';
return code;
}