Skip to content

Instantly share code, notes, and snippets.

View natmchugh's full-sized avatar

Nathaniel McHugh natmchugh

View GitHub Profile

Phone Number Formats

Below is a comma seperated list of phone numbers customers in the UK have typed into a web form. There was no required format or validation on characters used. Write a script to parse the list and output the numbers as a UK phone numbers in the 3 common display formats:

  • 0141 496 0018
  • (0141) 496 0018
  • +44 141 496 0018

The expected otput form for different dialing codes is given at https://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom#Format

@natmchugh
natmchugh / single_char_xor
Created June 19, 2015 08:49
Single Character XOR
kaqn5bHipa224qPisa+rrqfitqqjtuKrtuKxp6evseK2reKvp8iQp6+rrKax4q+n4q2k4qGqq66mqq2tpuKvp6+tsKunsciVqqewp+KntKewu7aqq6ylyJWjseKjseKksKexquKjseK2qqfioLCrpaq24qCut6fisam7yMiMrbXio6ym4raqp6zitaqnrOKL4rGnp+Kqp7DipKOhp8iRqqfitqOpp7Hir6fio7Wju+K2reK2qqO24rGyp6Gro67isq6joafIg6ym4quk4ovisbajsKem4ratreKuraylyIvlpuKysK2go6Cuu+KgsKejqeKmrbWs4qOspuKhsLvIyJG1p6e24qGqq66m4q3l4q+rrKfIkbWnp7birq20p+KtpOKvq6ynyMiRqqflseKlrbbip7unseKtpOK2qqfioK63p7G24rGpq6exyIOx4quk4raqp7vitqqtt6WqtuKtpOKwo6usyIvlpuKqo7an4rat4q6traniq6y2reK2qq2xp+Knu6exyIOspuKxp6fio6zirbesoafiraTisqOrrMjIiqew4qqjq7DisKevq6ymseKvp+KtpOKj4rWjsK/isaOkp+KyrqOhp8iVqqewp+KjseKj4qGqq66m4ovlpuKqq6anyIOspuKysKO74qStsOK2qqfitqq3rKansOKjrKbitqqn4rCjq6zIlq3is7erp7auu+Kyo7Gx4q+n4qC7yMiZ8bqfyJG1p6e24qGqq66m4q3l4q+rrKfIkbWnp7birq20p+KtpOKvq6ynyMiZ9rqfyJWqp7Cn4qat4rWn4qWt/ciVqqewp+KmreK1p+KlreKsrbX9yJWqp7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wFQVThPAAFBGRlbMmUmDEEBUFg4GlUWRVURQiMGHAMAGRlK
@natmchugh
natmchugh / MD5.php
Created May 8, 2015 08:17
PHP implementation with some test inputs
<?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);
@natmchugh
natmchugh / Makefile
Created May 6, 2015 07:37
Makefile for fast coll
fastcoll:
g++ -O3 *.cpp -lboost_filesystem -lboost_program_options -lboost_system -o fastcoll
<?php
include __DIR__.'/MD5.php';
$inFile = __DIR__.'/demo';
$dummyText = str_pad('', 64, 'A');
function replaceDummyText($input, $replacment, $position)
{
return substr_replace($input, $replacment, $position, strlen($replacment));
}
require 'bcrypt'
my_password = "\0hello is it me you're looking for";
verify = BCrypt::Password.create(my_password)
puts my_password.inspect
# This password verifies according to bcrypt
puts verify == my_password ? ' password verified ' : 'password incorrect';
# but also ...
puts verify == '' ? ' But also verifies to a blank string' : 'Hey thats just a blank string';
openssl s_client -msg -connect talktalk.co.uk:443 -cipher EXP-RC4-MD5
@natmchugh
natmchugh / rsa120.py
Created March 11, 2015 15:56
Print out plain test of message for RSA129
import string, sys
def extended_gcd(aa, bb):
lastremainder, remainder = abs(aa), abs(bb)
x, lastx, y, lasty = 0, 1, 1, 0
while remainder:
lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder)
x, lastx = lastx - quotient*x, x
y, lasty = lasty - quotient*y, y
return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1)
<?php
$p = '3490529510847650949147849619903898133417764638493387843990820577';
$q = '32769132993266709549961988190834461413177642967992942539798288533';
$N = bi_mul($p, $q);
$c ='96869613754622061477140922254355882905759991124574319874695120930816298225145708356931476622883989628013391990551829945157815154';
$phin = bi_mul(bi_sub($p, 1), bi_sub($q, 1));
$e = 9007;