Skip to content

Instantly share code, notes, and snippets.

View mythosil's full-sized avatar

Akito Tabira mythosil

View GitHub Profile
@mythosil
mythosil / qt_sample.cpp
Created February 21, 2012 13:37
qt4-mac sample
#include <QtGui>
using namespace std;
class Sample : public QObject {
Q_OBJECT
public slots:
void action() {
emit quitApplication();
}
signals:
@mythosil
mythosil / CryptAES128.java
Created October 25, 2011 17:16
encryption and decryption by AES-CBC (Java)
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.IvParameterSpec;
class CryptAES {
static final String cipher_type = "AES/CBC/PKCS5Padding";
public static void main(String[] args) {
String key = args[0];
@mythosil
mythosil / ev_timer.c
Created October 21, 2011 09:56
libevent timeout sample
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <event.h>
#define BUFSIZE 256
#define TIMEOUT_SEC 3
void read_handler(int fd, short event, void *arg)
{
@mythosil
mythosil / chat_tcp.js
Created October 18, 2011 04:19
tcp chat server (nodejs)
var net = require('net');
var streams = new Array();
var server = net.createServer(function(stream) {
stream.setEncoding('utf8');
stream.on('connect', function() {
stream.write('Welcome\r\n');
streams.unshift(stream);
});
stream.on('data', function(data) {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
char *encrypt(const char *data, const char *key, const char *iv, int *length)
{
int key_length, iv_length, data_length;
key_length = strlen(key);
iv_length = strlen(iv);
@mythosil
mythosil / ccrypto.m
Created October 17, 2011 15:02
encryption and decryption using CommonCrypto
/*
* gcc -std=c99 crypto.m -framework Foundation
*/
#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonCryptor.h>
@interface NSData (AES)
- (NSData *)AES128Operation:(CCOperation)operation key:(NSString *)key iv:(NSString *)iv;
- (NSData *)AES128EncryptWithKey:(NSString *)key iv:(NSString *)iv;
- (NSData *)AES128DecryptWithKey:(NSString *)key iv:(NSString *)iv;
@mythosil
mythosil / decrypt.c
Created October 17, 2011 10:08
decryption by AES(128bit) using libcrypto
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
int main(int argc, const char* argv[])
{
if (argc <= 3) {
fprintf(stderr, "Usage: %s <key> <iv> <data>\n", argv[0]);
exit(EXIT_FAILURE);
@mythosil
mythosil / encrypt.c
Created October 17, 2011 09:32
encryption by AES(128bit) using libcrypto
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
int main(int argc, const char* argv[])
{
if (argc <= 3) {
fprintf(stderr, "Usage: %s <key> <iv> <data>\n", argv[0]);
exit(EXIT_FAILURE);
@mythosil
mythosil / localized_disable.pl
Created September 10, 2011 06:07
disable the localization of dirname in macosx
#
# Description:
# Disable the localization of directory' name in Mac OS X.
#
use strict;
use warnings;
my $home = $ENV{'HOME'};
my @directories = (
"$home/Desktop",
@mythosil
mythosil / bufferevent_echo_server.c
Created August 31, 2011 09:42
echo server using bufferevent(libevent)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <event2/event.h>
#include <event2/bufferevent.h>
#define PORT 1986
#define BACKLOG 1000
void readcb(struct bufferevent *bufev, void *arg)