S2 - Essentials Tools of Modern Cryptography

ZK & Privacy Bootcamp · 2:10:34

Hands-on exercises introduce bitwise operations, hash functions, collision resistance, and symmetric and public-key cryptography. Participants calculate toy hashes, explore a blockchain demonstration, and work through Diffie–Hellman key exchange to establish a shared secret.

Speakers

Topics

From ZK & Privacy Bootcamp, published by dev3pack; community: dev3pack.

Transcript

encourages uh to create more right um due to this uh big positive feedback. Um so as we have promised uh previous in previous uh um lecture is that we're going to provide some um hash function lessons. We're going to look at RSA. How does that look like? The Vy Helman key exchange. So I have prepared some um exciting uh examples uh that we can use. Um so yeah, let's um let let's start with that one because why not? Uh let me just share my

presentation with you guys. Okay. That's so cool. Yeah, we had um yesterday we had um token launch. We launched mainet. So that was some um exciting times for us. U so yeah uh let's uh let's do slideshow presentation. Okay.

check. I know. Do you see? Do you guys see my screen right now or not yet? Okay, let me try again. Do we see it now? >> Yes. >> Okay. Um, so for those who might not have joined last time, my name is Milita. I'm deval engineer at ZK verify and I'm also doing u PhD in zero

knowledge proofs. So last time we have covered um modulus operations. Uh we had talked about cryptography and why is it essential in uh modern world of communication history of ciphers right and uh we did some um exciting uh exciting ciphers like visionary cipher and old ones like Caesar ones we have seen um uh um we have seen how the the old ones look like we have tried some of them uh both on paper and online. So now it's time for more exciting stuff. Uh but previously like uh do you guys have

any questions? If some of you have tried um at home using the tools I gave you, uh do you have any questions regarding that? Okay. So I see people doing this. It would be numb, right? Uh let me just check the chat. Uh, okay. Okay. So, it's uh Okay. Super cool. So, nothing um nothing that we uh need to talk about. Okay.

So, what are we going to do today? What is our agenda? Uh first of all um what is hash? Uh we'll try to calculate hash. I'm going to go through um some bitwise operations uh for all of us um to see you know it's important for you for you guys to see which ones are reversible and recoverable which ones are not. Um, we're going through symmetric cryptography, symmetric cryptography, key exchange. Um, and then we'll have some wrap up and QA time.

Okay. So, yes. So, why does does it matter that we have cryptography? Uh mostly yeah uh it's um data security privacy which we all roots uh for especially in these times of um super surveillance that we uh have seen around the world. People um losing access even to their bank accounts due to their opinions that they had on uh on on some topics in society. We have seen that in I think it was Canada and truck drivers they were protesting then next thing they know their assets were frozen. So it can be really really um challenging um to maintain privacy and um free

speech. Yeah. Um these past few weeks were very interesting in the EU uh because we had uh uh some proposition that um from I think it was fun um to be able to decrypt all the messages uh within the EU and uh people didn't really like it right um so yeah it's uh it's really important um so that we can have private chats so as we can have private chats somewhere in some um at some island, you know, just you know, expressing our feelings uh or or um you know, telling our deepest secrets to

someone else. U let's say we're having online sessions with um psychotherapist, right? We don't want all the whole all the world to know, you know, how we feel and and what are we going through except that one special person or our doctors or, you know, they're like there's so many uh sensitive data that we might want to protect and um and yeah, so next thing you know is you know when I'm um sending you the message let's say over telegram or somewhere else you want to be sure that that's me actually on the other end and not someone else trying to do some fishing on you like we had the previous day because it's the mainet

when the mainet approaches um you know all kinds of people trying to uh make you click this link because it will um double um your uh um your profits or something like that. Never do that. Uh so yeah in the end um why cryptography matters is because we're having blockchain and blockchain is operating on cryptography and and yeah so um people are not uh um people do not have a say in it and it's um censorship resistant.

Um, who here knows about pet wise operations? Okay, I see Hatton someone else. Mhm. Okay, I see it's like it looks like third of the people are familiar with that and uh the rest or like we're close to half. The rest of you guys are are not so sure. Um, okay. So, this table is full. I think I'll need to use the pen and paper method.

So, let's try. So, we're going to make um sort of a grid. Let's say what um let's say our inputs are uh zero. Let's say we have input A. We have input B, right? And this is the output area. You see that or like wly? Okay, I'll try something else. Uh let's see this work. Okay,

this will be much better. Let's try with much better, right? >> Much better. >> Super cool. Okay, so let's say like this. This is our input A. This is our input B and we're doing and operation. Okay. So here we have zero and zero and n says that the output will be zero.

So this is like the truth table of whole computer science behind it. It says that when one input is zero the other is one. Um this will also end up in zero. Uh the same goes here. This goes to zero. Only if both of them are one and one, it will end up in one. So this is your truth table, right? This is this was my favorite part of electronics, the digital electronics one, and I'll I'll never forget it. I had the best teacher. Um, yeah. So this is this is end function. So if you don't

know it by heart, um you might want to write that down. >> Okay. So everything is zero unless both of them are are true. >> Why? >> Something similar but very different is or function. or function is happy if we Oh, it's um Oh my god, I I see now it's in in reverse order because it's camera.

Sorry. Um how to resolve it now. Okay, I'll try writing in reverse. No actually >> no. It was better the other way. Yes, >> the other way was better. Then my then my slipping. >> Okay, so we my my camera is slipped. So I was like maybe I can I can write in reverse so you guys see it.

>> It would be amazing by the way. Like if you could in reverse order, would you respect like everything for science, right? So this is our truth table again. So it said like um first is zero, second is zero, output is zero. That's it. Then we have zero and one and said like this war says like either one or the other needs to be positive to for this one to be true. So this is

one one and zero gives us zero and one and one gives us one. Okay. But so let's uh let's try um let's try having uh um operations like this. Let's try with uh um let's say um 0 0 1 0 0 sorry one one uh one zero. Let's say we want to do and operation. Okay.

So let's try it. This is your starting values and tell me what you got. Everyone saying on the chat maybe I can say it loud so that we can you don't have to check for the chat.

Zero. >> Yeah. Yeah. I see people are saying 0 0 one zero. Don't hesitates to see better. Yeah. Yeah. So why do we have it? Um it says like when we have it this is this is like um adding like which are integers that we uh have g grown up in school with. So like it says like zero and zero when they add up. So an said like you are zero. When we have one and one we say like okay it's positive. These two are negative as per table. And this is our result. Uh let's do the same ones. 0 0 1 0

one one one zero. Let's do this one. This operation. And someone needs to tell me what's the result and why. I see people are saying so. Who wants to explain it? >> This is for and or for or operation >> it is or operation right now.

>> Yes. So this one says like okay like zero or zero says zero one or one says one one or one zero or one is one and same here. So this is our result. But we have a special very very very special function and cryptography that we really like and cherish. It's called or exclusive or and we will write AB output.

Too bad I don't have my table here so that you can see like everything how it's written but we have starting truth table. So what does source says? Exclusive or says uh that it only recognizes output as truth if it has like one or uh one or zero. So in this case it will be zero and in this case it will be zero because these two are the same and in this case it will be one only if they're are different we will have output truth.

Okay. So let's try let's give it a try with uh a being Okay. What will happen in this case? You guys have it in the chat.

Mhm. I see and Deisha got it right as well. Almost everyone So when we have zero zero one zero with one one one zero sort it will say I don't like this this is going to be zero right because they're looking the same these ones too likes diversity right so it It will take uh uh one only if they're different uh if they

have different inputs. But uh what happens is that um this is very um special example because sore function is the only one that is self-reversible. So if we try reversing from here, we will end up at the same path.

We don't have it. Uh this this is the only function in uh in bitwise in log logic operations that can do that and none uh all the others are um are not able to do it. So if we say like we just get the output with one of the uh one of the previous uh inputs it will give the previous input right and if we do let's say we want to do um we want to have something that's reversible to itself. health.

Sorry. And also, let me write up another page. >> This is how you turn everything to zeros. Whatever you take, let's say 0 1 0 1 and you want to add it to itself 0 1 01 you will end up with all the zeros. This is um very important attribute component of betice operations.

Yes. So, let's let's try something um let's try uh like any number like this one. Um sort with itself. What will you get? Okay. So now, yes, we're going to have

have all the zeros. Now you're going to sort this one with this one. I have the smartest people here. Yes. Um, it will uh preserve the the input.

Yes. Super cool. Super cool. All right. I think uh we got it. Um are there any kind of questions with bit operations? They can be combined. Um it's um important for you to get what is and or ensur uh especially later for um exercises around circum uh because we're going to use it extensively there. Um and yeah, you have even negation and like all sorts of combinations and you can even make electronic circuits out of them and it's um it's

quite amazing field but I want to just check guys like are there any questions like there are no stupid questions um we have all been there where there was something that's uh um you know uh unknown to us and um I'll be happy that we clear everything out. I don't see any hands.

Okay. Okay. I'm happy that everything is um clear. Let's go to hash functions then. Um, so does anyone has anyone actually used hash function functions somewhere? Mhm. Yes. Hatton build the Merkel tree library. Uh, during that I use to hash the notes and hash them together as witness.

>> Okay. Okay. Super cool. So we uh have used uh hash for mark trees. Super cool example and very blockchain one. Uh Ros CSS for downloading files u for havinging the proof that we have a correct one. That's also an awesome use of hash transactions as in where Robertson passwords.

Okay. So we have uh uh we have uh um some knowledge around it. Um so yeah it's it's perfect. S Okay. As transaction ID. All right. Super cool. Okay. Uh so what is important with hash functions and um also why they are so effective where they uh practical because like whatever you put inside you will have fixed size outputs. So even if it's like two letters, let's let's say ZK right you will have the same size output based on um the hash function uh

uh size. So sometimes you will have 256 then you'll have 512 but it will always be the same the same output. Um what um all of it means is that you know even if you take whatever the longest book possible uh I mean the biggest book possible like the longest sentences whatever you put inside you will get um you will get the fixed uh size output. Um what is also important is that uh that function needs to be deterministic. So every time you put uh the same input you should have the same uh uh the same outputs they cannot uh be

different. Um otherwise you would not know how to uh recreate the hash right and compare it. And um yeah why are we doing all of that? Because we want to have irreversible output. So that is um that is something that uh we need to have and one of the the biggest properties. All right. Um the properties that a hash function needs to satisfy um I mean uh collision resistance of course and avalanche effects. I will um explain both of them what they are. Um,

so what does avalanche effect mean? Uh, is that you see these inputs that we have here? Uh, like fox or something else, something else. Um, you know, if we have the red fox jumps over the blue dog, if we say the red fox jumps over the blue cat, it should that it should have a completely different hash unrecognizable on of what we have here. And uh it should be that you cannot recover uh what you have um what you have what um with hashes.

Um also the collision resistance uh means that whatever we um put uh whatever we put that it should not like two different uh two different inputs should not result in the same output. Of course, it can happen. Uh theoretically, it can happen. But that's why we have um these uh big hash tables and uh and uh uh bigger uh bigger sizes of hashes be strictly because of that. We we don't want that. Uh but it's it's very rare. But uh yes, collisions can happen. You see here in this picture

that um uh some let's say like jumps over the blue dog someone changed to from V to U and the output of uh the the the hash function we call it digest but it's um uh for me it's like I I like to to keep um something simpler especially from for the beginning as we are now. uh but yeah it's called digest so that you know it's uh it doesn't have to do anything with human body it is actually uh something that the hash function has digested and gave you right so every time you like you know you get some um some letter out or you change it or you change the order you get something completely different um so

let's see like from the the second input it start with 0086 um You change one letter in the middle of the sentence, it starts with 8, F, D, uh, 8. Then you change something else, it's F, C, D3, etc. Right? So, so this is what we want to have. Uh, this is called the avalanche effect. Why avalanche? Because it said like, oh, um, you just, uh, change this small thing and you have a huge change in the end.

That's why it's called the avalanche effect. Okay. Uh let me just move all the the the zoom controls that I have on my screen. Uh yeah, you some of the the examples of the hash algorithms is um so there there is MD5, SHA one, SHA 256, SHA 3 etc. Um I will not get go into the details of how all of them work. Um and this is why like all of these hashes and most of the cryptographic functions they rely on um trying to uh um trying to cover their

trails let's say. So, so you want to you want to cover like what room you went through this building and you you just left some trails. So you will end up with um electronic code book uh where like uh if you if you came let's say from one side you will see like okay this electronic code book says I'm going to the other side uh but I'm going to enter um let's say elevator number 11 or something else something like that uh or you will go to the the cipher block um cipher blocks and you know it will counters and like you you will you'll change uh uh and merge block. So it's like all the time it's like hey how can

we complicate the life of hackers right? So it's going to be very diff we're going to we want to make uh um life very difficult for them so they they cannot uncover um our secrets. But uh yeah, so for now it's important for you to know that um examples like this exist. Okay. So yeah, you guys told me that some of uh the times you have used u um hashes as for for password storage. So you know when um someone leaks the password they they just have hash. So they cannot do much with that right even

if they know uh the even if they know that maybe they have used let's say um sh uh uh 256 it's going to be very very terrible difficult job for them um to come to the original password and actually obtain all of your data and that is the standard uh when you're storing passwords but still some people I don't know why um they store it in plain text and um then they're like hacked and they they were like, "Oh, we never thought it's going to happen to us." But that's why we have hash functions and that's why we should use them because once you have input on your site with uh your your password and your username and password, um you want that

to be um you want to get the digest of it and you know just compare it. uh you want that the database just compares it with their um with their uh already existing hash but not to store it and yeah uh I think Rosio told us for um was it for for downloaded files to to uh do the integrity checking digital signatures and and blockchain that's for sure. So um you have uh all sides um uh of application, right?

Yeah. Let's go to visual examples, right? Because we're not we are visual beings. That's why we have two uh we have uh uh two eyes and one mouth and two ears so that we can hear and see more than we can talk. Uh which is obviously not the case today for me. But let's go. Let's go to this uh visual example. Uh let me check. Uh I will copy this link for you. Uh uh um okay and send it to you to to where is chat.

I'll never be able to understand zoom completely here. So let's try some examples like boot camp, right? Because we now have it here. So this is uh the output that it gives us. You can um use some other hashes.

This is uh 256. And uh let's try with the big B and see how the output will change. You see it's completely changed. Okay. Uh so now it's um it's up to you guys. Do you want to try it out? Uh I'll um I would like to recommend it to you.

So let's make um hashes let's say of our names. You can you can post it in the chat. Mhm. That's it.

Okay. Okay. Uh you can play with the tool if you want and um and see you know uh maybe even um send other people your own hashes and um uh check it compare it with the original messages. Uh but yeah like I would like to see if um you know if we can do toy hashes by hand. Um so uh just to just to see um uh how it looks like. Let me just check one thing.

Uh uh uh. All right. All right. Okay. Let's um before we go to explanations like how hashes work, uh we're going to go and compare um hashes. uh for example for for cat. So why do we have it? Uh why do we have 16 in the end? It's uh because we took uh s key codes of cat and every letter and uh because we want to um do um we

want to sum it and to do the modulus in the end. uh we're going to do modulus um at the very end and we'll get uh from 216 modulus 100 will get 16. But um let's try doing the same thing for these two words a gentleman and elegant man and let's compare it. I will write it down. So both of them should be with no capital letters

but it's a bit impossible here. Okay. So, we'll put um here you have it in chat. Please let me know when it's when you got it. So the idea is to use the ask key

characters, add them up and um and have a com a comparison between a hash of so hash of a gentleman and then elegant man. So like first one okay let me just gent the second one is alant um in see car and as characters um method is

Method is edition modules hundreds. Here you go. Oh, can you uh recalculate

uh the second one, the elegant man? Okay. So, um most of the people I see in

chat said they got 84 in and both. Can someone explain why? Because both both sentences uses the same letters. >> Uh you mean uh there both of them are using they have the same letters, right?

>> Yes. >> And this is what we have. We have collision uh because uh we got acronyms. So we can do the same thing for cat and act or listen and silent. So yeah but uh we will always have the same um yeah but this is um this is like uh some of the examples where you can have collision if you're doing it uh by hand. Okay. Someone said, "I think there are two different words." Yes. Yes, there are two different words. We just wanted to have

um we just wanted to experience I wanted to experience you. I wanted you to experience um the collision effect which we got. Bravo for everyone who got it right. Uh yeah, let's um let's go further. Super cool. Uh I'm not sure there is my screen. Where is it? Okay. So using notebooks and pencils we got that because these are the acronyms we got the same result which is um AP forum.

Super cool. Okay. Uh yeah. So these are the two different words with the same hash. And that also means that our hash pool is um is um if we have a smaller hash pool. But um we can even try um yeah we tried this one with the avalanche effect. Uh but we can you can you know always try to get you know the the collision it's going to be difficult but with um smaller uh hash tables you will definitely got it.

Uh so yeah let's see uh hash uh examples used in in blockchain. This is one of my favorite examples of a blockchain demo. Um, I will post this in chat. Just find chat. Where? Where is chat? Okay, it's here. It's not. It's hidden. Zoom is hiding things for me.

Mhm. Yeah. So I want you to see the hash in in um in action. Um so if you see like okay like whatever you try to change here with any data boom all the others are going to be red. Um there are like options here to calculate any hash. Right. This is SHA 256. Um, this is for mining the block. So, it needs to find um in blockchain it wants to have a first four zeros. So, maybe you can, you know, try it out and uh see when you're going to Oh, wow. We

had one zero in the beginning. But it needs to mine uh to find such a digest in in hash terms so that it has uh first uh four zeros as as as a as a digest which is quite difficult and you can try it out but it's it's not going to work like this. I I cannot uh mine it so good. Uh but yeah uh we we can uh we can do it um if we have um functions.

So here we need always to mine this one and then uh you know since the previous um let's say okay mine so we have a previous hash here uh starting four zeros 12 etc. This is that's one right and if we change it because here we're using the previous hash as well for uh computing the other hash then it's going to be um it's going to be uh um something that's not going to be accepted and we need to find more zeros and to mine everything.

Um this is uh this is something that uh all um the blockchains are using and that's how the chain is created. So actually chain is created with hashes. This is the the prime example of um hash usages because we're using the previous hash to calculate the the current one. Uh first one is all zeros all the time. Uh and then uh Next time you need to use the block number, the nons and data and the previous hash to compute the the new one. Um you need to calculate um uh you need to calculate new hash and um

especially like if you change something uh in in the middle of the chain, you need to calculate all the rest and your chain needs to be the longest to be accepted by um by blockchain. Uh but um since it's very difficult and people around the world are trying to find the same form of a hash uh then it's um usually you won't be able to send yourself 100 bitcoins because why not. Uh but yeah that's uh that's the case. So here I paste I think I got uh pasted yeah I pasted this uh demo for you guys so that you can um you can try it out yourself.

But um basically this is what um this this is like uh the the usage of hash and why are we doing all of that. So with uh let me see uh with with hash um how does it like practically look like? Let's see. Uh maybe I can chart out something really quickly here. So you can imagine like yeah but minute so why would we have you know why would we have uh uh the fixed uh you know number of outputs and like oh but maybe like someone can break it. Um how does

how does it even work? Like yeah now we see it practically but yeah like how does it even work? Um you know where's the where's the where the practice of it? So, I'll try to show it. Um, let's just uh stop sharing so that you can see my camera better. But I want you to imagine it this way. So, let's try um let's say that we have um let's say that we have uh um digits like this. like this is maybe like the the beginning state 1 6 07

93. So this is like the the the state of zero right? And you know this this looks like those like padlocks, right? That we have uh when someone wants to lock their bike or something like that. Have someone seen something like that with with these uh numbers that you have to you have to move the dial in the proper place so that it unlocks. Yeah, I I see I see people got it right.

So super cool. So um you can imagine hash like you got something here and then it's this moves to position three this moves to whole circle and then position zero because we have the modulus right uh this we're going to work within modulus 10 field because we're going to have uh yeah suitcases also have the umbrella Tanya yeah so you can imagine like okay like we have one uh one entry and this moves to something like like this.

It's it doesn't look really relatable to the previous one. But then uh we got uh something else and then it changes to let's say one 8 five six or two and then it starts being unrecognizable from the previous one. you don't know how what what operations to to go to so that so that you can reach the the the original state and try but uh but yeah like you you maybe know the original state but you don't know the operations like what to do right so um that's how it looks like so you know like you just

put some input and like it kind of like dances through uh all of the the the digits and uh then you end up with something else and that's essentially your hash. So this is like um this is like some simpler simpler um explanation of hash but uh guys how it works um within it's uh it's a lot of maths but um uh it has even some initial um initial hash values and Some of them are

consisting let's say um 32bit uh words uh that are eight of them and especially for SH 256 and uh the words are being um I think they're using uh fractional parts of square roots uh of the first eight prime numbers and all of that needs to be within the the the 32 32 bits. So they're taking the first 32-bit parts and that's how it how it looks like.

Yeah. So it's like quite um quite a process and um then you have those initial values and I don't want to get into all of that because I think uh I will discourage uh out of uh um how many participants we have here maybe one will maybe one will stay and say like okay this is this is all right but I want uh all of you to stay until the end of lecture so that we can go through some um smaller examples because what is the value of it if you go out you know um rememberingly yeah like uh uh fractions uh eight words 32

bits um uh you know quadrat squares first first eight primes like no uh even like last time people were complaining that uh their their brains are fried we don't want that I mean we want it mid-fried you know like medium rare so yeah let's uh let's go to some other examples and um this is with this we have wrapped hashes any questions so question is like so there is an infinite number of function hashes that

exist we are just using SHA 256 because it's the best one or because why is this one the most used? Uh, so for now it's SHA 3. I think it's um it's um SHA let me check. Um I'll I can I can give you guys the list back of uh in the chat of the most secure um hash ones uh hash functions. Uh but uh why um why are some hash functions better than others is because of the collision resistance uh the most. Um so yeah, let's say they have a bigger field

or like less chances of uh two different uh inputs ending up in the same hash. So everybody currently use this one or people still like choose different hash function in depending on what their use cases or it's more like there is one best hash function and everybody goes with it. Um well so there are like industry standards um let's say um uh SHA 3 um it's uh it's the I think it's like named after being the third generation of um secure hash

algorithms that's uh the abbreviation of SHA right um so it's um it's mostly you know when we see something else has been proven proven uh to work better then uh the whole industry will go after that. >> Okay. >> Yeah. And then you can you can develop your own uh hash function. Uh yeah play around with it.

>> That would be cool. >> Yeah, why not? Um there are get repos uh with uh with that to help you especially I know using Python for example so that uh people will find it easier but you can use um any language and you will be able to get some um hash function maybe invent some new industry standard who knows Uh those hash functions are already open source. Yes.

If you don't have it uh I mean for the public communication if you do not have it on the other side then it's not really useful if you just uh obtain let's say you obtaining a file with the hash and it says like this hash is produced using SHA 3 and if you do not know what SHA 3 is or you do not uh have the possibility to calculate it u then um you know you will not be able to check um the the authenticity of the file.

Anything else? I imagine that there is people that tries to break um these hashes. So, but they probably can read a number and they don't know which hash algorithm was used. So they probably try out all of them like brute forcing. >> Yeah. Um there are um people are trying to break apart uh blockchain as well and in the same uh manner almost but um yeah for now it's um it's uh the difficulty is hard.

John says if there's a script that can break shot 256. Um yeah, maybe you can try finding something. Uh I'm not sure about it or if it's public, but you can always try making your own, right? Okay, any other questions or we can go there. Birthday attack.

Someone knows their stuff. Hatton, can you can you tell us about the birthday attack? >> Oh, maybe I I will try. I will try my best. Um as far as we know uh we have an infinite uh amount of inputs in the hash function and we are trying to map it in a finite um set. So uh in some cases there are some collusions as we u mentioned in the class and in the birthday attack uh we are not trying to find a specific hash value like I'm not trying to find the um for example dev tree pack hash but I'm trying to find uh two collapsed

um hash values and the name actually come from a really school problem, birthday problem. Uh the problem asks that uh in a room at least how many people should be in a room so that two people have the same birthday actually maybe we can even try here because uh the answer is surprisingly only 23 as I remember I don't I don't remember exactly but um it must be 23 because um what you need to think about that you're not trying to find a specific birthday you are trying to find two uh two identical birthdays. So it is confirmed

that and yeah in some cases birthday attack can be used actually I tried to uh like not directly do the birthday attack but while I was trying to hash values I tried to find a special special hash values with changing values inside of my input. So it is something like that. It it is not too long. I'm so sorry. I'm Yeah. >> Yeah. We we can try it. Um if all of us write down our uh just uh then write the month and the date.

Yeah. Let's try. >> Yeah. Let me write my birthday. Oh, we have >> Oh, we already got a match.

>> Yeah. And it's with me. >> Wow. >> That's That's so interesting. >> Let's see if we're going to have another match. >> Loop. Almost. We were almost um 28th of October. Wow. So many people left October.

October season. Who is in death connect days? There is even uh the distribution of birthdays like how which one are the rarest and which one are the most frequent ones and um that is um that is actually uh um contributing to the the birthday attack. Yeah, >> I think all the people have put down

their birthdays and yeah, maybe some people are secretly want their birthdays to be public. Super cool. Super cool. We are going to have someone in the dev connect dates. Yes. Ridiculous has connect birthday. Super cool. All right.

Keep the birthday secret. Um, okay. We can let's let's go further with our lessons. Okay, we have tried uh proof of work. We have tried to uh trick uh the the hash to to start with four zeros. We even tried breach. Uh yeah. So we can go uh after hashes to symmetric cryptography. Yay. What does that mean?

Uh that means that um you can use the same key to um to encrypt and decrypt a message. Um so let's say that um your um secret key but like the problem is with that is that um you have to find uh uh you have to find a way to share uh that key. So we have advanced decryption standards and does that deprecated these are the algorithms.

Uh again I don't want to get too much into them uh because um uh yeah you can find that you can see that they're like at some point they're using uh um um chain blocks uh for for a dividing uh parts of um of the message and then uh encrypting and then switching the places adding some paths getting back sorting them uh doing all the the functions that are reversible. That's why we had theor example. Uh but uh yeah, these are the ones that if you want to take a look at them, they're quite advanced, but uh you can uh you can take a look. And if you

have any questions why some method was uh done including padding or something else, usually it's done to to keep the the length for operations the same. Okay. Um but yeah, if you have any questions, you can always reach out reach out in the group uh for a for and I'll be there to uh provide an answer. And if I do not if I do not know that um uh the exact answer I will always try and and find the proper solution for you. No worries.

So yeah uh we had it with um we had with simple uh uh cryptographic methods uh and the Asian one and not so ancient ones like which they are cipher and uh polyuse uh square and everything we had last time but uh we're going to try some advanced ones this time. I will get you the link uh this one where you can try some advanced ones. Uh let's see the chat.

Okay. Is there something else? Okay, this is your link guys. So provided that you see my screen um you see these are the cypher modes um this is uh chain blocks cipher blockchain uh this is electronic code book uh um this is uh counter and uh and that's u something that I did at the past you have even the initial vector that is recommended for um for for for

this one. Uh but let's say if you if you change it to something else, you won't have it anymore. So it's especially um important for a cipher block um uh chain. Uh but uh but yeah, let's see that um um let's let's try it out, right? Who wants to uh who wants to propose um the plain text and the secret key? We can put something like um

I don't know soon is deaf connect. Mhm. And then basically the secret key is a key that is able to encrypt and decrypt. >> Yeah. >> In both both side. Okay. Um we can put that three pack as the secret key. >> Mhm. >> Mhm. And then we're going to encrypt it. Okay, we need um let's say

okay we have it that's pack and because we are using cyber blockchain this is a bit um unsafe because we do not have the initial vector but I'm not going to uh overburden you with this but what we get what is Um what is the optional vector? >> Uh that's the initial vector. Uh that's um that's something that's used for the encryption um as as a basis for encryption. uh but to to improve the safety because otherwise it can this

type uh can be uh cyber blockchaining can be used uh uh as um it can be used uh to be vulnerable. Is it like what when we were on Monday, you know, choosing the padding like three or five for the letters? Is it like this like basically where we start? How how how is the padding etc? >> Uh you let's say that the closest you can imagine it to is um let's say that this is like the initial state somehow >> where like you do not start. You remember when we had the blockchain demo here and it sorry and it started with

zeros. So we we don't want that to be zeros for example and like we want to have initial vector that at least says something that's um uh that's not um always uh predictable, right? It's less prone to um it is less prone to to decryption that way. Uh that's um yeah yeah yeah okay let's uh try the advanced outputs uh this is the encrypted text this is the secret key and if we decrypt it it can say yes

so it is ste connect yeah perfect uh if you want to read more about uh padding um you can uh you can use this link uh which uh uh cipher modes are there uh why are we using paddings uh more about um initial vectors um so yeah it's um it's basically the randomization of the the similar blocks that are um that are initial ones then how it's how um whole chaining for example and um switching of blocks begins.

So yeah, why do we have key size and bits? What does that mean? And um and yeah, that's something you can uh try to um you can try use this tool to just do a bit more of research. And uh yeah it's um you can you can use like the galleries counter modes um the regular counter modes and uh you can even change the other to the other uh encryption tools.

Yes, I think uh they are here and then you can you can use them more of them. Anyway, let's go back. So, yeah, we had plain text cipher text and we got back to plain text, right? Uh using the same incipher text. So, yeah, pros and cons. Uh we always need to measure them, right? Um so, because uh we need some practical use. um everyday use even. So yeah, they're fast, they're quite efficient. You have seen how fast they can uh produce

uh the the output. But the problem is you know um how will I tell uh to Lupe or Margari Margawi that you know our um our you know cipher cipher is going to be uh the secret is going to be dev 3 pack dev3 pack because someone can eaves drop right and that's going to be a problem for us. Uh yeah. So how to you know change it? What can we do? Because usually we have Alice and Bob who communicate and then we have Eve who's trying to be a bit evil and get all of their secrets and

then maybe start a gossip with it and we don't want that right. Um so uh we want our secrets to remain uh secret. uh yeah so historical methods we remember Caesar from the last uh session right uh where he was uh trying to uh use the pre-shared secret uh or like um you know someone has shared someone has said trusted couriers but um you know that was not as reliable and um yeah uh prone to attacks all the time especially you know whenever you have a human factor it will be it will be vulnerable modern solutions. Here we are. That's

why we are here. Um you want to go to towards ZK towards more modern cryptography and uh this is uh this is what you see. Uh um River Shammer Alman and Diffy Helman uh are modern cryptographic solutions that are made um I think it was like end of yeah end of the 20th century and beginning of 21st uh for some of them and the versions are um there are there new versions of those but um because you know there is always something that becomes a bit more vulnerable um so uh people are trying to um make them uh less uh prone to attacks.

How does it look like uh symmetric cryptography, right? Uh so we will have a public key and private key and you know you you were like people like how is it possible right? You know um to have like oh my god like my public key is public so everyone can take my public key. Uh but the thing is only you can open whatever is time with your public key you can open with private key and uh and then uh you know uh with um you can even create something called the digital envelope um I was um writing my masters on application of that where you take um

let's say you take um the recipient's public key. Sign it with that and um you take your private key and sign the same message and only that person can um uh can open it with their private key and they can verify it came directly from you if they know your public key. Uh so that is uh something that is an interesting example. But uh for now let's keep it um very simple where we're going to uh you know just acknowledge that if you have um someone's uh uh uh if if someone signed uh a message with

your public key you are the only one that can open it. Yeah. So there are two uh algorithms that um are being core to it. Uh one of them is um elliptic curve cryptography. Uh we're going to um we're going to cover it uh as well. I'm not sure about uh the yeah I think we can uh we can cover it uh as well today and um yeah so let's see let's see how uh we can uh go through it to apply it. So, one of the huge applications are digital

signatures. You can see them in um HTTPS like um to all of the websites. You can always check their digital signature. Uh but um yeah, do you guys know any of the applications on it for banking like sending like payment or stuff like this? >> Mhm. Mhm. [Music] Okay. Someone else.

Okay. So, yesh, let's see. Pros and cons. um it is slower but it's solving the distribution problem the key distribution problem so um it's never without trade right uh so the helmet key exchange as I said like get um invented um later 20th century so um these two guys were thinking you know how can we you know exchange how can we exchange um our um our keys without them being exposed. Uh you know by sitting in two different uh sides of

the planet where we are not able to just hand in uh keys and um do a handshake and um it's uh yeah that's like first um key exchange that was actually practical one. Uh before that you would need to secretly share key and it would uh mostly rely on it being in person or trusted source or something else and we want to make things trust less.

Uh it's relying on discrete logarithm problem uh that um that we're going to see in a while. Yes, that's why we need it. Uh we don't want to have safe channels. We don't want to to have it as a requirement. And uh I want to show you the discrete logarithm problem uh by having the color mixed and um let's let's see how it goes. So you see like we have uh three main colors right here and if we mix two

these are the three prime colors right and then we have the color wheel um that can actually end up in like infinite number of of colors and if we want to present them in hexa value uh they will be in in a couple of letters right uh like RGB B red, green, and blue. Uh but uh uh but yeah, here um let's say that we're using primary colors as we use them in school, not as the light mixing.

So once we combine uh blue and uh red, we will end up with a purple. Um red and uh yellow will produce something that's close to orange here on this chart. uh yellow and blue will end up and having green. Uh and you know once you take a look at these colors you can say like yeah this purple it's usually com it's it it looks like a combination of two primary colors. Uh but uh yeah, you are not able to tell exactly which blue one and which red one is giving that ex you know that exact same color.

especially if we're not um if we're not combining the primary colors but their derivatives that are um on the on the other on at the end uh um as their result of mixing primary colors and then try to combine them with the primary colors will end up something we see here sorry something we see here um on the in the right uh um right bottom angle uh right bottom part where like we don't know this is this looks like a magenta to me the first one and like I wouldn't know which exact colors gave that

so or like something like lemon green like yeah maybe I can guess but I would not be able to give like exact hexa value of that uh color and because there's like almost like infinite inite number of uh of colors if we want to do it like in nature it's difficult to mix all of them uh and and find uh where we started and we need to have exactly let's say two colors or three colors or like we need to know um exactly like um the amount of main colors and um in milliliters for example to get there and not using any secondary colors. So that

that's the trick. It's it's easy to mix them but it's very difficult to find the origins and for anyone who's not familiar with the discrete logarithm this is a problem this is how we can uh take a look at that. Uh so um enough of chatting uh we're going to do uh we're going to do some um example like a practical one. So, we're going to use uh we're going to do the step by step. Um, and how it usually looks like there is like one person Alice, she is going to she's to communicate with Bob and there is

someone in between that wants to listen to them and to eaves drop on the whole conversation and uh to get right the the key or something and they would uh publicly agree uh on two numbers. Then they will uh they will um uh they will find um they will like randomly select some uh prime number of theirs and uh they will uh calculate using um they will do the calculations uh using the first ones that they have shared publicly and uh I will just show it in um in a bit but this is how it looks like. So first of all they agree

on um two um secret uh first of all they agree on two secret numbers they sorry two public numbers that anyone can eaves drop on even um that you know she wants to make some gossip or I don't know and steal their uh secrets uh you know and uh then like they elect to secret numbers then they do the calculations and then they have a shared trusted um a shared trusted secret that no one can calculate because it's based on discrete logarithm problem of the color wheel that we just had.

So we will try it in practice. This is this is your calculation and um let's try it with the pen and paper because we're not we have it. >> Someone have a cat. >> Yeah.

So, let's say I'll need to have it like this. Uh, you can write down with me. Um, let me check. Uh, okay. I will then, uh, stop sharing and you will see it on my notebook. So, let's see. Alice and Bob.

And here is some like Eve that's trying to ease drop on all of them. Camera is trying to follow my my face, but I want it to follow my my notebook. So I I'll maybe I'll need to be like this. I don't know. Okay. Um, so what what do we have here? Yeah, it's so funny, right? Okay, so let's uh let's uh let's acknowledge that there are like three people that wants to um there's like two people that want to to have a secret conversation. There's the third person who wants to uh join them and steal their secrets and Alice and Bob are

trying to protect against that. um they're trying to agree and they will agree publicly on a prime modulus and a generator. So this is what it looks like three mod 17. So I'll um I'll ask you to write this down like 3 mod 70. Okay, everybody got it?

Okay, let me check the comments. Eve is evil. Maybe she's jealous. Maybe she's just jealous. Who knows, right? Is Is um jealousy evil? Maybe it is. Uh okay. Yeah. Uh okay. Super cool. So, uh it's for me. I see it's reverted. I hope for you is not. Okay, >> it's perfectly fine.

>> Okay, if it's perfectly fine then all of us we're fine. Okay, so Alice will select private random number. Let's say 15. What she will do? She will calculate 3 to the power of 15 modulus 17.

Who can say what this ends up with? What's the result of this one? It's three again. This is Alice's. So 3 to the power of 15 then modulus 17. John says six

and then says nine. Louis says six. Any any other answers? Someone says three. Then we got six again. And then we got six again.

Then six again. I I would say the major consensus is six. Right. Let's write that down. Okay. So we would say it's sex. So what will happen here is that Alice will say okay says here Bob I'm sending you number six.

You should write uh you should write this down. You should write this down because I'm I suppose I will get questions. Okay. So, what will Bob do? Bob will also select uh a private let's say random number like Alice did with 15. He will select let's say 13 for the sake of the calculation.

What will he do? He will um calculate because they have agreed to a prime modulus and a generator 17 and three right. Um he will uh um he will take 3 to the power of 13 modulus 17. What will we have as a result here?

Ariel said 12. Aliot said 12. Hatton 12. John 12. Mgalli 12. The consensus is there, right? Yes, it is 12. So we have Bob's calculation here. We have Alice's calculation here. Alice sends six to Bob. Bob will send to Alice 12.

Okay. And what's what's the next thing that will happen? they will need uh so they want to have right the the secret the shared secret. So now that we know that Alice calculated six sent six um right to Bob and Bob said like okay I will do the same thing and then he sent 12 to Alice. Chad are we are we uh writing this down in our notebooks?

>> Oh yes. >> Okay. Okay. Perfect. This is the core of key exchange. So it's important that you guys have it written down. Um so what will happen now? Alice um she got let's say uh she got uh uh her private number 15. She got um 12 from uh Bob, right? So what will she do? Um so Alice will do the following operation. I don't know that this camera got me well. Okay.

Um Alice will uh take Bob's public result 12 and her private key that she randomly selected in the beginning. We do remember 15 and she will calculate like this 12 to the^ of 15 modulus 17 chat. What is this? A real system.

and Almas as well. Wow. Okay. Now we have consensus. Yes, it is 10. Perfect. Next thing you know, Bob says like, "All right, I need to do the same thing."

So Bob says like, "Okay, uh you know what? like um I will take what Alice gave me uh her public result six and my uh private key 13 and he will calculate modulus 17. What will this be chat? This one. Super cool. It's 10 again.

That means that both Alice and Bob they uh they were be they were able to um obtain the same shared secret uh without revealing it to anyone. Can someone explain how is this possible? Like how are how are they able to to do such thing? Magic of the math. Yes, Rosia the matrix. Show it once more. Which

which part? Uh which part John? The last part. Okay, let me just hit again. We have we have gone through um a lot of pages. This one. Mhm. No worries.

So if we remember they have um uh they have uh done um they have public agree on the prime modulus and the generator that's been three and 17 and um when the calculations are done um basically what uh they had is just in the reverse order. They had 3 to the power of 15 to the power of 13 modulus 17 and then 3 to the^ of 13 power of 15 modulus 17.

It ends as the same. It's it ends up in the same result. But because these two were secret uh that's what they have um um privately um privately elected and generated then um it was uh impossible for Eve to get them and to you know it's easy to calculate this one but it's difficult to get uh to get it from six or 12. That is the discrete logarithm problem.

Does someone need uh need to repeat any part or do we want to uh you know is there something that's unclear? I'll be um more than happy to repeat any part. Yeah, magic of the mat. It's really cool. Yeah, bravo defy Helman. Kudos to them for this invention. No questions. How I wish I was a

mathematician. Yes. It's so interesting, right? No questions at this point. I'm surprised. Okay. Uh let's um let's go uh uh further. So yeah, this is what we did. We did this uh computations and uh we have um provided a shared secret. We done this with you. We checked the result. Um

yeah, maybe if we have time uh we can assign pairs here so that you guys can share your own secrets. That's really cool idea by the way. >> Okay. Uh you know that you can uh privately message someone in uh in Zoom chat. So but even though like you know you can um you can say like uh you can even do it publicly and like you can calculate it and uh you will have your own shared

secret. You can just you know um tell the other person just for the sake of checking it out. Let's do it. Do you do you guys want me to make pairs or you guys will find someone? Let's say that you know uh Hatun you can find someone uh let's say Hatun and let's say Hatun and Maggali Ariel and Lupe >> we were actually talking on uh privately and you chose us. So >> you see Tracy and Karolina.

Um this is Sen with O Ibraim and Rosilio Sara and Almas Tanya and Critical E. Uh let's see. Is it let's see Sara and Roberta Louise and Sa Tracy and Shiao uh Eela and Wes Sunday and Elenate Leonet sorry uh and John and Cojo and uh Rose uh you can uh you can share it with me because I'm the other

is there a specification on the number that we choose as a secret? >> Uh you should um let's see uh this is uh this is a prime you should have a prime modulus and a generator. So it should be uh this this will work actually for anything. >> So both must be primes. >> Yes. >> Oh, okay. >> You can you can put like five or seven or three or >> Okay.

Someone said I cannot do calculations. I have a question. When we calculate in

the example, we calculate three modular 17 and we get three. But let's say we get two for example then we need when we calculate uh for example well at least calculate three power 15 is it the three like the first three or is the result of the modulation >> I'm not sure I got that right >> um when I calculate three power 15 >> which three is it Um so they have in this example they have agreed

on uh publicly on these numbers three and 17. Okay. >> Yeah. >> And then Alice sorry randomly picks 15 and Bob randomly picks 13. >> Yeah. And this is the calculations that then they're doing like three to the power of 15 and in his case it's three to the power of whatever he has chosen ends up in this one. >> Okay, perfect. Thank you. [Laughter] So you can use for example three modulus

and then um some um some prime um so that you're not using like 54 um um you know um an exponential to like 120 something or like so the first number in the equation that you are uh choosing Um um you can you can uh choose it like you should be chosed to like three or five or something small. Uh but like when you have a a private random number then you can choose uh whatever as we see from this example Alice had chosen 15 which is um not a uh it's it's not a prime

number but your modulus should be prime. Was someone able to

u exchange secret in the process? foundation.

H Okay. Okay. You can use if um if choosing the the

the starting parameters is difficult, you can um you can choose what Alice and Buff have chosen. Three and 17. Uh three is a generator, 17 is a modulus. Um, and then at your secrets found the secret but like how can we

communicate like where did do we can use that secret in is or like where we can use that secret like we found the correct um we found the same value each other >> yeah you got it right >> and now maybe we can talk in the chat but only we two understand like How can we achieve this? >> So let's say like um uh you got like result Alice and Bob Alice had like they had 10, right?

Um so maybe you can um um let's say uh maybe you can use that like um like if it was like a big number it could be used for further encryption of something using uh other standards for example. Uh but yeah like it's it's a great question. Yeah, maybe you can um you know uh >> going to be so small maybe we can use Caesar ciphers because it is going to be small all of us going to be so small so that >> that number can be the shifted value like something like that. Yeah, sure.

Maybe you can use uh visionaire cipher based on if it's a 10, maybe you can say like okay because it's 10 uh maybe you can write it uh um um maybe you can write it let's say in um in as key characters no sorry yeah like you can write it in this letter ten and then put it on top and just you know add it Right. My Um, [Music] Okay everyone

with vision. That was super cool. Um, yeah. Okay, everyone. Uh, we have, um, some couple of minutes to, uh, discuss. I hope it was, uh, funny. uh to get your uh to do your um key exchange. Uh let me just um share the presentation back. Um so yeah this is uh like why cannot ease dropper compute secret right because um the discrete logarithm is uh very difficult to um uh that problem is very difficult to resolve. Um and let's

do some uh summary. So what are we using uh every uh part of modern cryptography for so what we have is hashes for integrity and security and for um you know checking uh the genuinity of the data. uh symmetric cryptography is used um you know I see you know you you got like key change but with the fee helman and then uh with your partner and then you're using um symmetric cryptography to um such as visionire the cipher that you can um calculate uh and make um you know your own uh secret chat within our telegram

group and like no one can read that right Um so yeah a symmetric um uh symmetric one uh cryptography it's resolving uh the problem of key distributions. So you have a private and public uh keys and at the end we also have leafy helman that we tried um like not only we have seen the example but we worked in pairs and got our um keys um exchanged and uh we had our secret uh um we had our secret uh shared that only we know. Uh so yeah, now it's the time for the kitten in the basket

with a question mark. Um sadly we do not have much time uh because um we we have uh to we have to go but I'll try to answer it as soon as possible. Um do anything you guys have now. >> This class was so fun. so much fun behind like trying to find it. It was amazing. >> Yeah. And also it was nice to understand how the math behind is working. Like it's not so hard. Um but it's super powerful.

>> Super cool. We had a couple of exercises and and I really enjoyed it. Let's let's check chat, right? You can practice um you have a group right with um with all the participants. So you can randomly choose someone and start exchanging um you know messages and then you can uh just communicate freely with your own um with your own encryption and chat and like uh at that point our chat we're going to turn into something that's completely uncomprehensible to everyone

else and uh but we will be able to read that one message. That's a good tool for gossiping. I will teach this to my friends that no one can read even though they got our messages. >> You know, even if they share it like uh it's going to be a bunch of anything. Super cool, guys. and and girls, girls, uh if you have any questions, uh just tag me and the group um because um I don't see uh much uh going on in chat

and yeah, let's uh let's try out cryptography in real world and where we want to where we can apply it and that's uh private messaging even in public. Thank you for the session. Thank you for inviting me. >> Thanks a lot. >> Thank you. >> Thank you everyone for being here. >> And um yeah, as usual, we'll put >> amazing.

>> We'll put the recording on on Telegram, on Google Classroom. Uh you will receive an email. So all good. Thanks for the animation. [Music] All right, so see you uh next um Monday. Um and we will see Melissa on Wednesday next week. Normally >> um Monday or Wednesday? Was it Monday? >> Wednesday. >> No, no, no. Monday.

>> Monday. Ah, Monday. Okay. Yes. No. Yeah. The Wednesday. All right. Good. So, take care and yeah, see you next next week. >> Thank you. >> Have fun. Bye. Bye. >> Bye. Bye.