ajiet-blockchain-lab 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: ajiet-blockchain-lab
3
+ Version: 1.0.0
4
+ Summary: Blockchain Lab Program Launcher
5
+ Requires-Python: >=3.9
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: ajiet-blockchain-lab
3
+ Version: 1.0.0
4
+ Summary: Blockchain Lab Program Launcher
5
+ Requires-Python: >=3.9
@@ -0,0 +1,14 @@
1
+ pyproject.toml
2
+ ajiet_blockchain_lab.egg-info/PKG-INFO
3
+ ajiet_blockchain_lab.egg-info/SOURCES.txt
4
+ ajiet_blockchain_lab.egg-info/dependency_links.txt
5
+ ajiet_blockchain_lab.egg-info/entry_points.txt
6
+ ajiet_blockchain_lab.egg-info/top_level.txt
7
+ blockchain_tool/__init__.py
8
+ blockchain_tool/cli.py
9
+ blockchain_tool/programs/1.py
10
+ blockchain_tool/programs/2.py
11
+ blockchain_tool/programs/3.py
12
+ blockchain_tool/programs/4.py
13
+ blockchain_tool/programs/5.py
14
+ blockchain_tool/programs/6.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ bclab = blockchain_tool.cli:main
File without changes
@@ -0,0 +1,23 @@
1
+
2
+ from pathlib import Path
3
+
4
+ PROGRAMS = Path(__file__).parent / "programs"
5
+
6
+ def main():
7
+ choice = input("Enter question number: ").strip()
8
+
9
+ if not choice.isdigit():
10
+ print("Invalid question number!")
11
+ return
12
+
13
+ selected = PROGRAMS / f"{choice}.py"
14
+
15
+ if selected.is_file():
16
+ print("\n" + "=" * 45)
17
+ print(selected.read_text(encoding="utf-8"))
18
+ print("=" * 45)
19
+ else:
20
+ print("Question not found!")
21
+
22
+ if __name__ == "__main__":
23
+ main()
@@ -0,0 +1,281 @@
1
+ # **Experiment No. 1 – Public and Private Key Generation Using OpenSSL**
2
+
3
+ I'll guide you through the experiment step by step, assuming you are using **Ubuntu Linux Terminal**.
4
+
5
+ You don't need to write any Python or C code. Everything is done using Linux terminal commands.
6
+
7
+ ## **Step 1: Open Ubuntu Terminal**
8
+
9
+ 1. Start your Ubuntu system.
10
+ 2. Press `Ctrl + Alt + T` to open the terminal.
11
+ 3. You will see a terminal window where you can enter commands.
12
+
13
+ [Ubuntu Linux: El Terminal de comandos en Ubuntu](https://images.openai.com/static-rsc-4/bGvs_p2Gn0jI6wV4CQlqrbLXywfLjKUslczUXcktP3BSDVqwDyRk0znXMJlbOGOh-8OLkaOJ0-HPpBnERTDR1Q0hMDXAvbUqZb0WnRuDQd9QD6nRat8vKVGVqYejTqFq-6-8LKnw0YFeekEC0F-XL7F3CAoY0xQJ360yFJMAHLc?purpose=inline)
14
+
15
+ [ubuntinux.blogspot.com](https://ubuntinux.blogspot.com/2017/10/la-terminal-de-ubuntu.html?utm_source=chatgpt.com)
16
+
17
+ ## **Step 2: Update Ubuntu packages**
18
+
19
+ Copy and paste this command into the terminal:
20
+
21
+ ```
22
+ sudo apt-get update
23
+ ```
24
+
25
+ Press **Enter**.
26
+
27
+ - Ubuntu may ask for your password.
28
+ - Enter your Ubuntu login password.
29
+ - You won't see the characters while typing. This is normal.
30
+ - Press Enter again.
31
+
32
+ Wait until the update finishes.
33
+
34
+ Now install OpenSSL:
35
+
36
+ ```
37
+ sudo apt-get install openssl -y
38
+ ```
39
+
40
+ Press Enter and wait for installation.
41
+
42
+ Check installation
43
+
44
+ Type:
45
+
46
+ ```
47
+ openssl version
48
+ ```
49
+
50
+ You should see an output similar to:
51
+
52
+ ```
53
+ OpenSSL 3.x.x
54
+ ```
55
+
56
+ This confirms that OpenSSL is installed.
57
+
58
+ ## **Step 3: Create a workspace**
59
+
60
+ Now create a folder to store your keys.
61
+
62
+ Type:
63
+
64
+ ```
65
+ mkdir blockchain_crypto
66
+ ```
67
+
68
+ Press Enter.
69
+
70
+ Now enter the folder:
71
+
72
+ ```
73
+ cd blockchain_crypto
74
+ ```
75
+
76
+ Press Enter.
77
+
78
+ Your terminal is now inside the `blockchain_crypto` folder.
79
+
80
+ To verify, type:
81
+
82
+ ```
83
+ pwd
84
+ ```
85
+
86
+ You should see a path ending with:
87
+
88
+ ```
89
+ /blockchain_crypto
90
+ ```
91
+
92
+ ## **Step 4: Generate the RSA private key**
93
+
94
+ Now execute:
95
+
96
+ ```
97
+ openssl genpkey -algorithm RSA -out private_key.pem -aes256
98
+ ```
99
+
100
+ Press Enter.
101
+
102
+ [How to Use OpenSSL to Request and Sign SSL/TLS Certificates in Ubuntu 18.04, with a Wrinkle | by Bruno Osiek | Medium](https://images.openai.com/static-rsc-4/hFMjaodZuV9xc_XBBiwZGYhE-vIGpP4019IqSYIkutrqKKXsxoKeVTKUC6tg80dUFuXX_DdBE12O0rxjR5WsI9Y9J31Vi3PPVJm3LopGC2tW8OqlZmARBIckuvbyjgcTXJ3N9JrsWqGnq4GKMj3uXioTkW3LJJ-igFxn3h4R3wU?purpose=inline)
103
+
104
+ [medium.com](https://medium.com/%40brunoosiek/ssl-tls-certificate-authority-ca-with-a-wrinkle-4b43a881edd0?utm_source=chatgpt.com)
105
+
106
+ The terminal will ask:
107
+
108
+ ```
109
+ Enter PEM pass phrase:
110
+ ```
111
+
112
+ 1. Enter a password of your choice.
113
+ 2. Press Enter.
114
+ 3. It will ask you to verify the password.
115
+ 4. Enter the same password again.
116
+ 5. Press Enter.
117
+
118
+ **Important:** The password will not be visible while typing. Remember this password because you will need it in the next steps.
119
+
120
+ Your encrypted RSA private key is now generated.
121
+
122
+ ## **Step 5: Inspect the private key**
123
+
124
+ Execute:
125
+
126
+ ```
127
+ openssl rsa -in private_key.pem -text -noout
128
+ ```
129
+
130
+ Press Enter.
131
+
132
+ It will ask for the passphrase.
133
+
134
+ Enter the password you created in Step 4.
135
+
136
+ You will see mathematical details such as:
137
+
138
+ - Private key
139
+ - Modulus
140
+ - Public exponent
141
+ - Private exponent
142
+ - Prime numbers
143
+
144
+ This confirms that your RSA private key was generated successfully.
145
+
146
+ ## **Step 6: Extract the public key**
147
+
148
+ Now we need to generate the public key from the private key.
149
+
150
+ Copy and execute:
151
+
152
+ ```
153
+ openssl rsa -pubout -in private_key.pem -out public_key.pem
154
+ ```
155
+
156
+ Press Enter.
157
+
158
+ Enter your private key passphrase when requested.
159
+
160
+ If successful, you should see:
161
+
162
+ ```
163
+ writing RSA key
164
+ ```
165
+
166
+ Your public key is now saved as `public_key.pem`.
167
+
168
+ ## **Step 7: Verify the generated files**
169
+
170
+ Now check whether both files have been created.
171
+
172
+ Execute:
173
+
174
+ ```
175
+ ls
176
+ ```
177
+
178
+ Expected output:
179
+
180
+ ```
181
+ private_key.pem
182
+ public_key.pem
183
+ ```
184
+
185
+ Now display the private key file:
186
+
187
+ ```
188
+ cat private_key.pem
189
+ ```
190
+
191
+ You should see something similar to:
192
+
193
+ ```
194
+ -----BEGIN ENCRYPTED PRIVATE KEY-----
195
+ [Encrypted key data]
196
+ -----END ENCRYPTED PRIVATE KEY-----
197
+ ```
198
+
199
+ Next, display the public key:
200
+
201
+ ```
202
+ cat public_key.pem
203
+ ```
204
+
205
+ Expected format:
206
+
207
+ ```
208
+ -----BEGIN PUBLIC KEY-----
209
+ [Public key data]
210
+ -----END PUBLIC KEY-----
211
+ ```
212
+
213
+ The actual key data will be different on your computer. That is normal.
214
+
215
+ [How to use a RSA public key to encrypt headers on a Citrix ADC. - The world of Netscaler](https://images.openai.com/static-rsc-4/sfB0x5UEe4nMjKJt5DpEskfQyI-z199IR-dGJ82k-agQ4IRq9cx34Fk6FeFD1oUIl7JOrKL4OLvDgVWfol8BghF2rkyuy-VOduNOXbL_6nMFj08g3ihWfZOZwgk3M86-AQzwkcV1UsMTMCgS_gmy6u-aniq1Jj3sjCgK9YGPt8E?purpose=inline)
216
+
217
+ [netscaler.dk](https://netscaler.dk/how-to-use-a-rsa-public-key-to-encrypt-headers-on-a-citrix-adc/?utm_source=chatgpt.com)
218
+
219
+ **Important:** Your private key is confidential. Do not upload or share the actual private key screenshot publicly. For your lab record, follow your college's submission instructions.
220
+
221
+ ## **Step 8: Take the terminal screenshot**
222
+
223
+ Your assignment requires a screenshot showing the executed commands and generated key blocks.
224
+
225
+ Follow these steps:
226
+
227
+ 1. Keep your Ubuntu terminal open inside the `blockchain_crypto` folder.
228
+ 2. Make sure the `cat private_key.pem` and `cat public_key.pem` outputs are visible.
229
+ 3. Adjust the terminal size if necessary.
230
+ 4. Press `PrtSc` or use Ubuntu's screenshot tool.
231
+ 5. Save the screenshot.
232
+ 6. Paste it on the **left unruled page opposite the Result section**, as instructed in your record.
233
+
234
+ ## **Step 9: Final verification**
235
+
236
+ Execute these commands to confirm that both files exist:
237
+
238
+ ```
239
+ ls -l private_key.pem public_key.pem
240
+ ```
241
+
242
+ You should see both filenames with their file details.
243
+
244
+ You have now completed the experiment.
245
+
246
+ ## **Step 10: Result for your record**
247
+
248
+ You can write this in your practical record:
249
+
250
+ **Result:**
251
+
252
+ The RSA public and private key pair was successfully generated using OpenSSL. The private key was encrypted using AES-256, and the corresponding public key was extracted and saved in PEM format. The generated keys can be used for secure communication and digital signature verification in blockchain applications.
253
+
254
+ ## **Important commands – Quick reference**
255
+
256
+ | Purpose | Command |
257
+ | -------------------- | ------------------------------------------------------------- |
258
+ | Update packages | `sudo apt-get update` |
259
+ | Install OpenSSL | `sudo apt-get install openssl -y` |
260
+ | Check version | `openssl version` |
261
+ | Create folder | `mkdir blockchain_crypto` |
262
+ | Enter folder | `cd blockchain_crypto` |
263
+ | Generate private key | `openssl genpkey -algorithm RSA -out private_key.pem -aes256` |
264
+ | Inspect private key | `openssl rsa -in private_key.pem -text -noout` |
265
+ | Extract public key | `openssl rsa -pubout -in private_key.pem -out public_key.pem` |
266
+ | Display private key | `cat private_key.pem` |
267
+ | Display public key | `cat public_key.pem` |
268
+
269
+ **One small technical note:** Your experiment specifies 2048-bit RSA. To explicitly set that size when generating the key, you can use:
270
+
271
+ ```
272
+ openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out private_key.pem -aes256
273
+ ```
274
+
275
+ If you have already generated the key, check its size using the inspection command in Step 5.
276
+
277
+ Experiment 1 complete
278
+
279
+ I can also help you prepare simple viva questions and answers for this experiment.
280
+
281
+ 📚Revise OpenSSL experimentTap to set up
@@ -0,0 +1,104 @@
1
+ Experiment 2: Create a Simple Blockchain using Python
2
+
3
+ [Note: Please explain the commands briefly while writing the record]
4
+
5
+ Aim
6
+ To design and implement a simple blockchain using Python that demonstrates the fundamental concepts of blocks, cryptographic hashing, and chain linkage.
7
+
8
+ Theory
9
+ A blockchain is a distributed ledger consisting of a sequence of blocks linked together with cryptographic hashes.
10
+ Block Structure:
11
+ Each block contains:
12
+ index: Block position number.
13
+ timestamp: Exact time of block creation.
14
+ data: Transaction or message payload.
15
+ prev_hash: Cryptographic hash of the preceding block.
16
+ hash: Unique SHA-256 digital signature of the current block.
17
+ Hashing: A block’s hash is generated using SHA-256 to ensure immutability. Any modification to the data in a block invalidates all subsequent blocks.
18
+ Genesis Block: The very first block in the chain, initialized manually without a preceding block reference.
19
+
20
+ Software & Hardware Requirements
21
+ Operating System: Ubuntu / Linux
22
+ Software: Python 3.x, Nano (or any text editor)
23
+ Libraries: hashlib, json, time (Built-in standard libraries)
24
+
25
+ Procedure
26
+ 1. Set up Python Environment
27
+ Install Python and verify the installation:
28
+
29
+ Bash
30
+ sudo apt update
31
+ sudo apt install python3.12 python3.12-venv python3.12-dev -y
32
+ python3.12 --version
33
+
34
+
35
+ 2. Create Script File
36
+ Open a new Python file in your preferred text editor:
37
+
38
+ Bash
39
+ nano blockchain.py
40
+
41
+
42
+ 3. Write the Blockchain Code
43
+ Paste the following corrected Python code into blockchain.py:
44
+
45
+ Python
46
+ import hashlib
47
+ import json
48
+ import time
49
+
50
+ # Block Class
51
+ class Block:
52
+ def __init__(self, index, prev_hash, data, timestamp):
53
+ self.index = index
54
+ self.prev_hash = prev_hash
55
+ self.data = data
56
+ self.timestamp = timestamp
57
+ self.hash = self.hash_block()
58
+
59
+ def hash_block(self):
60
+ # Create a dictionary of fields excluding 'hash' itself
61
+ block_data = {
62
+ "index": self.index,
63
+ "prev_hash": self.prev_hash,
64
+ "data": self.data,
65
+ "timestamp": self.timestamp
66
+ }
67
+ block_string = json.dumps(block_data, sort_keys=True)
68
+ return hashlib.sha256(block_string.encode()).hexdigest()
69
+
70
+ # Genesis Block Generator
71
+ def create_genesis_block():
72
+ return Block(0, "0", "Genesis Block", time.time())
73
+
74
+ # Function to generate the next block in the chain
75
+ def next_block(last_block, data):
76
+ index = last_block.index + 1
77
+ timestamp = time.time()
78
+ prev_hash = last_block.hash
79
+ return Block(index, prev_hash, data, timestamp)
80
+
81
+ # Main Execution
82
+ if __name__ == "__main__":
83
+ # Initialize Blockchain with Genesis Block
84
+ blockchain = [create_genesis_block()]
85
+ previous_block = blockchain[0]
86
+
87
+ print(f"Genesis Block Hash: {previous_block.hash}\n")
88
+
89
+ # Add 5 additional blocks
90
+ for i in range(1, 6):
91
+ block_data = f"Block {i} Data"
92
+ new_block = next_block(previous_block, block_data)
93
+ blockchain.append(new_block)
94
+ previous_block = new_block
95
+
96
+ print(f"Block #{new_block.index} Hash: {new_block.hash}")
97
+ print(f" └─ Previous Hash: {new_block.prev_hash}\n")
98
+
99
+
100
+ 4. Save and Run
101
+ In Nano, press Ctrl+O, press Enter to save, then press Ctrl+X to exit.
102
+ Execute the script:
103
+ Bash
104
+ python3.12 blockchain.py