-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashkey_generator.py
More file actions
69 lines (51 loc) · 1.87 KB
/
hashkey_generator.py
File metadata and controls
69 lines (51 loc) · 1.87 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
63
64
65
66
67
68
69
import os
import json
import hashlib
import time
from pathlib import Path
def sanitize_filename(name):
return "".join(c for c in name if c.isalnum() or c in ('-', '_')).rstrip()
def create_hash_object(uid, seed, input_data):
return {
"uid": uid,
"seed": seed,
"input": input_data,
"timestamp": time.time()
}
def compute_hash(obj):
json_bytes = json.dumps(obj, sort_keys=True).encode('utf-8')
return hashlib.sha256(json_bytes).hexdigest()
def save_hash_data(uid, full_obj, hash_key, save_dir):
os.makedirs(save_dir, exist_ok=True)
safe_uid = sanitize_filename(uid)
full_path = Path(save_dir) / f"{safe_uid}.json"
txt_path = Path("known_hash.txt")
full_obj["hash_key"] = hash_key
with open(full_path, "w") as f:
json.dump(full_obj, f, indent=2)
with open(txt_path, "w") as f:
f.write(hash_key + "\n")
print(f"[+] Hash key saved: {full_path}")
print(f"[+] known_hash.txt updated.")
print(f"[✔] Hash key generated and stored.")
def load_input(input_path):
with open(input_path, "r") as f:
return json.load(f)
def main():
print("== AI-Core HashKey Desktop Prototype ==")
uid = input("Enter user/device UID: ").strip()
mode = input("(G)enerate new or (L)oad existing hash key? ").strip().upper()
if mode != "G":
print("[!] Only generation is supported in this prototype.")
return
seed = input("Enter seed phrase or string: ").strip()
input_path = Path("folded_input/folded_input.json")
if not input_path.exists():
print("[!] Error: folded_input/folded_input.json not found.")
return
input_data = load_input(input_path)
obj = create_hash_object(uid, seed, input_data)
hash_key = compute_hash(obj)
save_hash_data(uid, obj, hash_key, Path.home() / ".ai_core/hashkeys")
if __name__ == "__main__":
main()