How do Machines Keep Secrets II
Ryan: FYS Computational Reasoning Fall 2025
Lecture content licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Playlist
REFERENCES/RESOURCES
See Also
IMAGES
Outline
CH 3 Asymmetric encryption
What did we learn from Eddy Woo?
RSA starts by generating a "key pair" - one private or secret and one public. So we sometimes write SK and PK
We can encrypt with either one.
We can decrypt with the "other" one only.
RSA (Rivest–Shamir–Adleman) is an asymmetric cryptographic algorithm algorithm used to encrypt and decrypt messages.
Asymmetric means one key is used to encrypt and another is used to decrypt.
Generate RSA Keys
Why "public" and "private"?
Two kinds of "secret keeping"
I want to create something that only you can read
I want to create something that you can be certain came from me.
RSA DEMO

ONLINE RSA
"Public Key Cryptography Standards"
CONFIDENTIALITY
-
You generate public and private key
- You tell me your public key
- I encrypt message with your public key
- I send you the encrypted message
- You decrypt message with your private key

Sending a message for your eyes only

For your eyes only
AUTHENTICATION
-
I generate public and private key
- I encrypt message with my private key
- I tell you my public key
- I send you the encrypted message
- You decrypt message with my public key

Sending a message you know comes from me

Anyone can read it and know it is from me
I'd like a secure session
Here is SPUBKEY
Here is ESPUBKEY(CPUBKEY)
ECPUBKEY("READY")
ESPUBKEY("REQUEST")
ECPUBKEY("RESPONSE")
DCPRIVKEY("READY")
process
DSPRIVKEY("REQUEST")
process
hacker
hacker
Server private key not available to hacker
Client private key not available to hacker
With What We Have So Far
Certificates
Start with information about yourself
Ask a trustee to validate and confirm
Trustee signs certificate with private key
Recipient uses trustee's public key to decrypt
If result matches certificate then it's valid.
I am Dan.
This IS Dan.
45ab98de7ff7ced213198005adfe
Skey(trustee)
Web connection receives certificate
Secure Web Exchange
Browser generates keys and sends public as "session" key, encrypted with server's public key.
Server encrypts web page content with session key.
Browser encrypts content to send with private session key.
Browser decrypts content with private key.
Server decrypts content with session key.
Certificate includes server's public key.
Hashing
Quick Interlude: Hashing

Hashing
- a hash function maps or converts arbitrary data (meaning data of any size) to a fixed sized piece of data in a more or less unique way
- that is, no two things will have the same hash
- in general it is a one way operation
- that is, you can't unhash the hash to find out what the original data was
HASHING REFERENCES
Example



Example
Example
1st letter of first name
3rd letter of first name
3rd letter of last name
1st letter of last name
length of first name
length of last name
dnracdgg
month of birth
date of birth mod 26*
* 1=a, 2=b, ..., 27=a, 28=b, 29=c, 30=d, 31=e
Cryptographic Hash
A cryptographic hash (sometimes called ‘digest’) is a kind of ‘signature’ for a text or a data file.
Cryptographic Hash
aa58b21b01d6b8a99c1a5856962dbac36c758a79dc0a77c2e013ce2c39ecdc8a

da
ec4f2dbb3b140095550c9afbbb69b5d6fd9e814b9da82fad0b34e9fcbe56f1cb

dan
Nam tristique hendrerit iaculis. Ut quis tortor velit. Proin posuere turpis ac mi tincidunt, id vulputate augue semper. Nulla finibus ex nisi, eget feugiat nisl sollicitudin sit amet. Suspendisse dui lorem, sollicitudin eget sodales vitae, gravida vel libero. Morbi elementum id mi non cursus. Proin hendrerit placerat sapien, ut placerat sapien tincidunt vel. Donec pellentesque justo neque, a faucibus odio rhoncus vitae. Quisque viverra aliquet pulvinar. Mauris porta urna vel porttitor rutrum. Quisque dictum finibus neque, ut convallis augue finibus ac. Suspendisse libero lorem, maximus ac tristique et, gravida eget diam. Donec semper dui metus. Pellentesque lobortis porta commodo. Aenean eu augue ultricies, fringilla augue nec, blandit arcu. Nunc consectetur libero tristique, ornare felis consectetur, tincidunt dolor. Nulla facilisi. Sed et feugiat mauris, ac dapibus leo. Etiam eget accumsan lacus. Nam facilisis tortor vel odio sollicitudin auctor. Maecenas quis vulputate enim. Aliquam condimentum justo leo, in bibendum magna fringilla ac. Phasellus a facilisis lorem. Quisque facilisis leo eros, non ultrices tellus volutpat at. Nulla et leo vehicula tellus egestas luctus sed mollis mauris. Maecenas lobortis nec risus sed convallis. Vivamus sit amet imperdiet quam. Cras maximus dui et pellentesque dignissim.
30293f4f02f784c4166a3e17109f01625bd1bfe97de2e017eebf9d23a55d9caf

We just learned two things
- Different sized inputs produce same size output
- Similarity in input does not mean similarity in output
Cryptographic Hash
A cryptographic hash (aka ‘digest’) is a transformation of a text or a data file into an almost-unique fixed length block of data.
A hash is not ‘encryption’ insofar as it cannot be decrypted back to the original text.
As a ‘one-way’ cryptographic function it can be used on a copy of a document and then compared to a hashed version of an original to verify that the copy is accurate to the original.
SHA-256
an algorithm that generates an almost-unique 256-bit (32-byte) signature for a text input.
Secure Hashing Algorithm 256 bit
SHA256 Pseudocode
SHA-256 Implemented in JS
DIGITAL SIGNATURE
-
I generate public and private key
- I create a hash of my document.
- I encrypt the hash with my private key (the signature)
- I tell you my public key
- I send you the message and the encrypted hash
- You hash the message and decrypt the signature with my public key
- If the two hashes match then you have the same document that I signed

HOW do I guarantee that I signed THIS document?


only you can read it
Information Security
- confidentiality: secrecy is maintained
- authenticity: it is from who it says
- integrity: it is what it says
How to operate on lots of data? Break it up into blocks. Blocks always same size. Padding.
How Machines Keep Secrets II
By Dan Ryan
How Machines Keep Secrets II
Asymmetric Encryption and Sending Secrets in Public
- 25