Spaces:
Sleeping
Sleeping
Igor
Feat: Add Visual Fingerprint (TOFU) to verify session integrity against MITM
77c38a4 unverified Download fingerprint.py from igor53627/shitposter-api: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/igor53627/shitposter-api/resolve/main/fingerprint.py
- Command line
-
hf download hf://spaces/igor53627/shitposter-api/fingerprint.py
-
curl -L -o fingerprint.py https://huggingface.co/spaces/igor53627/shitposter-api/resolve/main/fingerprint.py
1.13 kB
| import hashlib | |
| # 64 High-Compatibility Emojis | |
| EMOJI_MAP = [ | |
| "๐ถ", "๐ฑ", "๐ญ", "๐น", "๐ฐ", "๐ฆ", "๐ป", "๐ผ", "๐จ", "๐ฏ", "๐ฆ", "๐ฎ", "๐ท", "๐ฝ", "๐ธ", "๐ต", | |
| "๐", "๐ง", "๐ฆ", "๐ค", "๐ฃ", "๐ฅ", "๐ฆ", "๐ฆ ", "๐ฆ", "๐ฆ", "๐บ", "๐", "๐ด", "๐ฆ", "๐", "๐", | |
| "๐ฆ", "๐", "๐", "๐", "๐ฆ", "๐ท", "๐ธ", "๐ฆ", "๐ข", "๐", "๐ฆ", "๐ฆ", "๐ฆ", "๐", "๐ฆ", "๐ฆ", | |
| "๐ฆ", "๐ฆ", "๐ก", "๐ ", "๐", "๐ฌ", "๐ณ", "๐", "๐ฆ", "๐", "๐ ", "๐", "๐ฆ", "๐ฆ", "๐ฆง", "๐" | |
| ] | |
| def get_fingerprint(session_keys: dict) -> str: | |
| """ | |
| Generates a visual fingerprint (4 Emojis) from the session keys. | |
| Inputs: {'tx': bytes, 'rx': bytes} | |
| """ | |
| # Combine keys to hash | |
| combined = session_keys['tx'] + session_keys['rx'] | |
| # Hash to get random distribution | |
| h = hashlib.sha256(combined).digest() | |
| # Take first 4 bytes | |
| indices = [h[0], h[1], h[2], h[3]] | |
| # Map to Emojis (modulo 64) | |
| fingerprint = [EMOJI_MAP[i % 64] for i in indices] | |
| return " ".join(fingerprint) | |