See, this algorithm has one big weakness and that's the key. and out pops our decrypted text, SQLUndercoverīut it seems that the clever boys at MI5 have managed to intercept and decrypt our message. To decrypt is a simple matter of running the same proc but this time we need to plug in the cypher text instead of the plain text. The resultant cypher text is ~|axCIH_NB[H_ The XOR will be performed as described above on the ASCII value of each character and the output printed. Let’s see this in action in SQL, the following procedure will accept text as and a single byte binary value as the key. To decrypt we just have to do the opposite and XOR the cypher text against the key. Firstly we need to XOR S or 83 against our key, to see this in action, we’re going to need to look at these values in their binary form. We’ll now XOR our key against each character of our plain text, the result will make up our encrypted message (or cypher text). In order to perform encryption or decryption, we’re going to need a key value. How are we going to do this? Firstly we need to remember that all text characters are represented by a single byte as an ASCII code. Let’s say that we want to encrypt the plain text ‘SQLUndercover’. Let’s look at an example of how this is going to work. Basically this cypher works by taking a key which for simplicity sake will be a single byte and XOR-ing that against the message (or plain text) that we want to encrypt. Undercover Encryption Version 1: XOR CypherĪs this post was prompted by my post on bitwise logic, we’re going to base our algorithm around the XOR cypher. There are plenty of encryption options in SQL Server so I’ve got no idea why you’d ever want to write your own but just for fun, that’s exactly what we’re going to look at here. Because of that I’m not going to say that what I’ve done is the best way of doing it but it is a way. This isn’t really a serious post about SQL Server but rather me playing around and seeing what I could do with it. At first I was going to write something on bitmaps but then a thought of another area where bitwise logic is heavily used and that’s in cryptography. After my last post on The Arcane Science of Bitwise Logic and SQL Server I was asked a couple of questions on where it’s used so I thought I’d write a follow up post.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |