juneja-codebase 4.0.0__tar.gz → 4.1.1__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.
Files changed (84) hide show
  1. juneja_codebase-4.1.1/MANIFEST.in +1 -0
  2. juneja_codebase-4.1.1/PKG-INFO +60 -0
  3. juneja_codebase-4.1.1/README.md +42 -0
  4. juneja_codebase-4.1.1/juneja_codebase/__init__.py +6 -0
  5. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/main.py +41 -14
  6. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/.vscode/tasks.json +28 -0
  7. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise1_Blockchain +0 -0
  8. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise1_Blockchain.cpp +82 -0
  9. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise2_Blockchain +0 -0
  10. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise2_Blockchain.cpp +69 -0
  11. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise3-1_Blockchain +0 -0
  12. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise3-1_Blockchain.cpp +31 -0
  13. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise3-2_Blockchain +0 -0
  14. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise3-2_Blockchain.cpp +23 -0
  15. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise3-3_Blockchain +0 -0
  16. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise3-3_Blockchain.cpp +32 -0
  17. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise4_Blockchain +0 -0
  18. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise4_Blockchain.cpp +25 -0
  19. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise5_Blockchain +0 -0
  20. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise5_Blockchain.cpp +62 -0
  21. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise6_Blockchain +0 -0
  22. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise6_Blockchain.cpp +91 -0
  23. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise7_Blockchain +0 -0
  24. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise7_Blockchain.cpp +139 -0
  25. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise8-1_Blockchain.sol +15 -0
  26. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise8-2_Blockchain.sol +19 -0
  27. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/AnshJuneja_LabExercise8-3_Blockchain.sol +21 -0
  28. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q10_hyperledger_chaincode.js +273 -0
  29. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q1_sha256_digest.py +16 -0
  30. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q2_sha256_encrypt_decrypt.py +40 -0
  31. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q3_rsa.py +103 -0
  32. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q4_pow_blockchain.py +69 -0
  33. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q5_digital_signature.py +104 -0
  34. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q6_blockchain_transactions.py +78 -0
  35. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q7_five_nodes_hash.py +55 -0
  36. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q8_five_nodes_validity.py +94 -0
  37. juneja_codebase-4.1.1/juneja_codebase/templates/Blockchain Codes/pythonic version/q9_SimpleBank.sol +144 -0
  38. juneja_codebase-4.1.1/juneja_codebase.egg-info/PKG-INFO +60 -0
  39. juneja_codebase-4.1.1/juneja_codebase.egg-info/SOURCES.txt +77 -0
  40. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/setup.cfg +1 -1
  41. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/setup.py +1 -1
  42. juneja_codebase-4.0.0/MANIFEST.in +0 -0
  43. juneja_codebase-4.0.0/PKG-INFO +0 -76
  44. juneja_codebase-4.0.0/README.md +0 -58
  45. juneja_codebase-4.0.0/juneja_codebase/__init__.py +0 -6
  46. juneja_codebase-4.0.0/juneja_codebase.egg-info/PKG-INFO +0 -76
  47. juneja_codebase-4.0.0/juneja_codebase.egg-info/SOURCES.txt +0 -45
  48. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/LICENSE +0 -0
  49. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical10_CD.l +0 -0
  50. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical10_CD.y +0 -0
  51. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical11_CD.l +0 -0
  52. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical11_CD.y +0 -0
  53. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical12_CD.l +0 -0
  54. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical12_CD.y +0 -0
  55. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical13_CD.l +0 -0
  56. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical13_CD.y +0 -0
  57. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical1_CD.l +0 -0
  58. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical2_CD.l +0 -0
  59. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical3_CD.l +0 -0
  60. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical4_CD.l +0 -0
  61. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical5_CD.l +0 -0
  62. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical6_CD.l +0 -0
  63. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical7_CD.l +0 -0
  64. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical8_CD.l +0 -0
  65. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical9_CD.l +0 -0
  66. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/compiler_design/AnshJuneja_Practical9_CD.y +0 -0
  67. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/deep_learning/Denoised_Autoencoders.ipynb +0 -0
  68. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/deep_learning/Fashion_Mnist_DenseNet201_VGG19_PreTModel.ipynb +0 -0
  69. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/deep_learning/Image_Compression_Autoencoders.ipynb +0 -0
  70. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/deep_learning/boston_housing.ipynb +0 -0
  71. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/deep_learning/cnn_fashionmnist.ipynb +0 -0
  72. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/deep_learning/posneg_imdb_ffnn..ipynb +0 -0
  73. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/deep_learning/reuters.ipynb +0 -0
  74. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/deep_learning/rnnlstm_timeseries_imdb.ipynb +0 -0
  75. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/social_network_analysis/1_try.ipynb +0 -0
  76. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/social_network_analysis/2_try.ipynb +0 -0
  77. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/social_network_analysis/3_try.ipynb +0 -0
  78. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/social_network_analysis/4_try.ipynb +0 -0
  79. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/social_network_analysis/5_try.ipynb +0 -0
  80. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/social_network_analysis/6_try.ipynb +0 -0
  81. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase/templates/social_network_analysis/new.ipynb +0 -0
  82. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase.egg-info/dependency_links.txt +0 -0
  83. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase.egg-info/entry_points.txt +0 -0
  84. {juneja_codebase-4.0.0 → juneja_codebase-4.1.1}/juneja_codebase.egg-info/top_level.txt +0 -0
@@ -0,0 +1 @@
1
+ recursive-include juneja_codebase/templates *
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.1
2
+ Name: juneja_codebase
3
+ Version: 4.1.1
4
+ Summary: CLI tool to generate academic practical code files for Compiler Design, Data Structures, OS, and DBMS
5
+ Home-page: UNKNOWN
6
+ Author: AJ
7
+ License: UNKNOWN
8
+ Platform: UNKNOWN
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Intended Audience :: Education
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # juneja-codebase
18
+
19
+ Offline CLI for generating practical code files for multiple subjects.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pip install juneja-codebase==4.1.0
25
+ ```
26
+
27
+ ## Use
28
+
29
+ ```bash
30
+ juneja-codebase --list
31
+ juneja-codebase --all
32
+ juneja-codebase --subject compiler_design
33
+ juneja-codebase --subject blockchain
34
+ juneja-codebase --all --zip
35
+ juneja-codebase --all --output ./my_codes
36
+ ```
37
+
38
+ If the console script is not on PATH, use:
39
+
40
+ ```bash
41
+ python3 -m juneja_codebase.main --list
42
+ python3 -m juneja_codebase.main --all
43
+ python3 -m juneja_codebase.main --subject blockchain
44
+ ```
45
+
46
+ ## Subjects
47
+
48
+ - Compiler Design
49
+ - Blockchain Codes
50
+ - Deep Learning
51
+ - Social Network Analysis
52
+
53
+ ## Notes
54
+
55
+ - `--subject blockchain` resolves to the `Blockchain Codes` templates folder.
56
+ - The package works offline because templates ship inside the wheel and sdist.
57
+
58
+
59
+
60
+
@@ -0,0 +1,42 @@
1
+ # juneja-codebase
2
+
3
+ Offline CLI for generating practical code files for multiple subjects.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install juneja-codebase==4.1.0
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```bash
14
+ juneja-codebase --list
15
+ juneja-codebase --all
16
+ juneja-codebase --subject compiler_design
17
+ juneja-codebase --subject blockchain
18
+ juneja-codebase --all --zip
19
+ juneja-codebase --all --output ./my_codes
20
+ ```
21
+
22
+ If the console script is not on PATH, use:
23
+
24
+ ```bash
25
+ python3 -m juneja_codebase.main --list
26
+ python3 -m juneja_codebase.main --all
27
+ python3 -m juneja_codebase.main --subject blockchain
28
+ ```
29
+
30
+ ## Subjects
31
+
32
+ - Compiler Design
33
+ - Blockchain Codes
34
+ - Deep Learning
35
+ - Social Network Analysis
36
+
37
+ ## Notes
38
+
39
+ - `--subject blockchain` resolves to the `Blockchain Codes` templates folder.
40
+ - The package works offline because templates ship inside the wheel and sdist.
41
+
42
+
@@ -0,0 +1,6 @@
1
+ """
2
+ juneja-codebase: A CLI tool to generate academic practical code files
3
+ """
4
+
5
+ __version__ = "4.1.1"
6
+ __author__ = "AJ"
@@ -15,24 +15,49 @@ def get_templates_dir():
15
15
  return Path(__file__).parent / "templates"
16
16
 
17
17
 
18
+ def normalize_subject_name(name):
19
+ """Normalize a subject name for flexible matching."""
20
+ return "".join(ch.lower() for ch in name if ch.isalnum())
21
+
22
+
23
+ def resolve_subject_dir(subject):
24
+ """Resolve a user-supplied subject name to a template directory."""
25
+ templates_dir = get_templates_dir()
26
+ subject_lookup = normalize_subject_name(subject)
27
+
28
+ for candidate in templates_dir.iterdir():
29
+ if not candidate.is_dir():
30
+ continue
31
+
32
+ candidate_lookup = normalize_subject_name(candidate.name)
33
+ if (
34
+ candidate.name.lower() == subject.lower()
35
+ or candidate_lookup == subject_lookup
36
+ or candidate_lookup.startswith(subject_lookup)
37
+ or subject_lookup.startswith(candidate_lookup)
38
+ ):
39
+ return candidate
40
+
41
+ return None
42
+
43
+
18
44
  def list_subjects():
19
45
  """List all available subjects"""
20
46
  templates_dir = get_templates_dir()
21
- subjects = [d.name for d in templates_dir.iterdir() if d.is_dir()]
47
+ subjects = sorted(d.name for d in templates_dir.iterdir() if d.is_dir())
22
48
  return subjects
23
49
 
24
50
 
25
51
  def copy_subject_files(subject, output_dir):
26
52
  """Copy files for a specific subject to the output directory"""
27
- templates_dir = get_templates_dir()
28
- subject_dir = templates_dir / subject
53
+ subject_dir = resolve_subject_dir(subject)
29
54
 
30
- if not subject_dir.exists():
55
+ if subject_dir is None:
31
56
  print(f"Error: Subject '{subject}' not found!")
32
57
  print(f"Available subjects: {', '.join(list_subjects())}")
33
58
  return False
34
59
 
35
- output_path = Path(output_dir) / subject
60
+ output_path = Path(output_dir) / subject_dir.name
36
61
  output_path.mkdir(parents=True, exist_ok=True)
37
62
 
38
63
  # Copy all files from subject directory
@@ -66,17 +91,17 @@ def create_zip_archive(subject, output_file):
66
91
 
67
92
  if subject:
68
93
  # Zip specific subject
69
- subject_dir = templates_dir / subject
70
- if not subject_dir.exists():
94
+ subject_dir = resolve_subject_dir(subject)
95
+ if subject_dir is None:
71
96
  print(f"Error: Subject '{subject}' not found!")
72
97
  return False
73
98
 
74
- zip_name = output_file if output_file else f"{subject}.zip"
99
+ zip_name = output_file if output_file else f"{subject_dir.name.replace(' ', '_')}.zip"
75
100
 
76
101
  with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
77
102
  for item in subject_dir.rglob('*'):
78
103
  if item.is_file():
79
- arcname = subject / item.relative_to(subject_dir)
104
+ arcname = Path(subject_dir.name) / item.relative_to(subject_dir)
80
105
  zipf.write(item, arcname)
81
106
  print(f"Added to zip: {arcname}")
82
107
 
@@ -150,7 +175,7 @@ Examples:
150
175
  parser.add_argument(
151
176
  '--version', '-v',
152
177
  action='version',
153
- version='%(prog)s 4.0.0'
178
+ version='%(prog)s 4.1.1'
154
179
  )
155
180
 
156
181
  args = parser.parse_args()
@@ -177,12 +202,14 @@ Examples:
177
202
  # Generate files
178
203
  if args.all:
179
204
  print("Generating all subject files...")
180
- copy_all_subjects(args.output)
181
- print(f"\n✓ All files generated in: {os.path.abspath(args.output)}")
205
+ if copy_all_subjects(args.output):
206
+ print(f"\n✓ All files generated in: {os.path.abspath(args.output)}")
207
+ else:
208
+ print("\nSome subjects could not be generated.")
182
209
  elif args.subject:
183
210
  print(f"Generating {args.subject} files...")
184
- copy_subject_files(args.subject, args.output)
185
- print(f"\n✓ Files generated in: {os.path.abspath(args.output)}")
211
+ if copy_subject_files(args.subject, args.output):
212
+ print(f"\n✓ Files generated in: {os.path.abspath(args.output)}")
186
213
  else:
187
214
  # No action specified, show help
188
215
  parser.print_help()
@@ -0,0 +1,28 @@
1
+ {
2
+ "tasks": [
3
+ {
4
+ "type": "cppbuild",
5
+ "label": "C/C++: gcc build active file",
6
+ "command": "/usr/bin/gcc",
7
+ "args": [
8
+ "-fdiagnostics-color=always",
9
+ "-g",
10
+ "${file}",
11
+ "-o",
12
+ "${fileDirname}/${fileBasenameNoExtension}"
13
+ ],
14
+ "options": {
15
+ "cwd": "${fileDirname}"
16
+ },
17
+ "problemMatcher": [
18
+ "$gcc"
19
+ ],
20
+ "group": {
21
+ "kind": "build",
22
+ "isDefault": true
23
+ },
24
+ "detail": "Task generated by Debugger."
25
+ }
26
+ ],
27
+ "version": "2.0.0"
28
+ }
@@ -0,0 +1,82 @@
1
+ #include <iostream>
2
+ #include <vector>
3
+ #include <string>
4
+ #include <iomanip>
5
+ #include <openssl/evp.h>
6
+ #include <openssl/rsa.h>
7
+ #include <openssl/pem.h>
8
+ #include <openssl/err.h>
9
+
10
+ void printHex(const unsigned char* data, size_t len) {
11
+ for (size_t i = 0; i < len; ++i) {
12
+ std::printf("%02x", data[i]);
13
+ if ((i + 1) % 32 == 0) std::printf("\n");
14
+ }
15
+ std::printf("\n");
16
+ }
17
+
18
+ int main() {
19
+ std::string document = "This is a confidential document for verification.";
20
+ unsigned char* signature = nullptr;
21
+ size_t sig_len = 0;
22
+
23
+ // Generating RSA Key Pair
24
+ EVP_PKEY *pkey = EVP_RSA_gen(2048);
25
+ if (!pkey) { std::cerr << "Keygen failed\n"; return 1; }
26
+
27
+ // Printing the Private Key (The Secret Part)
28
+ std::cout << "\nSENDER'S PRIVATE KEY (Used for Signing):\n\n";
29
+ BIO* pri_bio = BIO_new(BIO_s_mem());
30
+ PEM_write_bio_PrivateKey(pri_bio, pkey, NULL, NULL, 0, NULL, NULL);
31
+ char* pri_buf;
32
+ size_t pri_len = BIO_get_mem_data(pri_bio, &pri_buf);
33
+ std::cout.write(pri_buf, pri_len) << "\n";
34
+
35
+ // Printing the Public Key (The Shared Part)
36
+ std::cout << "\nSENDER'S PUBLIC KEY (Shared with Receiver):\n\n";
37
+ BIO* pub_bio = BIO_new(BIO_s_mem());
38
+ PEM_write_bio_PUBKEY(pub_bio, pkey);
39
+ char* pub_buf;
40
+ size_t pub_len = BIO_get_mem_data(pub_bio, &pub_buf);
41
+ std::cout.write(pub_buf, pub_len) << "\n";
42
+
43
+ // Creating the Signature (Signing Process)
44
+ std::cout << "SIGNING THE DOCUMENT...\n";
45
+ std::cout << "Document Content: \"" << document << "\"\n\n";
46
+
47
+ EVP_MD_CTX *m_ctx = EVP_MD_CTX_new();
48
+ EVP_DigestSignInit(m_ctx, NULL, EVP_sha256(), NULL, pkey);
49
+ EVP_DigestSignUpdate(m_ctx, document.c_str(), document.length());
50
+
51
+ // Getting signature length first
52
+ EVP_DigestSignFinal(m_ctx, NULL, &sig_len);
53
+ signature = (unsigned char*)OPENSSL_malloc(sig_len);
54
+ EVP_DigestSignFinal(m_ctx, signature, &sig_len);
55
+
56
+ std::cout << "\nGENERATED SIGNATURE (HEXADECIMAL):\n\n";
57
+ printHex(signature, sig_len);
58
+
59
+ // Verification Process
60
+ std::cout << "\nVERIFYING SIGNATURE WITH PUBLIC KEY...\n\n";
61
+ EVP_MD_CTX *v_ctx = EVP_MD_CTX_new();
62
+ EVP_DigestVerifyInit(v_ctx, NULL, EVP_sha256(), NULL, pkey);
63
+ EVP_DigestVerifyUpdate(v_ctx, document.c_str(), document.length());
64
+
65
+ int is_valid = EVP_DigestVerifyFinal(v_ctx, signature, sig_len);
66
+
67
+ if (is_valid == 1) {
68
+ std::cout << "RESULT: SUCCESS! The signature is VALID.\n";
69
+ } else {
70
+ std::cout << "RESULT: FAILED! The signature is INVALID.\n";
71
+ }
72
+
73
+ // Cleanup
74
+ OPENSSL_free(signature);
75
+ BIO_free(pri_bio);
76
+ BIO_free(pub_bio);
77
+ EVP_MD_CTX_free(m_ctx);
78
+ EVP_MD_CTX_free(v_ctx);
79
+ EVP_PKEY_free(pkey);
80
+
81
+ return 0;
82
+ }
@@ -0,0 +1,69 @@
1
+ #include <iostream>
2
+ #include <vector>
3
+ #include <ctime>
4
+ #include <string>
5
+ using namespace std;
6
+
7
+ class Block {
8
+ public:
9
+ int index;
10
+ string transactions;
11
+ string prevHash;
12
+ string currentHash;
13
+ time_t timeCreated;
14
+
15
+ Block(int idx, string tx, string lastHash) {
16
+ index = idx;
17
+ transactions = tx;
18
+ prevHash = lastHash;
19
+ timeCreated = time(0);
20
+ currentHash = generateHash();
21
+ }
22
+
23
+ string generateHash() {
24
+ // We combine all data into one string to "sign" it
25
+ string toHash = to_string(index) + transactions + prevHash + to_string(timeCreated);
26
+
27
+ hash<string> hasher;
28
+ return to_string(hasher(toHash));
29
+ }
30
+ };
31
+
32
+ // Manages the list of blocks
33
+ class Blockchain {
34
+ public:
35
+ vector<Block> ledger;
36
+
37
+ Blockchain() {
38
+ // Create the first "Genesis" block manually
39
+ ledger.push_back(Block(0, "Initial Block", "0"));
40
+ }
41
+
42
+ void addTransaction(string data) {
43
+ // Get the hash of the very last block in our ledger
44
+ string lastBlockHash = ledger.back().currentHash;
45
+
46
+ // Create a new block linked to the last one
47
+ ledger.push_back(Block(ledger.size(), data, lastBlockHash));
48
+ }
49
+
50
+ void displayChain() {
51
+ for (const auto& b : ledger) {
52
+ cout << "--- Block #" << b.index << " ---" << endl;
53
+ cout << "Time: " << b.timeCreated << endl;
54
+ cout << "Data: " << b.transactions << endl;
55
+ cout << "Prev: " << b.prevHash << endl;
56
+ cout << "Hash: " << b.currentHash << endl << endl;
57
+ }
58
+ }
59
+ };
60
+
61
+ int main() {
62
+ Blockchain bitCoin;
63
+
64
+ bitCoin.addTransaction("I have 40 bit coin");
65
+ bitCoin.addTransaction("Aman have 30 bicoin");
66
+
67
+ bitCoin.displayChain();
68
+ return 0;
69
+ }
@@ -0,0 +1,31 @@
1
+ #include <iostream>
2
+ #include <openssl/sha.h>
3
+ #include <iomanip>
4
+ #include <string>
5
+ #include <sstream>
6
+ using namespace std;
7
+
8
+ string getSHA256(string input) {
9
+ unsigned char hash[SHA256_DIGEST_LENGTH];
10
+
11
+ SHA256(reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), hash);
12
+
13
+ stringstream ss;
14
+ for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
15
+ ss << hex << setw(2) << setfill('0') << (int)hash[i];
16
+ }
17
+ return ss.str();
18
+ }
19
+ int main() {
20
+ string userInput;
21
+ cout << " SHA-256 HASH GENERATOR " << endl;
22
+
23
+ cout << "Enter text to hash: ";
24
+ getline(cin, userInput); // Allows spaces in input
25
+
26
+ string result = getSHA256(userInput);
27
+
28
+ cout << "\nInput String : " << userInput << endl;
29
+ cout << "Message Digest: " << result << endl;
30
+ return 0;
31
+ }
@@ -0,0 +1,23 @@
1
+ #include <iostream>
2
+ #include <openssl/sha.h>
3
+ #include <iomanip>
4
+ using namespace std;
5
+
6
+ int main() {
7
+ string msg = "Blockchain Developer";
8
+ unsigned char hash[SHA256_DIGEST_LENGTH];
9
+
10
+ SHA256(reinterpret_cast<const unsigned char*>(msg.c_str()), msg.size(), hash);
11
+
12
+ cout << "Message : " << msg << endl;
13
+ cout << "SHA256 Hash : ";
14
+
15
+ for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
16
+ cout << hex << setw(2) << setfill('0') << (int)hash[i];
17
+
18
+ cout << endl;
19
+ cout << "Decryption : Not possible (SHA256 is one-way)" << endl;
20
+
21
+ return 0;
22
+ }
23
+
@@ -0,0 +1,32 @@
1
+ #include <iostream>
2
+ #include <openssl/sha.h>
3
+ #include <iomanip>
4
+ #include <string>
5
+ #include <sstream>
6
+
7
+ using namespace std;
8
+
9
+ string getSHA256(string input) {
10
+ unsigned char hash[SHA256_DIGEST_LENGTH];
11
+ SHA256(reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), hash);
12
+
13
+ stringstream ss;
14
+ for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
15
+ ss << hex << setw(2) << setfill('0') << (int)hash[i];
16
+ }
17
+
18
+ return ss.str();
19
+ }
20
+
21
+ int main() {
22
+ string str1 = "Hello World";
23
+ string str2 = "Hello world";
24
+
25
+ cout << "String 1: " << str1 << endl;
26
+ cout << "Hash 1 : " << getSHA256(str1) << endl;
27
+
28
+ cout << "\nString 2: " << str2 << endl;
29
+ cout << "Hash 2 : " << getSHA256(str2) << endl;
30
+
31
+ return 0;
32
+ }
@@ -0,0 +1,25 @@
1
+ #include <iostream>
2
+ #include <openssl/sha.h>
3
+ #include <iomanip>
4
+ #include <string>
5
+ #include <sstream>
6
+
7
+ using namespace std;
8
+
9
+ int main() {
10
+ string input = "Hello World";
11
+ unsigned char hash[SHA256_DIGEST_LENGTH];
12
+
13
+ // Generating the hash
14
+ SHA256(reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), hash);
15
+
16
+ stringstream ss;
17
+ for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
18
+ ss << hex << setw(2) << setfill('0') << (int)hash[i];
19
+ }
20
+
21
+ cout << "Input : " << input << endl;
22
+ cout << "SHA-256: " << ss.str() << endl;
23
+
24
+ return 0;
25
+ }
@@ -0,0 +1,62 @@
1
+ #include <iostream>
2
+ #include <cmath>
3
+ #include <iomanip>
4
+ using namespace std;
5
+
6
+ long long power(long long base, long long exp, long long mod) {
7
+ long long res = 1;
8
+ base = base % mod;
9
+ while (exp > 0) {
10
+ if (exp % 2 == 1) res = (res * base) % mod;
11
+ base = (base * base) % mod;
12
+ exp = exp / 2;
13
+ }
14
+ return res;
15
+ }
16
+
17
+ int findPrivate_d(int e, int phi) {
18
+ for (int d = 1; d < phi; d++) {
19
+ if ((e * d) % phi == 1)
20
+ return d;
21
+ }
22
+ return 0;
23
+ }
24
+ int main() {
25
+ int p = 17;
26
+ int q = 11;
27
+ int n = p * q;
28
+ int phi = (p - 1) * (q - 1); // Euler's Totient Function
29
+
30
+ // Given Public Exponent (e)
31
+ int e = 11;
32
+
33
+ // Find Private Key (d)
34
+ int d = findPrivate_d(e, phi);
35
+
36
+ // Original Message (Transaction Data)
37
+ int M = 123;
38
+
39
+ // --- RSA Encryption ---
40
+ long long C = power(M, e, n); // Formula: C = (M^e) % n
41
+
42
+ // --- RSA Decryption ---
43
+ long long decrypted_M = power(C, d, n); // Formula: Decrypted_M = (C^d) % n
44
+
45
+ cout << "--- RSA Implementation ---" << endl;
46
+ cout << "p: " << p << " | q: " << q << endl;
47
+ cout << "Public Modulus (n) : " << n << endl;
48
+ cout << "Euler's Totient (phi) : " << phi << endl;
49
+ cout << "Public Key (e) : " << e << endl;
50
+ cout << "Private Key (d) : " << d << endl;
51
+ cout << "----------------" << endl;
52
+ cout << "Original Message (M) : " << M << endl;
53
+ cout << "Encrypted Ciphertext (C) : " << C << endl;
54
+ cout << "Decrypted Message : " << decrypted_M << endl;
55
+
56
+ if (M == decrypted_M) {
57
+ cout << "\nVerification complete! Original message recovered." << endl;
58
+ } else {
59
+ cout << "\nDecryption failed." << endl;
60
+ }
61
+ return 0;
62
+ }