HTML Email Address Obfuscation (PHP)

Small class, intended to be used as a callback for preg_replace_callback to obfuscate email addresses. You can also simply pass a string in rather than being obliged to use preg_replace_callback

Supports a number of obfuscation modes

  • part - e.g. test@
  • full - e.g.
  • none - e.g. test@example.com
  • htmlencode - Generates a javascript snippet to write the address in
document.write('test');
document.write('@');
document.write('example.com');

Although it's targetted with HTML output in mind, it can just as easily be used on plain text

Read more…

Encrypt with One Time Pad (BASH)

Basic example of how to generate, and encrypt arbitrary strings (or text files) with a One Time Pad/OTP

In principle, where the pads are sufficiently controlled, One Time Pads cannot be cracked in any reasonable timeframe. The real challenge lies in distributing the pads themselves securely, and independantly of the ciphertext. For most people and uses, they are effectively unusable

This implementation does have some known limitations, which could quite easily be fixed

  • The cipher text consists of hex encoded ASCII codes - primarily to avoid issues raised by BASH's handling of non printable character codes in strings - so the cipher text is longer than the plain text
  • Trailing newlines on the end of a file will be stripped, so files may not be exactly identical
  • There's no protection against providing too short a One-Time pad

Read more…

Split string on Delimiter (LUA)

Basic function to split a string on a delimiter in LUA. Syntax is like PHP's explode - delimiter then string

Returns a table of the identified substrings

One known limitation is that it won't include an empty key where two delimiters occur in sequence - e.g. 'foo,,bar' - will return a table with two entries instead of 3. But I didn't need that behaviour when I wrote it, so didn't spend any extra time on it

Read more…

Calculate Fibonacci Sequences (Python)

A small function to calculate Fibonacci like sequences based on provided seed values. Can be used to calculate Fibonacci numbers, Lucas numbers or an arbitrary Fibonacci like sequence

We're simply calculating Fn = Fn-1 + Fn-2 for a given number of iterations

When called without arguments, the default behaviour is to return the first 12 numbers of Fibonacci

Returns a list of numbers in the sequence, with the provided seeds at the beginning

Read more…