-
Notifications
You must be signed in to change notification settings - Fork 10
/
str-crypt.c
executable file
·34 lines (28 loc) · 937 Bytes
/
str-crypt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <string.h>
#include <jni.h>
#include <stdio.h>
void xor_crypt(char *key, char *str, int str_len);
jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
return JNI_VERSION_1_4;
}
JNIEXPORT jstring JNICALL
Java_org_cf_nativeharness_Cryptor_decryptString( JNIEnv *env,
jobject thiz,
jstring encryptedString )
{
// Explicitly cast to char * to avoid warning:
// initializing 'char *' with an expression of type 'const char *'
// We're going to be changing bytes in xor_crypt
char *str = (char *)(*env)->GetStringUTFChars(env, encryptedString, NULL);
xor_crypt("{$}", str, strlen(str));
return (*env)->NewStringUTF(env, str);
}
void xor_crypt(char *key, char *str, int str_len)
{
int i;
int key_len = strlen(key);
for(i = 0; i < str_len; i++) {
str[i] = str[i] ^ key[i % key_len];
}
}