-36
you are viewing a single comment's thread
view the rest of the comments
[-] cow@lemmy.world 1 points 1 day ago

Ok I played with this, made a very trivial encoding with 16 words in python for fun today.

code

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import ed25519
import itertools
import sys

if sys.argv[1] == "words":
    with open("wordlist-65536.txt", "r") as f:
        words = [x.strip().lower() for x in f.readlines()]

    assert len(words) == 65536

    k = serialization.load_ssh_private_key(open(sys.argv[2], "rb").read(),
                                           password=None)

    j = k.private_bytes(encoding=serialization.Encoding.Raw,
                        format=serialization.PrivateFormat.Raw,
                        encryption_algorithm=serialization.NoEncryption())

    for a, b in itertools.batched(j, n=2):
        z = a << 8
        if b is not None:
            z = z | b

        print(words[z], end=" ")

    print()

elif sys.argv[1] == "key":
    seed = [x.strip() for x in input("Enter your mnemonic ssh key: ").split()]
    assert len(seed) == 16

    with open("wordlist-65536.txt", "r") as f:
        words = [x.strip().lower() for x in f.readlines()]

    assert len(words) == 65536

    words_map = {}
    for i, word in enumerate(words):
        words_map[word] = i

    k = bytearray()
    for word in seed:
        z = words_map[word]

        b = z & 0xff
        a = (z >> 8) & 0xff

        k.append(a)
        k.append(b)

    k2 = ed25519.Ed25519PrivateKey.from_private_bytes(k)

    private_bytes = k2.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.OpenSSH,
        encryption_algorithm=serialization.NoEncryption())

    open(sys.argv[2], "wb+").write(private_bytes)
```
this post was submitted on 24 Nov 2026
-36 points (23.5% liked)

Selfhosted

64081 readers
741 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

Detailed Rules Post

  1. Be civil.

  2. No spam.

  3. Posts are to be related to self-hosting.

  4. Don't duplicate the full text of your blog or readme if you're providing a link.

  5. Submission headline should match the article title.

  6. No trolling.

  7. Promotion posts require active participation, with an account that is at least 30 days old. F/LOSS without a paywall has exceptions, with requirements. See the rules link for details. Tags [CBH] or [AIP] are required, see the links in Rule 8 for details.

  8. AI-related discussions and AI-involved promotional posts have additional requirements for tagging, as noted in Rule 7 and the AI & Promotional Post Expanded Rules post, and find example disclosures here.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 3 years ago
MODERATORS