Weakish character switching, truncate-able obfuscation with a-z cypher text for niche uses

Edit: some people have gone spack that this is more obfuscation and ranted that I might unintentionally cause people to use this for something other than vaguely making trivial strings hard to read, so, if you don’t know what you’re doing, don’t use this ever. Also, try and use standard encryption libraries, this is for a very niche use in my work which I found vaguely interesting. Sorry for any confusion.

Most of the time if you want something securely transmitted or stored and you’re reasonably on the ball, you’d use something like the industry standard AES-256 or other rijndael-based cyphers. They have libraries in almost all known languages, are NSA-approved, and offer fairly trivial processing overheads these days on modern computers.

However, there are some occasions when something a little more basic or flexible is required. I work in a heterogeneous environment where the projects are written in Python, some legacy applications are in PHP, there’s a bit of C and the reporting is done by the analysts in Excel (natch…). This was actually written some two years ago, but yaknow, lazy and so on.

In one recent example we required data to be stored in a cookie which would be passed via a third party and sent back to us in a report. The catches being:

Ruh-roh. So, normal options such as UU or B64 encoding an AES encrypted string was right out, plus I’m not aware of any non-terrible and free ways to decrypt AES encrypted strings in Excel (not that I looked very hard) given that lowercasing it was going to break B64 and friends. We could have written a basic alphanumeric parser ourselves, but that would still probably be too slow in Excel to decrypt. Additionally, truncating the B64 encoded AES encrypted string would possibly make it unusable, if not awkward to decode. Requiring the cypher text to be truncate-able largely rules out anything that uses typical encryption methods.

After a few minutes getting angry at Excel, I went back to basics. The cookies were all going to be about 0-128 chars in length so I decided on the old fashioned and pretty secure one time pad cypher which comes from the WWII spy era with some tweaks with a key about the same length as the cookie would provide ample security. While true that if enough encrypted cookies were disclosed it might be possible to reverse engineer the data eventually as is the bane of all switched based cyphers, it’s certainly a computational challenge. Obviously those with any minor background in cryptography will spot the flaws in using such a simple cypher are that while OTP encryption is considered near unbreakable if used once (hence the ‘one time’ part) if you re-use the key repeatedly as we do in this example it’s possible to reverse engineer the key with enough samples of encrypted data.

This cypher is useful for anyone wishing to pass snippets of data over 3rd party networks where security is beneficial but not critical and the data might be truncated, off-the-top-of-head examples would include:

Anyway, on to the very basic GCSE-level maths! Our example code accepts any standard ASCII characters as input. It represents any ASCII character as a number from 0-255 (the standard ASCII range), this of course can be represented by 16^2, which is what the cypher uses. This means that any ASCII character after the pad switch is represented by exactly two characters in the a-p range representing 0-15 (a = 0, p = 15). Two of these 0-15 characters together can easily be reversed into the full 0-255 representation of the ASCII character, and then displayed as the former character it represents, anyone with any coding background should of course see that this is what ord() and chr() do or their equivalents in your language of choice. In the middle of this process after the conversion from ASCII to a 0-255 integer has taken place, we just add the value of the relevant position of the key, which ‘shifts’ the value upwards, wrapping around to 0 if the shift takes the count past 255. The key is also represented as a-z the same as the cypher text. For example:

[h] [i] [ ] [t] [h] [e] [r] [e]
is represented as the ASCII values
104 105 32 116 104 101 114 101

lets say we have a key of
[b] [i] [s] [c] [u] [t] [s] [!]
98 105 115 99 117 116 115 33

some simple addition
104 105 32  116 104 101 114 101
98  105 115 99  117 116 115 33  +
---------------------------------
202 210 247 215 221 217 229 134

And so on...

As you should be able to see, it’s not possible to get the original “hi there” out of the cypher’d 202 210 247 215 221 217 229 134 without the key “biscuits!”, which would be used in the reverse (subtracting the values) to get the original values back out again. The only stage missing from this is the conversion of the 0-255 integers into two a-z characters, but this again is trivial. So anyway, there you have it. It’s all incredibly simple, but if you have a long enough key (as long as the data you’re encoding) it’s actually surprisingly secure. Insanely secure if you only use the key once. If the cypher text is truncated at all you just round the length to the nearest even positioned character and off you go, you lose some data but it doesn’t destroy the whole message. I also randomise the letters in the cypher text if g-p range with a 50% chance of adding 10 to the position (g becomes q, p becomes z, and so on) - this adds nothing to the security, it just makes the cypher text look more random than it is, because, well, shut up.

On to the code itself, you can grab a copy here, all three versions are BSD licensed, please respect the licence. If you use the code it would be really nice to have a link back to this post :) Note that this code uses /dev/urandom on *NIX for the seed and key genration, you can happily port this to Windows by editing the seed generation method, or just mashing the keyboard.

Just to wrap this massive post up, here’s some examples of using the PHP class, if you need help using the Python or Excel macros, this probably isn’t the code for you ;) Example in PHP:

1. Key (pad) generation:

// import the class
require_once('otpcrypto.php');
// create the instance
$crypto = new otpcrypto();
// generate a key (pad) of a set length (bytes)
// you only normally do this ONCE, and save the key
$key = $crypto->genkey(128);
echo "my random key is: {$key}";

2. Encrypting

// import the class
require_once('otpcrypto.php');
// create the instance
$crypto = new otpcrypto();
// set the key, stored somewhere (see step 1)
$crypto->setkey($key);
// set what we want encrypted
$crypto->setmessage('my quote securely encoded string!');
// perform the encryption
$crypto->encrypt();
// get the cypher text
echo $crypto->getcypher();

3. Decrypting:

// import the class
require_once('otpcrypto.php');
// create the instance
$crypto = new otpcrypto();
// set the key, stored somewhere (see step 1)
$crypto->setkey($key);
// set the encrypted cypher text
$crypto->setcypher('jguihgraehuogra.... etc.');
// perform the encryption
$crypto->decrypt();
// get the clear text message
echo $crypto->getmessage();

Example in Python:

Encrypting

from otpcrypto import otpcrypto
crypto = otpcrypto()
crypto.setkey(key)
crypto.setmessage('my quote securely encoded string!')
crypto.encrypt()
print crypto.getcypher()

… yeah you get the idea…

That about wraps it up, all the libraries work in much the same way, there’s no key generation in the Excel macro one, but that’s about it. There’s no real error throwing as such, but it’s trivial to add to the existing passive error trapping.

Hope you enjoy this very basic waddle into the world of very basic obfuscation of messages, and hope you find it useful if you’re in a similar situation to me.

@2 months ago
#cookies #cypher #excel #one time pad #otp #php #python #affiliate 

Insane reply from Labour

Well, that was pretty crazy. My letter below was mentioned in passing in the Guardian, the Financial Times, boingboing, Media Week, CrunchGear, TechEYE, bitterwallet, Anorak, Prison Planet (via Guardian), Infowars (via Guardian) and last but not least Brand Republic. After that I started ignoring the Google alerts (edit: and ars technica, woo).

Most interestingly, it seems Brand Republic contacted a Labour spokesperson who is quoted saying the following (end of the article):

A Labour spokesman said Timms was an expert in this area, pointing out that he wrote a book about broadband 25 years ago, “before many people knew what it was”.

The spokesman added: “He is in total command of the detail and it would be ridiculous to suggest that he doesn’t know the difference between intellectual property and internet protocol. This is an embarrassing slip and Stephen Timms will make sure it won’t happen again.”

So, who can spot the insanity this time‽ First of all, 25 years ago, consumer broadband didn’t exist. In the UK, consumer broadband emerged about 10 years ago (I assume this isn’t ‘any connection above the speed of a modem’). So apparently he wrote the book on mythical broadband, which wasn’t in the UK for another 15 or so years.

Just to clarify, Labour just claimed that Stephen Timms wrote a book about broadband in 1985. That’s right, 4 years before MCI Mail, 4 years before Tim Berners-Lee starting playing with hypertext at CERN in 1989, just as TCP/IP was becoming mildly popular with basic dialup, just as a few geeks were playing with 1200baud modems and monochrome BBS, our all-knowing Minister for Digital Britain was writing books on broadband. Makes complete sense. I don’t consider a document about the impact of ISDN a couple of years later with ‘broadband’ in the title relevant, but it at least demonstrates a long term understanding of some technical issues (edit: sorry, it seemed the British Library link moved, updated to working Google Library link to Mr. Timms’ document).

While this might well be just another insane typo, and even if Mr. Timms knows the internet inside out and he’s just pressed the DE bill through for another agenda, it’s screamingly clear that most of the government who championed the DE bill are totally, painfully and absolutely clueless.

Now, I freely admit that my original letter (the ‘IP Address = Intellectual Property’ one that went viral) could well be a stupid mistake (and hopefully not a catastrophic lack of knowledge), but this is an important inter-departmental letter written by the very people who pushed the digital economy bill into law and they can’t even apparently proof-read the letters they send out, which is pathetic. An intern with 5 seconds and access to Google could have spotted the error. It also doesn’t bode well for the ‘digital economy’ when, after listening to the live rushed debates at midnight, it is painfully clear to anyone with any technical background that the digital economy bill was debated by people with absolutely no knowledge or clue what they were voting on. This includes ridiculous statements such as confusing what an ‘ISP’ with what an ‘email address’ is. I don’t expect seasoned ministers to know the inner workings of the internet, but I expect them to at least read up on the ramifications of what they’re voting on, and not bundle bullshit laws through at the behest of the media industry (who are making more money than ever, despite the internet ‘costing hundreds of zillions of millions of pounds’ and ‘tens of thousands of jobs’). Ministers have absolutely no right to vote in massively unpopular laws on subjects they know nothing about. I am still amazed that the current government can still shock me with its complete and utter incompetence.

@5 months ago with 2 notes
#debill #digital economy bill #stephen timms #labour #election #ip address 

Another amazing Amazon bargain! Looks like a real price this time though o_O 

@7 months ago

meeb on OiNK (former raided torrent site) owner acquitted of all charges in landmark case 

@7 months ago

meeb on Xbox 360 Elite with Lego Batman and Pure bundle now $293.99 (under list price) 

Twitter segment? o_O

@7 months ago

Subtle liberal bias on the BBC

UPDATE: and it’s gone! No sooner than this post starts getting traffic and the magic black Liberal candidates merge back into the dull greyness like the rest of the other candidates. Go BBC, that was a quick update. I had a tab still open, here’s a screenshot:

BBC Bias towards Liberal Democrats

Original post:

I’ve just noticed there’s some very very subtle bias on the BBC election pages.

If you pick any constituency (for example my home constituency, Islington & South Finsbury) the Liberal Democrat candidate Bridget Fox is shown in black, all the other candidates are in grey.

This is the same for every constituency, the Liberal Democrat candidate is always in black.

Some typographers might be able to enlighten me as to what subliminal suggestion this implies when you look at the table of candidates. It’s very minor, but it’s interesting they treat the candidates differently.

Edit: No, it’s not because it’s a LD target constituency as some people have suggested, check out these others: Cumbernauld, Kilsyth & Kirkintilloch East, Norfolk South, Carmarthen East & Dinefwr etc.

I’ve dug out the CSS as well, it’s definitely not a mistake:

.party-CON .party-colour { border-color:#333399; }
.party-LD .party-colour { border-color:#ff9900; color:#000; }
.party-LAB .party-colour { border-color:#CC0000; }
.party-UKIP .party-colour { border-color:#663366; }
.party-GRN .party-colour { border-color:#339900; }
.party-PC .party-colour { border-color:#006600; }
.party-SNP .party-colour { border-color:#FFB400; }
.party-DUP .party-colour { border-color:#CC3300; }
.party-SF .party-colour { border-color:#003300; }
.party-SDLP .party-colour { border-color:#669966; }
.party-BNP .party-colour { border-color:#666633; }
.party-UCU .party-colour { border-color:#0066CC; }
.party-ED .party-colour { border-color:#660000; }
.party-SSP .party-colour { border-color:#990066; }
.party-LIB .party-colour { border-color:#FF6600; }
.party-RES .party-colour { border-color:#990000; }
.party-IHC .party-colour { border-color:#CC3366; }
.party-AP .party-colour { border-color:#FFCC00; }
.party-TUV .party-colour { border-color:#66CCCC; }
.party-PV .party-colour { border-color:#6699FF; }

Footnote: I’m going to vote LD anyway (purely because they can win in Islington over Labour), this isn’t an anti-liberal post.

@4 months ago
#bbc #bias #liberal democrats #subliminal #typography #css 
I wrote to my MP two weeks ago regarding my shock and horror at the ridiculous speed the UK’s Digital Economy bill was being pressed through parliament, and into the “wash-up” before the next general election, effectively making it law with only a minor discussion.

I was forwarded this letter from my MP (the letter is addressed to my MP, Emily Thornberry) as the reply from the BIS (Department of Business, Innovation & Skills) written by the Minister for Digital Economy. It seems the UK Minister for Digital Economy, Stephen Timms, doesn’t know what an IP address is.

And we’re meant to trust these people when it comes to regulation of the internet? Complete insanity.

I wrote to my MP two weeks ago regarding my shock and horror at the ridiculous speed the UK’s Digital Economy bill was being pressed through parliament, and into the “wash-up” before the next general election, effectively making it law with only a minor discussion.

I was forwarded this letter from my MP (the letter is addressed to my MP, Emily Thornberry) as the reply from the BIS (Department of Business, Innovation & Skills) written by the Minister for Digital Economy. It seems the UK Minister for Digital Economy, Stephen Timms, doesn’t know what an IP address is.

And we’re meant to trust these people when it comes to regulation of the internet? Complete insanity.

@5 months ago with 5 notes
#debill #uk #politics #mandelson #digital economy bill #ip address #internet 

OiNK (former raided torrent site) owner acquitted of all charges in landmark case 

@7 months ago

meeb on Xbox 360 Elite with Lego Batman and Pure bundle now $293.99 (under list price) 

Modern ‘Elites’ use a 65nm CPU and CPU (currently the ‘Jasper’ chipset) rather than the 90nm CPU in the original, which I would assume makes it a bit cooler and quieter. They also have larger HD’s…

@7 months ago

meeb on White House seeks to block new environmental regulations on coal ash. "The Obama administration has joined with the energy companies in seeking to block new regulations that would designate coal ash as toxic waste." 

I’m going to start blanket-ignoring these kind of articles. There’s an unlimited supply of “bad person supports bad thing that are bad, how could they!” posts. The problem is that while they…

@7 months ago