This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int encrypt( | |
void* buffer, | |
int buffer_len, | |
char* IV, | |
char* key, | |
int key_len | |
){ | |
MCRYPT td = mcrypt_module_open("rijndael-128", NULL, "cbc", NULL); | |
int blocksize = mcrypt_enc_get_block_size(td); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] padBytes(byte[] str, int blocksize){ | |
byte[] barr; | |
if (str.length > blocksize){ | |
int padbytes = str.length % blocksize ; | |
barr = new byte[str.length + (blocksize-padbytes)]; | |
}else{ | |
barr = new byte[blocksize]; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void* padBuffer(void* buf, int buflen, int blocklen){ | |
void* barr; | |
int barrlen; | |
if(buflen > blocklen){ | |
barrlen = buflen + (blocklen-(buflen%blocklen)); | |
}else{ | |
barrlen = blocklen; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String decrypt(byte[] cipherText, String encryptionKey) throws Exception{ | |
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE"); | |
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES"); | |
cipher.init(Cipher.DECRYPT_MODE, key,new IvParameterSpec(IV.getBytes("UTF-8"))); | |
return new String(cipher.doFinal(cipherText),"UTF-8"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int decrypt( | |
void* buffer, | |
int buffer_len, | |
char* IV, | |
char* key, | |
int key_len | |
){ | |
MCRYPT td = mcrypt_module_open("rijndael-128", NULL, "cbc", NULL); | |
int blocksize = mcrypt_enc_get_block_size(td); | |
if( buffer_len % blocksize != 0 ){return 1;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.SecureRandom; | |
public static byte[] genIV(int len) throws Exception{ | |
byte[] arr = new byte[len]; | |
SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); | |
prng.nextBytes(arr); | |
return arr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int genIV( | |
void* buffer, | |
int buffer_len | |
){ | |
/* | |
* Note that we propagate the return code from the library called. | |
*/ | |
#ifndef _WIN32 | |
return RAND_bytes(buffer, buffer_len); | |
#else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* random.c */ | |
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
void parser(char *input, double particles[][4]){ | |
sscanf( | |
input, | |
"p[20] = nullvector(%lf,%lf,%lf,%lf)", | |
&particles[20][3], &particles[20][0], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#if defined(SMALL) | |
#define SIZE 30 | |
#endif | |
#if defined(LARGE) | |
#define SIZE 3000 | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define SMARTY_SIZE_INIT 16 | |
typedef struct { | |
char * str; // a null terminated C string | |
char * end; // a pointer to the null byte, to be able to repeatedly append | |
// without using strlen() every time. | |
size_t size; // currently allocated size for *str, so we know when we |