Lesson 2: Under the Hood
90 minutes
Overview
Students are introduced to public-key cryptography, which uses a public and private key to encrypt messages. This system can also be used to verify messages by creating a unique signature that can be verified by anybody. Students then learn that this process is the basis for transactions on blockchain networks, where individuals exchange currency without needing to trust one another. Students use a widget to simulate several blockchain transactions, including mining blocks and adding them to the shared blockchain ledger.
Agenda
Objectives
Students will be able to:
- Explain how public key cryptography can help authenticate messages
- Explain how public key cryptography is used in blockchain technology
- Use public key cryptography to verify transactions on the blockchain
Preparation
- Review the slides, activity guides, and widgets
- Prepare copies of the activity guide for each student
- Prepare copies of the vocabulary notetaker for each student
- Follow the steps in the Before the Lesson section of the lesson plan. Several of these steps are optional
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the teachers
- Under the Hood - Slides
- [Key] Blockchain Scenarios - Answer Key
- [Key] Vocabulary Matching - Answer Key
For the students
- Blockchain Scenarios - Activity Guide
- How Blockchain Works: Under the Hood - Video
- Public-Key Encryption - Video
- Vocabulary Matching - Handout
Vocabulary
- Asymmetric Encryption - When different keys are used to encrypt and decrypt a message
- Consensus - A mechanism requiring enough people to agree which transactions are valid
- Decryption - Unscrambling a message to make it readable
- Encryption - Scrambling or changing a message to hide the original text
- Key - A secret password for unlocking a message
- Ledger - A record of all transactions in a group
- Message Hash - a unique representation of an original message that has been transformed so it is unrecognizable.
- Message Signature - A unique encrypted message used to verify the sender of a message.
- Mining - When you continually generate new numbers to try and get a hash to start with a unique set of 0’s. This is a puzzle that can only be solved by guessing
- Nonce - A number used to try and change the hash of a block of messages so that it starts with a unique set of 0’s. It’s an abbreviation for “Number used once”
- Private Key - A key that is kept private so only a specific person can decrypt a message
- Proof of Work - Verifying information with a lot of computing effort
- Public Key - A key that is shared with everybody so anyone can encrypt a message
- Symmetric Encryption - When the same key is used to encrypt and decrypt a message
Teaching Guide
Before the Lesson
Preparing for Experiential Learning
This lesson is designed to create an immersive experience for students, where they participate in an activity or simulation which motivates the learning goals of the lesson. This creates a social, memorable, and engaging experience for students that helps transfer learning from this lesson to other aspects of their life, especially if this is the only lesson students engage in on this topic.
The pedagogy and teaching moves used in this lesson are based on Experiential Learning, which follows an Experience <> Reflect <> Think <> Act cycle. The teacher curates and guides an experience that students participate in, then students reflect on the experience leading to abstraction and meaning-making of the concepts embedded in the experience.
Because of the experiential nature, this lesson may feel messy and the classroom may feel chaotic. However, there may also be moments to elevate students' lived experiences and to capitalize on "teachable moments".
(Optional) Learn more about the pedagogy behind Experiential Learning
- Getting Started with Experiential Thinking
- The 10 Commandments of Experiental Learning (even though this is geared towards higher education, the themes still apply)
- What is experiential learning?
- Deep Dive: Experiential Learning Research Paper
Preparing to Teach Blockchain
This lesson centers around the How Blockchain Works: Under the Hood video - watch this video first before exploring the lesson plan. In this particular lesson, students watch the video first which introduces key concepts and vocabulary that students will use in their activity.
(Optional) If you want to dive deeper into blockchain and cryptocurrency concepts to be prepared for student questions, consider reading the Teaching How Blockchain Works - Tips & Resources doc.
(Optional) Teaching with Code.org
If you intend to teach all of the lessons and this is your first time using Code.org, consider watching our Getting Started with Code.org video series for an overview of how to navigate lesson plans, setup a classroom section, and other important features of the Code.org platform. Each video also has a support article if you'd prefer to read or print instructions - click here to learn more.
Warm Up (Option 1) (5 minutes)
Two Warm-Up Options: This lesson has two warm-up options, depending on whether or not this lesson is being taught within an existing computer science / cybersecurity course, or if it's being taught in sequence with out blockchain / cryptocurrency lessons.
Option 1 is for classrooms that are teaching this lesson as part of a computer science / cybersecurity course. This warm-up is more accessible to students who have recently thought about cybersecurity and can bring that knowledge into the lesson.
Option 2 is for classrooms that are teaching this lesson as part of a sequence on blockchain or cryptocurrencies. This warm-up makes an immediate connection to the blockchain to create a discussion about the blockchain right away before pivoting into cryptography.
Prompt: Two friends, Kim and Isaac, want to send secret messages to each other but their parents read all of their text messages. How do you think they can communicate with each other even if someone reads all of their messages?
Discussion Goal: Students may come up with several solutions to this problem:
- They could scramble the letters in their messages so, if someone were reading them, it would look like nonsense. Then the other person would know how to unscramble the message
- They could embed a secret message into an unimportant message. For example: by circling the first letter of each word to create a secret message, or by reading every third word.
- They could not use text messages at all and instead just meet in person to communicate
Remarks
These are all great examples of how two people could communicate secretly even when being watched. In today’s lesson, we’re going to look at how cryptography can help solve this problem and a few others. Then we’ll see how this system is vital to a modern invention for communication and the economy: the Blockchain.
Question of the Day: How is public key cryptography used in the Blockchain?
Warm Up (Option 2)
Two Warm-Up Options: This lesson has two warm-up options, depending on whether or not this lesson is being taught within an existing computer science / cybersecurity course, or if it's being taught in sequence with out blockchain / cryptocurrency lessons.
Option 2 is for classrooms that are teaching this lesson as part of a sequence on blockchain or cryptocurrencies. This warm-up makes an immediate connection to the blockchain to create a discussion about the blockchain right away before pivoting into cryptography.
Prompt: Imagine two people, Kim and Isaac, had to make a purchase without ever meeting: Kim wants to pay Isaac $300 for the latest gaming system. What problems could happen between Kim and Isaac while completing this transaction?
Discussion Goal: Students may come up with several responses, but focus on the ones involving trust. For example:
- Kim may not have all the money he says he has
- Isaac may not have a working gaming system and it will be broken on arrival
- How do they know they’re actually communicating with who they say they are?
- One of them may say they’ve completed their end of the bargain when they really haven’t
Remarks
These are all great examples of issues that come up when trying to make a transaction with a stranger. Many of them focused on issues of trust - that we can’t always believe what another person says. At a larger scale, this is still true in our modern economy. Today, we’ll talk about an invention that helped solve this problem: the blockchain. We’ll learn how it uses cryptography to help verify trust and allow people to exchange goods.
Question of the Day: How is public key cryptography used in the Blockchain?
Activity (80 minutes)
Public Key Encryption (15 minutes)
Building on Prior Knowledge: If students have recently completed a lesson on public-key cryptography, such as the lessons in our CS Principles course, then you could decide to skip watching the video below. It is a slightly edited version of the video that appears in these other lessons.
Remarks
We're going to watch a short video on cryptography. This video introduces a lot of new vocabulary - to help keep track of these new words, we'll use a notetaker to help match each word to its definition
Distribute: Pass out a copy of the Vocabulary Matching activity guide to each student. Students will use this while watching the video to identify vocabulary
Video: Show the Public-Key Encryption video
Vocabulary: Review the following vocabulary from the video. Allow students to check their answers from their matching notetaker.
- Encryption - Scrambling or changing a message to hide the original text
- Decryption - Unscrambling a message to make it readable
- Key - A secret password for unlocking a message
- Symmetric Encryption - When the same key is used to encrypt and decrypt a message
- Asymmetric Encryption - When different keys are used to encrypt and decrypt a message
- Public Key - A key that is shared with everybody so anyone can encrypt a message
- Private Key - A key that is kept private so only a specific person can decrypt a message
Managing Vocabulary: There’s a lot of vocabulary here! Instead of having students write all of it down, you may consider having pre-made posters or a word wall that students can refer to. The most important pieces to remember are the relationship between the public and private key, which is reinforced in the following slides.
Remarks
Let’s look at an example of how this can look on the internet
Display: Show the slides showing how a message can be encrypted and decrypted using public and private keys. The slide will animate automatically showing the process.
Slides | Speaker Notes |
---|---|
![]() | Say: In this example, Kim wants to send a secret message to Isaac. |
![]() | Say: She starts by taking Isaac’s public key and using it to encrypt her message. |
![]() | Say: The result is a string of letters and numbers that were specially created by Isaac’s public key. Kim sends this to Isaac. |
![]() | Say: In order to retrieve the original message, Isaac takes the encrypted message and uses his secret private key to decrypt it. |
![]() | Say: When Isaac decrypts with the private key, he reverses the encryption created by the public key and ends up with the original message. This is only possible because the two keys are created especially for this purpose. Encryption is great for making sure that no one else can read the messages you are sending. But there still could be a problem: how do we know for sure that the person sending the message is who they say they are? |
![]() | Say: How can we make sure the person we’re talking to is actually who they say they are? |
Remarks
Trusting the person that we’re talking to requires two things: a unique way to represent the message to make sure it wasn’t forged, and a way to verify the person who sent the message. The first part - representing messages in a unique way - can be solved with something called a message hash.
Vocabulary: Show the slide with the definition and visual for the following terms:
- Message Hash - a unique representation of an original message that has been transformed so it is unrecognizable.
Point out the last two examples on the slide, where the only difference is the capitalization. Emphasize that even though the original messages are very similar, the resulting hashes don’t look anything alike.
Password Hashing: One common use of hashing is an added layer of security to protect your passwords. When you create a password for a website, some websites won’t save the password itself but will instead just save the hash. When you type in your password, it first gets converted to the hash value and then compared to the saved hash that the website knows about. This adds security because if someone were to hack the website and look at the passwords, they wouldn’t be able to see the actual password - they would just see the hash.
Display: Show the next slide with the Hash Example. The slide has animations to click through:
- Clicking the first animation will show an example of the phrase "A dog barks" being converted into a hash by turning each letter into a number corresponding to its place in the alphabet. Creating these numbers is easy because we can clearly define what each letter maps onto
- Clicking the second animation shows what happens if you try to reverse-engineer the same hash numbers from the first example. Because it's not clear how to separate the numbers, it is hard to reconstruct the original phrase and you end up with jumbles instead.
Remarks
As we saw in the example, message hashes can help us make sure messages aren't forged. The second part - verifying the person who sent the message - requires creating a message signature, which is a unique message that can be used to verify who sent a message. This can be accomplished using public and private keys in reverse! Let’s look at an example.
Display: Show the slide presenting how public key cryptography can be used to verify the sender using a message signature.
Slides | Speaker Notes |
---|---|
![]() | Say: Let’s say Kim wants to send Isaac a message and prove that it came from her. |
![]() | Say: First, she converts the message into its message hash using a special process. The thing that makes a hash special is that it is unique to the original message. |
![]() | Say: Then Kim takes her private key and uses that to encrypt the message hash, creating another string of letters and numbers. This is the signature, which was created with the private key that only Kim has. |
![]() | Say: Now Kim is ready to send her message, which is now two parts: the original message and the signature. In this example, Kim isn’t using any additional encryption but she could if she wanted to. |
![]() | Say: Now we switch to Isaac’s perspective. Right now, Isaac can see both the signature and the message but he doesn’t know for sure that Kim sent it. Here are three steps he needs to take to verify if she sent the message. |
![]() | Say: Step 1 - he takes Kim’s public key and uses it to decrypt the signature. This reverses the encryption created by Kim’s private key. |
![]() | Say: Step 2 - Isaac takes the message he received and determines its hash using the same process Kim did. |
![]() | Say: Step 3 - Finally, Isaac compares the results from his two calculations to see if they match. In this case, they do! |
![]() | Say: Since Isaac used Kim’s public key to verify the signature, that means she was the only person who could’ve sent the message. |
Vocabulary: Display the following vocabulary for students to match on their activity guide
- Message Signature - A unique encrypted message used to verify the sender of a message.
Real-World Example - Website Certificates: Signatures are commonly used when browsing the web and visiting secured websites. Sometimes hackers try to create fake copies of websites to trick you into entering your password information - for example, a fake banking website. But, if the website doesn’t have the correct signature, then your browser will warn you that the website isn’t secure and you should be careful.
Remarks
So far, we've just been talking about encryption and it can seem really complicated. Let's start to look at a practical example of how people do this in practice.
Code Studio: Send students to Level 1 in Code Studio
Model: Show students how to use the widget to view different messages and the corresponding hash. Model how to verify the signature of a message by testing each public key:
- Use the orange arrows at the top to scroll through different messages
- Choose a public key from the table on the level and type it into the box, then press Verify Signature
- Check that the decrypted signature matches the original message hash. If it does, you’ve verified the signature!
Complete the first example together as a class
Distribute: Give each student a copy of the Blockchain Scenarios Activity Guide. Have students complete the section on verifying signatures. They can fill in one of the rows from the example completed as a class.
Circulate: Monitor that students verifying each signature. You can check-in with students as the widget is running to verify that they understand that the decrypted signature and the original hash should match in order to verify the sender.
Splitting the Lesson: If you need to split this lesson into two days, this is a good break point. Students should leave Day 1 with a better understanding of cryptography and encryption, and will start Day 2 learning how it's applied to Blockchain and Bitcoin.
Blockchain and Bitcoin
Remarks
Using encryption is important when trust can be an issue - for example, sending a secret message and not wanting someone to eavesdrop on it. Another situation where trust can be an issue is with money and finances - how can two people exchange goods without needing to trust each other? This is a problem that the Blockchain and Bitcoin have been able to solve
Video: Show students the How Blockchain Works: Under the Hood video (~6 minutes). Have students match the vocabulary words from the video on their notetaker as well.
Vocabulary: Display the slide with the following vocabulary. Allow students to check their matches from their notetaker.
- Ledger - A record of all transactions in a group
- Consensus - A mechanism requiring enough people to agree which transactions are valid
- Proof of Work - Verifying information with a lot of computing effort
Remarks
Blockchain technology helps solve the problem of exchanging money without relying on a shared sense of trust - instead, people trust the underlying technology: encryption. However, there is still the need to verify the transactions and add those transactions to the blockchain. This is what the blockchain miners do. Let’s see if we can simulate what it would be like to be a miner on the blockchain.
Code Studio: Send students to the next level in Code Studio. They will also be using their activity guide again.
Model: Show students how to view individual messages in the widget and how to use the public keys to verify signatures:
Widget | Modeling Notes |
---|---|
![]() |
|
Do This: As the class works together, have students record their answers on their activity guide for Blockchain Scenario 1. Decide as a class which messages to add to the blockchain, then continue to the next screen. Pause on this next screen to explain how this relates to Proof of Work.
Display: Display the following slides, which explains how the widget handles Proof of Work.
Slides | Speaker Notes |
---|---|
![]() | Say: When we have a single message block, we can convert that into a unique hash |
![]() | Say: As we add more blocks to our chain, we can convert all of the messages together into a unique hash. Each time we add a new message, the hash changes |
![]() | Say: To demonstrate our proof of work, we want to try and create a special hash. In this case, we want one that starts with two 0’s. This is like the special “puzzle piece” that will allow our blocks to join the rest of the blockchain. |
![]() | Say: To try and reach this goal, we add a special number to the end of our chain called a nonce, which stands for “Number used once”. Changing this number will also change hash that we get. Our job is to guess the correct number that solves the puzzle. |
![]() | Say: It turns out this takes a lot of work to find the right number that will work! This process is called mining - it’s when you continually generate new numbers to try and solve this special puzzle, which can only be solved by guessing. |
![]() | Say: Eventually though, you can find a number that matches! This is called the Proof of Work - it’s how you can prove to the rest of the blockchain network that you did the work to verify all of the signatures in your blocks. |
Vocabulary: Display the following vocabulary slide. Allow students to check their vocabulary matching notetaker.
- Nonce - A number used to try and change the hash of a block of messages so that it starts with a unique set of 0’s. It’s an abbreviation for “Number used once”.
- Mining - When you continually generate new numbers to try and get a hash to start with a unique set of 0’s. This is a puzzle that can only be solved by guessing.
Remarks
Trying to find the correct nonce can only be done with guessing and trying lots of combinations, which is what makes this a proof of work. Let’s look at how we can do this in the widget.
Model: Demonstrate how to iterate through various guesses to determine a correct nonce for the block:
Widget | Modeling Notes |
---|---|
![]() |
|
How Many Guesses? On average, it should take less than 100 guesses before the widget finds a nonce that works. However, there are many possible values that can solve the puzzle. Encourage students to share their nonce's with each other and compare which ones work
But Really - How Difficult Is This? The mechanism that this widget uses - generating a nonce so the start of a hash starts with a certain number of 0's - is actually how the bitcoin blockchain network works. The key difference is that it doesn't look for just two 0's in order to show proof of work. The actual number of zeroes varies depending on the number of miners on the network and is optimized so it takes around ~10 minutes for a group of miners to find a proof of work. Sometimes the network requires as many as 30 zeroes to show proof of work, which is too much guessing and checking for just one person!
Investigating Scenarios (20 minutes)
Remarks
Congratulations - we've successfully mined our first block on a blockchain! We looked at a pool of messages and verified their signatures, compiled them into a "block", then completed the proof of work that allows us to send this block to the rest of the blockchain. However, mining is not a collaborative activity - it's intentionally designed to be a competition, and that competition helps keep the network secure. Let's see who can be the first to mine new blocks in these next three scenarios!
Do This: Have students continue to work through the next 3 scenarios on Code Studio, filling in their activity guide as they continue.
Make it a Competition... These scenarios are an opportunity to create a dynamic classroom environment where students are "racing" to be the first to mine a blockchain block. You could consider having students compete within their groups, or you could encourage groups to work together to validate signatures and then try different nonce's for the block they create. The video mentions how the winning miner gets a little extra bitcoin - you could consider offering candy or high-fives to the first 4-5 groups who can mine a block.
...But don't go too far: Not all students will respond positively to a competitive classroom and may be discouraged from participating if the environment becomes too antagonistic. Even though competition is an intentional part of the Blockchain algorithm, be cautious in how much you lean into this during these scenarios.
Forged Messages: Each of these scenarios has at least one message that is forged, but students still have the option of adding it to their "block" to send to the network. This is also how the actual blockchain network works - however, it relies on the other miners on the network to verify the transactions themselves. If a student solves a block, make sure to ask them to share the messages that make up their block - if there are any forgeries in there, then the network (aka: the class) can reject the block!
Prompt: Look back at the scenarios in each of these levels. Since the transactions are public, we can see how these people are trading money. Look through the scenarios and see if you can identify one that seems like it has a pattern. What story can you tell about that scenario amongst that group of friends?
Discussion Goal: This is the same prompt repeated on the activity guide. Invite students to share any ideas or observations that they noticed while validating transactions. Some examples may include:
- in Blockchain Scenario 1: A group of friends paying each other back for meals when they can’t split the check and 1 person has to pay for everyone (similar to Venmo or Zelle transactions)
- in Blockchain Scenario 2: One person trying to create fraudulent transactions and steal money from others
- in Blockchain Scenario 3: Some kind of gambling ring, where everyone sends their “bets” to a central person who then redistributes it to the winner
- in Blockchain Scenario 4: One person gives “loans” to their friends, who pay it back later with a little extra as interest.
Wrap Up (5 minutes)
Prompt: The blockchain helps facilitate thousands of transactions each day between people who’ve never met or trust each other. Based on what you’ve seen today, how does cryptography help the Blockchain accomplish this goal?
This prompt is also on the last page of the activity guide. Students can write their responses first, then share with a neighbor before sharing out as a full class.
Discussion Goal: This discussion can help summarize some of the big-picture takeaways relating the blockchain to cryptography. Student answers may vary, but some responses may include:
- Signatures help verify that the person sending money is actually who they say they are
- The effort to verify all of the blocks contributes to the proof of work, ensuring that only accurate blocks are added to the blockchain
After the Lesson
Teacher Survey
We'd love to learn more about the folks teaching these lessons and the classroom experience. Please let us know in this How Blockchain Works Teacher Survey.
Extended Learning
Depending on your goals and student interests, you may decide to offer optional extensions related to blockchain and cryptocurrencies. Additional resources and the rest of the How Blockchain Works video series are available on https://code.org/blockchain, including a Blockchain & Cryptocurreny Hour of Code Activity.
This work is available under a Creative Commons License (CC BY-NC-SA 4.0).
If you are interested in licensing Code.org materials for commercial purposes contact us.