Let's talk a little bit about encryption and specifically kind of modern encryption and how it works
Now before we jump straight into something like the advanced encryption standard. I wanted to talk about SP networks
or Substitution-Permutation networks because they are the basis for a lot of modern cryptography — not all of it, but a lot of symmetric cryptography anyway.
Dave has done a lot of videos on things like Enigma. Enigma is a kind of classic cipher and it's a substitution cipher.
Just like the Caesar cipher. It's just that its substitution is a little bit better than the Caesar cipher
so with something like Enigma or the Caesar cipher
you've got an input which is you know letter 1, letter 2, 3, 4, 5
this is the message going this way and this is going to undergo some kind of substitution and turn it into another one
Which let's say is kind of ciphertext 1 ciphertext 2 3 4 and so on each one now
There's a lot of problems to the Caesar cipher - okay
And there's a few problems with Enigma, but one of the problems is but there's only ever a one to one mapping
That is to say this character is encrypted and becomes this character and this one is encrypted. It becomes this character, which means that
however complicated the substitution is to work out the mapping you really need to focus on these two characters alone if this cipher text was
Based on ten of these characters that'll be a little bit more difficult already
So we could say that the Enigma machine or Caesar cipher has a block size of one
right
Which is but it encrypts a block of one character
Into an output of one character right now modern encryption doesn't work. This way modern encryption has a block size
It's quite a lot larger, right? Certainly. This is a block cipher
So a block cipher is something that takes a block of a certain size
Let's say 128 bits and it turns it into an output or ciphertext of 128 bits
So what I want to talk about today was a very simple example of a network
That you can make significantly more complicated and end up being the most used
Algorithm on the planet might not the one I'm going to show you
So this is an SP Network
the idea is that is
That what we want to do is combine some kind of substitution process changing characters for other characters
With something called a permutation process swapping characters around XOR in things to other things moving things about and that way
Not only do is the mapping between the input and the output confusing but it moves all over the place. So it's even more confusing
Technically, that's what enigma does though, right? No
Yeah, because every time you change it the map, you know, so so the yes a good question, right?
So let's go back to this
so what enigma does is it changes this substitution if we tick but it doesn't mean that this goes to this and this goes to
This and this goes to this so it's still one-to-one
It's just for the substitution is confusing and changes. So it's still gonna block size of one
An Engel, I guess will be better if I had a bigger block size, but I don't know how they would wire that up
What we want is some kind of slightly larger block, so I'm going to have a full block
Substitution. Alright, so I'm gonna have something called an S box right an S box
I'm gonna do like this takes four bits of input
So these are the bits might be the north or one or two one or two one or two one and it outputs four bits
And then in it, I'm going to come up with some rules
So when a five goes in let's say a seven comes out and when a fourteen goes in a two comes down
Right, and I can come up with some rules. So I'm going to make up some balls now
I'm not going to draw them all in here because I've already want to have space
So this is two to the four possible combinations so numbers between 0 and 15 right all zeros to all want
Okay, so let's come up with some rules. Right? So for example, let's let's do all the inputs
So in what North one two, three, four five six?
Possible to this bit. I think those are all the different combinations
So I'm gonna use a different pen because otherwise it's gonna get confusing. Okay?
These are some rules I've come up with now. These are not particularly good
There's a lot of reasons for this one is my xbox is too small
but the other thing is that I haven't given I mean I've
Paid a little bit of attention to things not going back on themselves
but so things like
If a one went to a 10 and a 10 went to a 1 that's kind of invertible and that's some a statistically weaker
But if you didn't do that, right?
So there's a little bit always you should be careful about when you're designing these kind of things, right?
My best advice would be to use the ones that have already been designed and not develop your own
Let's put a number through here. So let's put the number twelve in through this S box. Okay
so 12 is 8 plus 4 plus nor plus naught so 12 goes in and
12 maps to 5. So that's going to be naught 1 or 1/4 plus 1, okay
So so this comes out as 5 right now
This could be this could go into another mess box or just some other process, right?
The idea is that you're just mapping numbers to another number now this on its own
It's like a terrible version of enigma, right a number goes in and a really poorly masked number comes out, right?
It's terrible because everyone can see this so, you know what this is you can just invert it. We need more than this
Ok. So what we do is we also implement some permutation. So let's list this contra permutation box a permutation box in my example
It's just going to move things about so we're going to take let's say an 8 bit permutation box
So that's going to be like this
1 2 3 4 5 6 7 8 bits of input 8 bits of output and then we're just gonna mix it up
So we're gonna take that one over here and that one over here
This is getting confusing I'm running out of lines
Okay, right I made that up. So I mean, you know, is that good? I don't know but it's not
It's not important how good it is as a cipher
So you would have 2 X boxes here - 4 bit s boxes for example plugging into one 8-bit permutation box
So the outputs of these get jumbled about or mixed up here the way an SP network works. Is it repeats?
Substitution and permutation over and over again. So I'll just draw like an example
Without drawing all the lines up again
And then we'll go through using our permutations
So you might for example have 4 bits in and another S box here 4 bits in these 4 bits
come into our permutation box and go through that mapping which I won't draw out again, but
that one right and then out come 8 bits of
Ciphertext in some sense. So let's put it on belén and see how it works. Ok
I've got control now pick a number between 1 to 5 5 way
103 okay, I'm gonna give you come about now before I break it 103 like let me get a pen a different pen
So one. Oh three. Oh
one
100 warms wand one, right?
I checked because making a mistake will be two emerging now. So just do business box on its own first, right?
These are my rules I've got here. I'm going to refer to them just sort of on the side
This number here is four plus two, which is six
So if I look in here six goes to eight so that's 1 0 0 0 so 1 0 0 0
like that 0 1 1 1 is
4 plus 2 plus 1 alright, which is 7 so I look 7 up goes to 3 eventually buy naught naught 1
1 okay, so I'm gonna start trying to I mean because I haven't drawn them in here. I don't know where they're going
But this one goes all the way to the end. So this one comes down here. This one goes to
That one apparently that's not great. That's not very exciting. So that's a lot. This one goes to here
This one goes 1 across to here. I
Think I didn't I didn't separate them out not very excited. Okay, I mean, yeah, it was mostly not that no
I'll pick a bad number date. Yeah it do you not know anything about my cipher
I've got completely lost about which number I was turning on which
That that one so one goes to there. Yeah. Okay. So there's one there one there
Yeah, we can cut this out and it will all look great. That one goes to there that one K
So now you would program this up
So you work quite as slow as me right because because AES for example can encrypt at 700 megabits per second. I can't
I've done
8 bits
And it's taking this way too long. Okay, right. So this number is
So 16 plus a 4 of 20 plus the wall is 21 21
So is this a good cipher?
well
Let's put aside the fact that it's trivially decrypted all and say well 103 is not a lot like 21 so intuitively maybe right
It's not absolute table now on its own. This is not very good
This is called a round
Right and the idea is of what you would do is you would repeat this over and well over again
and hopefully you wouldn't just be switching eight bits about you'd have a whole hundred twenty eight bit block and
Overtime bits from the very left it getting moves over to the vote right and having effects on everything
Alright, so this mapping becomes much much more confusing
The other thing is that we've got to introduce a secret key because about a secret key if you know the code for this
You can just reverse the process. This is not hard to reverse
The inverse box is just a reverse lookup of this table and this permutation is just a reverse direction for all these wires
So how do we introduce a key? Obviously called something called key mixing. So what we have is we have our message
Alright, which is the size of our block. Thankfully we're gonna put it through around like this round one and we're gonna put it through
And - and then we're gonna get some ciphertext now that alone is not very good
So what we do is we have our key aisle secret key and we expand it into a nice block of this length
and we split it up to be let's say three chunks long right in this case and the first chunk is ex-ored with
this here and the second chunk is XOR dear and the third chunk in the edge sword here like this and that means that
Once you take the key away, you can no longer reverses process, but the key is the secret bit
We all know how the S boxes work. We all know how the permutation box works
But as soon as you take a key away, we're a bit stuffed way
if you have the key decryption is really easy you expand the key right something called a key schedule and
You start with a ciphertext you XOR it with this bit of a key you go through the inverse of here
you XOR of this bit you go through the inverse of this you excellent this bit and you've got the message back so you can
Go forward you can go backwards
All you need to do is change these light arrows to left if you take the key away
You can't perform these XOR operations which are going to be flipping bits and ompletely muddling around with the input
so none of this is going to work right you'll be able to
Achieve absolutely nothing
like I said
what we don't do is keep our s box or a permutation box secret right because it will be easy to
Decompile the code and work out. What happened
what we do is we develop really really good s boxes and permutation boxes and
Then we introduce a key schedule to mix our key in and then when you take a key away, you can't break it
That's how a modern s
Network works, you've got two rounds there or they're usually more another different is usually more. They're not different, right?
So typically you'd use the same round as usual rounds really good
The number of rounds of use will depend on the algorithm the strength of your round function
So a EES uses between ten and fourteen rounds
The way it's designed is that you increase the number of rounds until you can't break it any more
That's the idea
If you use too few mounds
They'll probably be some statistical mapping between the input and the output you might better work out how to break that cipher
Only one half if you just use a billion rounds
Then no one's going to do anything because they're all busy encrypting and it's going to take too long
So you've put there's a compromise between how many rounds you use for speed and how many miles you use for security right and this?
used
In anything we can put our finger on now
This is actually absolutely so so this SP network is the basis for the advanced encryption standard and the advanced encryption standard
Encrypts almost every connection over the Internet right the one you're using now
We'll talk another time about AES the advanced encryption standard, but it functions quite a lot like this
It's just that they've given a little bit more consideration to their design than I have
Video cycle can being applied to every frame of an image
It's gonna be little bit noisy why you're gonna have to take steps or tries to move that out yet?
38 billion hashes per second, which is why md5 is not usable in any sense anymore ever?
Don't use it. Okay, is that clear yet?