Skip to content

Instantly share code, notes, and snippets.

View natmchugh's full-sized avatar

Nathaniel McHugh natmchugh

View GitHub Profile
@natmchugh
natmchugh / gist:3169075
Created July 24, 2012 09:29
call by reference example
<?php
class A {
function callByRef(&$var) {
$var->foo = 'bar';
$var = new stdclass;
$var->baz = 'bat';
}
function callOnObject($var) {
@natmchugh
natmchugh / Response.php
Created February 1, 2013 12:41
for mark
/**
* getConfirmedDeliveryDate
*
* @return void
*/
public function getConfirmedDeliveryDate()
{
return $this->_confirmedDeliveryDate;
}
<?php
function changeMessage($ip, $msg)
{
$fp = fsockopen($ip, 9100, $errno, $errstr, 5);
if (!$fp) {
echo "$errstr ($errno)";
} else {
$string = "\x1B%-12345X@PJL RDYMSG DISPLAY = \"".$msg."\"\r\n\x1B%-12345X\r\n";
fwrite($fp, $string);
<?php
require (__DIR__.'/../vendor/autoload.php');
use Guzzle\Http\Client;
use Fishtrap\Guzzle\Plugin\OAuth2Plugin;
use Guzzle\Log\MessageFormatter;
<?php
define('π', M_PI);
var_dump(π);
@natmchugh
natmchugh / sha1.php
Last active August 10, 2018 15:08
Pure PHP implementation of SHA1from wikipedia pseudo code
<?php
/*
Note 1: All variables are unsigned 32 bits and wrap modulo 232 when calculating, except
ml the message length which is 64 bits, and
hh the message digest which is 160 bits.
Note 2: All constants in this pseudo code are in big endian.
Within each word, the most significant byte is stored in the leftmost byte position
*/
@natmchugh
natmchugh / md4.php
Created March 29, 2014 13:05
Pure PHP MD4 implementation
<?php
function preProcess($message) {
$message .= chr(128);
while (((strlen($message) + 8) % 64) !== 0) {
$message .= chr(0);
}
return $message;
}

Keybase proof

I hereby claim:

  • I am natmchugh on github.
  • I am natmchugh (https://keybase.io/natmchugh) on keybase.
  • I have a public key whose fingerprint is 1807 554C EDC9 A540 CEBA B189 53CA 1AC2 5751 A4A8

To claim this, I am signing this object:

<?php
$hashes = [];
$count = 0;
while (true) {
$randBytes = openssl_random_pseudo_bytes(100);
++$count;
$hash = hash('md5', $randBytes);
$smallerHash = substr($hash, 0, 8);
if (isset($hashes[$smallerHash])) {
@natmchugh
natmchugh / MD5_no_padding.php
Last active September 11, 2022 08:23
MD5 algo with padding commented out this makes it suitable for use in length extension attacks as output can then be used as initial values for next block
<?php
//Pre-processing: adding a single 1 bit
// append "1" bit to message
// Notice: the input bytes are considered as bits strings,
// where the first bit is the most significant bit of the byte.[46]
//Pre-processing: padding with zeros
// append "0" bit until message length in bits ≡ 448 (mod 512)
function preProcess($message) {
// $message .= chr(128);