Skip to content

Instantly share code, notes, and snippets.

View jaytaph's full-sized avatar
:shipit:
Calculating pi

Joshua Thijssen jaytaph

:shipit:
Calculating pi
View GitHub Profile
/**
* Taken from Nikita Popov's answer on stack overflow: http://stackoverflow.com/questions/16489509/decrypting-aes-ctr-little-endian-with-php
*/
static public function ctr_crypt($str, $cipher = MCRYPT_RIJNDAEL_256, $key, $iv) {
$numOfBlocks = ceil(strlen($str) / 16);
$ctrStr = '';
for ($i = 0; $i < $numOfBlocks; ++$i) {
$ctrStr .= $iv;
// 6. Encrypt inner packet
$blob = $inner_packet->encode();
$cipher = new \Crypt_AES(CRYPT_AES_MODE_CTR);
$cipher->setIv($iv);
$cipher->setKey($hash);
$body = $cipher->encrypt($blob);
// 7. Create sig
// This is why we can't have nice things
if (! defined('OPENSSL_ALGO_SHA256')) define('OPENSSL_ALGO_SHA256', 7);
// // sign & encrypt the sig
// var md = forge.md.sha256.create();
// md.update(body.bytes());
// var sig = id.private.sign(md);
openssl_sign($body, $sig, $my_priv_key, OPENSSL_ALGO_SHA256);
@jaytaph
jaytaph / gist:7517596
Created November 17, 2013 20:02
telehash xfer app
All application packets are marked with the "_xfer" type.
Returning a listing of all files from a particular node:
Request:
{
type : '_xfer',
_ : {
request : 'list'
filter:
paths: [lib/*]
excluded_paths: [vendor/*, tests/*]
before_commands:
- 'composer install --dev --prefer-source'
tools:
external_code_coverage: true
php_mess_detector: true
php_code_sniffer: true
sensiolabs_security_checker: true
/** gcc -g -O0 -fno-inline -o test test.c `pkg-config --libs --cflags icu-uc icu-io` */
// We will be using UTF8
#define U_CHARSET_IS_UTF8 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "unicode/uchar.h"
#include "unicode/ucnv.h"
class string {
public method pad(numerical width, numerical direction = PAD_RIGHT); // PAD_LEFT, PAD_RIGHT, PAD_BOTH
public method utf8(); // shortcut to convert("utf-8");
public method utf16(); // shortcut to convert("utf-16");
public method bytes(); // Return some kind of bytestream?
public method convert(string charset); // Convert to different charset
public method byte_length(); // Returns number of BYTES in this string (which can be more than actual characters)
public method char_length(); // shortcut to length();
#define MAXLED 3
int ledPins[MAXLED][3] = {
{2,3,4},
{5,6,7},
{8,9,10},
};
typedef struct _rgb {
@jaytaph
jaytaph / sf2create.sh
Created January 20, 2014 17:56
Simple script that automatically creates and initializes a correct sf2 project for me.
#!/bin/sh
php composer.phar create-project symfony/framework-standard-edition $1
cd $1
ln -s web public
sed -i public/app_dev.php -e '/header/s|^|//|' -e '/exit/s|^|//|'
sudo setfacl -R -m u:www-data:rwX -m u:jthijssen:rwX app/cache app/logs
import io;
class foo {
public method bar() {
try {
io.print("try\n");
return "1";
} catch (exception e) {
io.print("exception\n");