Skip to content

Instantly share code, notes, and snippets.

View cia48621793's full-sized avatar

Steve Fan cia48621793

  • Hong Kong
View GitHub Profile
class EventListener<T> {
private callbacks:{(user : T) : void}[] = [];
addEventListener(callback:{(user : T) : void}):void {
this.callbacks.push(callback);
}
removeEventListener(callback:{(user: T) : void}):void {
this.callbacks.splice(this.callbacks.lastIndexOf(callback));
}
@cia48621793
cia48621793 / aes.cpp
Created June 11, 2015 14:25
ASE128 with managed wrapper
#include "aes.h"
// This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states.
static void KeyExpansion(void)
{
uint32_t i, j, k;
uint8_t tempa[4]; // Used for the column/row operations
// The first round key is the key itself.
for(i = 0; i < Nk; ++i)
@cia48621793
cia48621793 / md5.c
Last active August 29, 2015 14:19
dirty md5
#include "md5.h"
char* md5(const char* src)
{
unsigned char* buffer = (unsigned char*) malloc(16 + 1);
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, src, strlen(src));
MD5_Final(buffer, &ctx);
#include "base64.h"
void build_decoding_table()
{
int i;
decode_table = (char*) malloc(128);
for (i = 0; i < 64; i++)
decode_table[encode_table[i]] = i;
}
@cia48621793
cia48621793 / hexutil.c
Last active August 29, 2015 14:18
bin2hex & hex2bin
#include "hexutil.h"
short char2int(char c)
{
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;