Lab 7: Neural Networks and Authentication
Lab 7: Neural Networks and Authentication
NetID:
Link to published notebook:
In this lab, we will have have a look at generating text using Neural Networks. We will also look at hash functions, symmetric & asymmetric key cryptography.
Part 1: Neural Networks to Generate Text
Part 1: Neural Networks to Generate Text
The GPT2 Transformer is a neural net model trained on WebText Data (preliminary version of the OpenWebText dataset, consisting of 40 GB of text scraped from webpages that have been curated by humans ) to generate text in English and represent text as a sequence of vectors.
A version of this neural net model is available in the Wolfram Neural Net Repository at https://resources.wolframcloud.com/NeuralNetRepository/resources/GPT2-Transformer-Trained-on-WebText-Data/
This model consists of a family of individual neural nets, each identified by a specific parameter combination. Inspect the available parameters:
In[]:=
NetModel["GPT2 Transformer Trained on WebText Data","ParametersInformation"]
Retrieve the language model by specifying the “Task” parameter:
In[]:=
lm=NetModel[{"GPT2 Transformer Trained on WebText Data","Task"->"LanguageModeling"}]
Out[]=
NetChain
What information is available about this particular model?
In[]:=
Information[lm]
What does the network graph look like?
In[]:=
Information[lm,"FullSummaryGraphic"]
How many layers does this neural network have?
In[]:=
Information[lm,"LayersCount"]
Problem 1
Problem 1
Problem 2
Problem 2
Part 2: Hash Functions
Part 2: Hash Functions
Hash functions take an arbitrary long, but finite, input and produce a fixed-size output based on that input:
In[]:=
book=ExampleData[{"Text","AliceInWonderland"}];
Hash[book]
The result of applying a hash function to the input data is called a digest (hash value, hash code, hash checksum). This digest serves as a reproducible representation of the input that detects any accidental or intentional change. Importantly, a digest is also very compact:
In[]:=
ByteCount[book]
In[]:=
ByteCount[Hash[book]]
Hash functions are commonly used to authenticate data integrity, to verify that the data received is indeed the data that was sent, with no alterations, or that “copies” of data stored in different locations are in fact the same.
Problem 3
Problem 3
Alice has to send her fellow scientist Bob a novel secret formula their lab has developed, so she attaches a file to an email and provides its “digest” or “hash checksum”:
Dear Bob, please find attached the molecule plot. The hash checksum is 2654733945256440784.
In[]:=
molecule=;
Calculate the hash of the 3D “molecule” above.
Answer
Answer
Problem 4
Problem 4
Is the calculated hash value same as what Alice sent? If not, what might be the reason?
Answer
Answer
Part 3: Symmetric-Key Cryptography
Part 3: Symmetric-Key Cryptography
Two-party communication using secret-key encryption
Two-party communication using secret-key encryption
The presented scheme describes the traditional approach of symmetric secret-key cryptography to secure communication.
Alice and Bob have agreed on the cipher and the key to encrypt their future messages:
In[]:=
key=SymmetricKey;
Alice uses the above key to encrypt the plaintext and sends the following ciphertext to Bob:
In[]:=
secretMessage=EncryptedObject;
Problem 5
Problem 5
Which key must Bob use to decrypt the message? Use the Decrypt function to decrypt the encrypted message and show what it says.
Answer
Answer
Hint: This is how you use the function
Decrypt[someSecretKey,someEncryptedMessage]
Problem 6
Problem 6
A single key is being used by both parties, and encryption and decryption functions are essentially an inverse of each other, which is the reason why this type of cryptography is also called symmetric cryptography.
While this has advantages like:
1) they can encrypt arbitrary big data
2) they are very efficient at it
Do you see any disadvantages of sharing the key? If so what?
While this has advantages like:
1) they can encrypt arbitrary big data
2) they are very efficient at it
Do you see any disadvantages of sharing the key? If so what?
Answer
Answer
Part 4: Asymmetric-key Cryptography
Part 4: Asymmetric-key Cryptography
Symmetric cryptosystems use one key to encrypt and decrypt traffic between two parties, which is a source of weakness that can be exploited.
An asymmetric cryptosystem instead deals with two keys per communicating party.
An asymmetric cryptosystem instead deals with two keys per communicating party.
Asymmetric cryptography introduces the concept of a public key, which, as its name suggests, does not need to be kept protected and may be shared with other parties over any open channel or even posted freely on your website. The secret that has to be kept hidden is its corresponding private key.
Exposing the public key does not put the private key or encrypted messages at risk. As opposed to symmetric algorithms, the sender does not have to share the secret private key with the receiver, only the public key. Each communicating party has their own pair of a public key, shared with others, and a private key, kept secret.
Exposing the public key does not put the private key or encrypted messages at risk. As opposed to symmetric algorithms, the sender does not have to share the secret private key with the receiver, only the public key. Each communicating party has their own pair of a public key, shared with others, and a private key, kept secret.
You may also imagine public-key encryption as a locked mailbox outside your house. Anyone who has your address can mail you a letter, but only you with the private key in your pocket can open the box and collect envelopes.
For Alice to receive messages encrypted with an asymmetric cipher, she needs to generate a key pair and send her public key to others or post it somewhere they can find it (personal website, company directory profile, etc.).
This is probably how Alice generated her public and private key. (You do not need to run the key in the commented part. It is just to give you an idea of how Alice probably generated the keys.)
Null
(*keysAlice=GenerateAsymmetricKeyPair[]*)
Here are the keys:
In[]:=
alicePrivateKey=PrivateKey;alicePublicKey=PublicKey;
Bob (uses Alice’s public key) sends the following message:
In[]:=
messageToAlice=EncryptedObject;
Problem 7
Problem 7
◼
If you are Alice, which key will you use to decrypt Bob's message?
◼
Use the Decrypt function to decrypt the message and show what it is.
Answer
Answer
Submitting your work
Submitting your work
1
. Publish your notebook
1
.1
.From the cloud notebook, click on “Publish” at the top right corner.
1
.2
.From the desktop notebook, use the menu option File -> Publish to Cloud
2
.Copy the published link
3
.Add it to the top of the notebook, below your netID
4
.Print to PDF
5
.Upload to Gradescope
6
.Just to be sure, maybe ping your TA Sattwik on Slack that you have submitted.