Hello and welcome to this fundamentals of cryptography course.
In earlier videos in this course, we talked about the fact that all of cryptography is math, encryption
algorithms, decryption algorithms, hash functions.
They're all mathematical functions that take an input, transform it in certain ways and produce an
output.
And so many of these functions are fairly complex at a high level.
But if you break them down, many of them share the same building blocks, the same low level mathematical
operators that perform the transformations, a plain text, a cipher text or inputs to hash values.
And so in this video, we're going to talk about some of the most common building blocks used in cryptographic
algorithms.
There's certainly others.
And sometimes the math and cryptography gets pretty intense.
But we're not going to dive into that in this video.
And so we're going to talk about four different mathematical functions are operators in this video.
We'll talk about the modulo operator, the X or function, bitwise shifts and rotations and then elliptic
curve cryptography, which is a bit higher level, but useful to discuss because it's becoming more
and more common.
And so let's get started with the modulo operator and the modulo operator essentially comes down to
performing integer division and keeping the remainder.
So if we take a look at the image on the right hand side of the slide, we see that what we're doing
is dividing six by five.
And then we end up with a quotient of five and a remainder of one.
And so typically when you're doing division, what you want is the quotient.
However, when we're using the modulus function, what we really care about is that remainder of one.
And this can be written in a few different ways.
So in computer science, it's often written with a percentage sign.
As we see in the sub bullet here, we see twenty six percent.
Five equals one.
Translates to twenty six modde five equals one or divide.
Twenty five by six.
And give me the remainder which happens to equal one in cryptography.
You might see that percentage sign replaced by M0 D for Modulus, but they mean the same thing.
And so Modulo is commonly used in cryptography to keep mathematical operations within a certain range
of values.
If I'm using a modulo of five like we're doing here, I'm never going to end up with a value outside
the range of zero to four, which can be useful in certain contexts, as we'll discuss throughout this
course.
But for now, let's move on to talking about the X or function in English.
For example, when I say or I'm using B inclusive or if I say I want A or B, I don't mean that you
can give me A or B, but you certainly cannot give me both.
I'm willing to accept both when I use the inclusive or.
However, when I use exclusive or like we are here, we're using the logical operator equivalent to
this or that, but not both.
And so if we look at this table on the right, we see the outputs of exclusive oring different combinations
of two bits, A and B..
So if they're both the same zero zero or zero one sorry, zero zero or one one, we produce an output
of zero.
If the two input bits are different, a zero and a one, we produce an output of one.
So it's A or B, but not both.
Also, interestingly, XOR is equivalent to additions in modulo two and so zero plus zero zero zero
plus one is one and one plus one is two, which happens to be zero mod two.
And so this also useful in cryptography.
And so XOR is actually one of the most commonly used mathematical functions in cryptography, if not
the most commonly used.
And one example of this is the one time pad, which is the only information, theoretically secure cryptographic
algorithm.
So the only one that, if used absolutely properly, is completely unbreakable.
And it only uses X or so if you're using the one time pad, you take your plain text, you take a completely
random secret, key of the same length of the plain text and you x or each bit together to get the ciphertext
at the other end.
The recipient does the exact same thing.
They take the cipher text X or each bit with the key and they get the plain text.
Because if you do plaintext bit X or what, X or Chebet, X or Chebet, you're going to end up with
the plain text bit, because if that key bit was a zero zero X or zero zero in that key bit is a one
one X or one is zero, and anything X or zero is itself.
And so you apply the same key twice and end up with what you started with.
One time pad isn't really used because if you have a means of sharing a completely random secret key
with someone of the same length as your secret message.
Well, why didn't you just share the secret message there and not bother with the crypto?
Only logical application right now is if you can share that key in advance to be used later for a secure
cipher.
But moving on, let's talk about bitwise shifts or rotations.
So a bitwise shift or rotation means shifting everything by a certain number of steps.
And this is interesting because a bitwise shift in rotation is equivalent to multiplication by a power
of two.
For example, if I take a binary string shift at one step to the left, I've doubled its value.
And as we see on the right hand side of this slide here, if in a bitwise ship shift, you have a bit,
that's going to fall off the edge.
For example, our most significant bit at the top, which is the far left one, it will typically wrap
around to the other end in cryptography.
Not always true in computer science.
There are applications where you want to multiply by a power of two, in which case you're going to
shift in a zero.
So in this particular case, because our most significant bit is a zero, we've doubled the value through
our shift.
If it was a one, doing our wrap around messes up that multiplication by a power or two that I just
mentioned.
But shifting is useful.
And we'll see it again when we talk about A-S, the advanced encryption standard.
Now, our final cryptographic primitive we're going to talk about here is elliptic curve cryptography.
And so elliptic curve cryptography allows you to perform cryptography on elliptic curves.
And this is useful because certain integer operations map directly to ones on the elliptic curve.
If I multiply two numbers together, it's equivalent to adding two points on the elliptic curve.
If we use integer exponentiation, we can make that equivalent to multiplying points on the curve.
And so this is useful because there are certain cryptographic algorithms that are based off of multiplication
and exponentiation.
And doing those with an elliptic curve as opposed to integers makes them more efficient.
They consume less power.
And also you get a higher level of security with a shorter secret key, which is valuable because when
we're protecting against brute force, password guessing attacks or brute force attacks against that
secret key.
The longer the key, the stronger it is.
And so if we can get that same level of security with a shorter key, we take up less memory and can
be much more efficient.
And so this concludes this video talking about some of the fundamental principles of cryptography.
We talked about the modulo operator, the XOR function, bitwise shifts and rotation's and elliptic
curve cryptography.
And so, as I mentioned, this is definitely not an exhaustive study of every mathematical function
used in cryptography.
But understanding these operators is important.
And it will also help you to understand most or all of the algorithms that we'll be looking at throughout
the rest of this course.
Thank you.