Repository navigation
Expand file tree
/
Copy pathexample_random.py
More file actions
62 lines (50 loc) · 1.58 KB
/
Copy pathexample_random.py
File metadata and controls
62 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
"""
libzupt - Random Bytes and Hashing Example
Shows how to generate random bytes and compute hashes
"""
import sys
import os
sys.path.insert(0, os.path.dirname(__file__))
import zupt
def main():
print("=" * 60)
print("libzupt - Random Bytes and Hashing Example")
print("=" * 60)
print()
# Generate random bytes
print("1. Generating random bytes...")
random_bytes = zupt.random_bytes(32)
print(f" Generated {len(random_bytes)} random bytes:")
print(f" {random_bytes.hex()}")
print()
# Generate a nonce
print("2. Generating AES nonce...")
nonce = zupt.random_bytes(zupt.AES_NONCE_SIZE)
print(f" Nonce ({len(nonce)} bytes): {nonce.hex()}")
print()
# Compute SHA-256 hash
print("3. Computing SHA-256 hash...")
data = b"Hello, Post-Quantum World!"
sha256_hash = zupt.sha256(data)
print(f" Data: {data}")
print(f" SHA-256: {sha256_hash.hex()}")
print()
# Compute SHA3-512 hash
print("4. Computing SHA3-512 hash...")
sha3_512_hash = zupt.sha3_512(data)
print(f" Data: {data}")
print(f" SHA3-512: {sha3_512_hash.hex()}")
print()
# Use random bytes for key generation simulation
print("5. Simulating key derivation...")
salt = zupt.random_bytes(16)
print(f" Salt: {salt.hex()}")
derived_key = zupt.sha256(salt + b"my-secret-password")
print(f" Derived key (32 bytes): {derived_key.hex()}")
print()
print("=" * 60)
print("Random bytes and hashing example passed!")
print("=" * 60)
if __name__ == "__main__":
main()