Creating a Crypto Chat Bot

I have my favouriate module of the year coming up in Semester 2: Applied Cryptography and Trust. Overall, it gives me a chance to cover…

Creating a Crypto Chat Bot

I have my favouriate module of the year coming up in Semester 2: Applied Cryptography and Trust. Overall, it gives me a chance to cover most of the key cryptographic principles. So, this year, I have been investigating the usage of a chat bot, and where I could try and answer most of the questions that come up year after year. For this, ChatGPT (Generative Pre-trained Transformer 3 — GPT-3) from openai.com looks to be an interesting development.

The playground for the crypto chat bot is here:

https://beta.openai.com/playground/p/JKa2K3ykmzStUvSEq0aSzSAU?model=text-davinci-003

With ChatGPT, we first provide it with some questions and answers:

I am a highly intelligent cryptography bot. If you ask me a question that is 
rooted in truth, I will give you the answer. If you ask me a question that is
nonsense, trickery, or has no clear answer, I will respond with "Unknown".

Q: Which is a hash function?
A: A hash function is a one-time function which takes any amount of data and converts it into a fixed length hash value.

Q: Which hash functions are insecure?
A: MD5 only has a 128-bit hash value and can create a hash collision within a reasonable amount of time. SHA-1 has a 160-bit hash value, and could be cracked with significant computing power.

Q: Which is the size of an MD5 hash?
A: 128 bits

Q: Which is the size of a SHA-1 hash?
A: 160 bits

Q: Which cryptography hashing method is most often used?
A: SHA-256

Q: Which is the size of the SHA-256 hash?
A: 256 bits.

Q: Which is the size of the SHA-512 hash?
A: 512 bits.

Q: Which is the fastest cryptographic hashing method?
A: BLAKE-3.

Q: Who created the MD5 hashing method?
A: Ron Rivest

Q: Which method did NIST standardize for SHA-3?
A: Keccak

Q: Which hashing method does SHA-3 use?
A: A sponge function

Q: Two messages which return the same hash value is known as what?
A: A hash collision

The code for this is then:

import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

start_sequence = "\nA:"
restart_sequence = "\n\nQ: "
message="I am a highly intelligent cryptography bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with \"Unknown\".\n\nQ: Which is a hash function?\nA: A hash function is a one-time function which takes any amount of data and converts it into a fixed length hash value.\n\nQ: Which hash functions are insecure?\nA: MD5 only has a 128-bit hash value and can create a hash collision within a reasonable amount of time. SHA-1 has a 160-bit hash value, and could be cracked with significant computing power.\n\nQ: Which is the size of an MD5 hash?\nA: 128 bits\n\nQ: Which is the size of a SHA-1 hash?\nA: 160 bits\n\nQ: Which cryptography hashing method is most often used?\nA: SHA-256\n\nQ: Which is the size of the SHA-256 hash?\nA: 256 bits.\n\nQ: Which is the size of the SHA-512 hash?\nA: 512 bits.\n\nQ: Which is the fastest cryptographic hashing method?\nA: BLAKE-3.\n\nQ: Who created the MD5 hashing method?\nA: Ron Rivest\n\nQ: Which method did NIST standardize for SHA-3?\nA: Keccak\n\nQ: Which hashing method does SHA-3 use?\nA: A sponge function\n\nQ: Two messages which return the same hash value is known as what?\nA: A hash collision \n\nQ: How large is the SHA-256 hash?\n\nA: 256 bits.\n\nQ: What is a hashing method?\nA: A hashing method is a mathematical algorithm that takes an input of any size and produces a fixed-length output. It is used to securely store and verify data, and is commonly used in cryptography.\n\nQ: SHA-3 uses which method? SHA-3 uses a sponge function.\n\n"
question="Q: Which is the most used hashing method and how many bits does it have?\nA:"

response = openai.Completion.create(
model="text-davinci-003",
prompt=message+question,
temperature=0,
max_tokens=100,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
stop=["\n"]
)

print (response["choices"][0]["text"])

We get the Open API key, and save it as an environment variable. Now, we can run our Python with a question:

Question: Q: Which is the most used hashing method and how many bits does it 
have?
Answer: SHA-256 is the most used hashing method and it has 256 bits.

We see that the AI bot has managed to merge two areas together, for the most widely used hashing method and the size of the hash.

Conclusions

And, so, I am now building a crypto chat bot for my forthcoming module, and trying to load it with enough information to handle student questions. For this I will try to think of every question that students ask, and hopefully it will help in their studies.