Here’s our RSA-8 toy key is:
p = 11
q = 13
n = 143
e = 7
d = 103
Public = (7,143)
Private = (103,143)A normal OpenSSH RSA public key looks very different:
ssh-rsa AAAA... commentBut the encoded binary payload still carries RSA values including e and n.
In this experiment we build that SSH public-key blob ourselves, Base64-encode it, decode it again, and prove that it still represents:
e = 7
n = 143Lab warning: This 8-bit RSA key is deliberately insecure and modern OpenSSH will reject it for SSH authentication. i The goal is to understand the representation, not to bypass OpenSSH’s minimum RSA-key requirements.
8.1 SSH Public-Key Structure#
For an RSA public key, the SSH wire-format payload can be viewed as three length-prefixed fields:
string "ssh-rsa"
mpint e
mpint nEach field is binary. OpenSSH then Base64-encodes the complete payload for the familiar one-line public-key format:
ssh-rsa <Base64 payload> <optional comment>Conceptually:
(e=7, n=143)
|
v
+-------------------+
| string "ssh-rsa" |
| mpint e = 7 |
| mpint n = 143 |
+-------------------+
|
v
Base64 encoding
|
v
ssh-rsa AAAA...8.1.1 Build SSH Public Key#
This script intentionally implements the small amount of SSH binary encoding we need so we can see what is happening.
import base64
import struct
def ssh_string(data: bytes) -> bytes:
"""SSH string = 4-byte big-endian length + bytes."""
return struct.pack(">I", len(data)) + data
def ssh_mpint(value: int) -> bytes:
"""Encode a non-negative integer as an SSH mpint field."""
if value == 0:
raw = b""
else:
raw = value.to_bytes((value.bit_length() + 7) // 8, "big")
# SSH mpint is signed. Prefix zero if the high bit would
# otherwise make this positive integer look negative.
if raw[0] & 0x80:
raw = b"\x00" + raw
return ssh_string(raw)
# Our 8-bit RSA public key
e = 7
n = 143
blob = (
ssh_string(b"ssh-rsa")
+ ssh_mpint(e)
+ ssh_mpint(n)
)
encoded = base64.b64encode(blob).decode("ascii")
ssh_public_key = f"ssh-rsa {encoded} rsa-8-demo"
print(ssh_public_key)Notice that 143 is 0x8f.
Its highest bit is 1, so SSH’s signed mpint representation needs a leading zero byte:
143 -> 0x8f -> 0x00 0x8fThat is a serialization detail. The mathematical value is still 143.
8.2 Decode the SSH key#
Let’s decode the SSH key and recover e and n.
Now reverse the process.
import base64
import struct
def read_field(data: bytes, offset: int):
length = struct.unpack(">I", data[offset:offset + 4])[0]
offset += 4
value = data[offset:offset + length]
offset += length
return value, offset
def decode_ssh_rsa_public_key(line: str):
key_type, encoded, *_ = line.split()
if key_type != "ssh-rsa":
raise ValueError("Not an ssh-rsa public key")
blob = base64.b64decode(encoded)
offset = 0
algorithm, offset = read_field(blob, offset)
e_bytes, offset = read_field(blob, offset)
n_bytes, offset = read_field(blob, offset)
if algorithm != b"ssh-rsa":
raise ValueError("Unexpected algorithm")
e = int.from_bytes(e_bytes, "big", signed=False)
n = int.from_bytes(n_bytes, "big", signed=False)
return e, n
e2, n2 = decode_ssh_rsa_public_key(ssh_public_key)
print("Recovered e =", e2)
print("Recovered n =", n2)
print("Matches original:", (e2, n2) == (7, 143))Expected result:
Recovered e = 7
Recovered n = 143
Matches original: TrueWe have now demonstrated:
(7,143)
|
v
SSH binary representation
|
v
Base64 text representation
|
v
decode
|
v
(7,143)The long-looking SSH public key is a representation of the RSA numbers, not a replacement for them.
8.3 SSH RSA Private Key#
A real RSA private-key serialization contains more than our shorthand (d,n).
From our toy parameters we can derive the RSA private components:
p = 11
q = 13
n = 143
e = 7
d = 103and CRT values such as:
d mod (p - 1)
d mod (q - 1)
q^-1 mod pSo our tiny RSA mathematics contains enough information to describe a complete RSA private key mathematically.
However, producing a standards-compliant OpenSSH private-key file does not make this an acceptable SSH authentication key. Modern OpenSSH requires much larger RSA moduli and will reject our 8-bit key.
8.4 What Can the 8-bit RSA key do?#
Yes. We can prove that the RSA mathematics works without asking OpenSSH to accept an insecure key.
The cleanest demonstration is a toy textbook RSA signature.
Assume our demonstration message has already been represented as the small integer:
m = 9For this educational textbook-RSA exercise, sign using the private exponent:
signature = m^d mod nThen verify using the public exponent:
recovered = signature^e mod n8.4.1 Signature Demo#
# Our complete toy RSA parameters
p = 11
q = 13
n = 143
e = 7
d = 103
message = 9
# Toy textbook-RSA signing
signature = pow(message, d, n)
# Toy textbook-RSA verification
recovered_message = pow(signature, e, n)
print("Message:", message)
print("Signature:", signature)
print("Recovered during verification:", recovered_message)
print("Signature valid:", recovered_message == message)This gives us a real mathematical round trip:
message = 9
|
| private exponent d=103
v
signature
|
| public exponent e=7
v
message = 9That proves our RSA exponents perform the expected modular relationship.
Note that a real RSA signatures do not normally sign an arbitrary tiny integer this way. Production systems hash the message and use a defined signature encoding/padding scheme, such as RSA-PSS. Our modulus is far too small to hold the structures required by real secure signature schemes.
8.4.2 Another Proof: Encrypt/Decrypt#
We already demonstrated the complementary operation:
message = 9
ciphertext = pow(message, e, n)
plaintext = pow(ciphertext, d, n)
print("Message:", message)
print("Ciphertext:", ciphertext)
print("Recovered:", plaintext)For our key:
9 --public exponent--> 48 --private exponent--> 9Again, this is textbook RSA, not secure real-world RSA encryption. Real RSA encryption uses an approved padding/encoding construction such as OAEP and a sufficiently large modulus.
8.5 Summary#
We have proved that:
(e=7,n=143)can be represented in the SSH RSA public-key binary format.- That binary data can be Base64-encoded into an
ssh-rsa ...-shaped public-key line. - We can decode that line and recover exactly
e=7andn=143. - The matching private exponent
d=103performs the expected RSA modular operations. - The toy key can demonstrate textbook RSA encryption/decryption and signing/verification mathematics.
We have not proved that:
- the key is secure;
- the key is acceptable to modern OpenSSH;
- textbook RSA is a safe encryption or signature protocol;
- an 8-bit RSA modulus can support the padding and hashing required by real RSA protocols.
8.6 RSA-8 Toy vs Real SSH RSA key#
| RSA component | 8-bit Toy | Real SSH RSA key |
|---|---|---|
p | 11 | A large secret prime |
q | 13 | A large secret prime |
n | 143 | A large public modulus |
e | 7 | Commonly 65537 |
d | 103 | A large secret exponent |
| SSH-style public encoding | Can beconstructed | Yes |
| Textbooksign/verify | Yes | Mathematically possible, but not how secure protocols are defined |
| Secure RSAsignature padding | No room | Yes, with suitable key size and scheme |
| OpenSSH authentication | Rejected | Yes, when policy/algorithm requirements are met |
| Security | None | Depends on key size, generation, algorithms, and implementation |
Revision: 🔑 Key Takeaway#
This part adds another layer to our mental model:
RSA mathematical values
|
| e=7, n=143
v
SSH binary fields
|
v
Base64 encoding
|
v
ssh-rsa AAAA...and then:
ssh-rsa AAAA...
|
v
Base64 decode
|
v
SSH field parsing
|
v
e=7, n=143So an SSH public-key file is a container/representation of public-key parameters. Base64 is not the cryptography itself.
Meanwhile, the mathematical key can still demonstrate:
Encryption/decryption
m^e -> c -> c^d -> m
and
Toy signing/verification
m^d -> signature -> signature^e -> mOur 8-bit RSA key is mathematically functional but cryptographically useless: we can serialize its public values and demonstrate RSA operations, while real protocols correctly reject it because security requires far larger keys and proper padding/signature schemes.


