t27.aiРусский

A key is a pair

You will learn

Why a key comes in two halves, which half you may share, and which half never leaves your machine.

To prove who you are to a code host without a password you make a key pair: a public half you hand out and a private half that never leaves your machine. The host keeps the public half and sends a challenge that only the private half can answer. In key_pair.t27 a pair has 2 halves, 1 is shared and 1 is kept, and 0 copies of the private half are ever sent to a host, a chat or a repository. The key text in the spec is a made-up placeholder, not a key. Never paste a real private half into a prompt: an agent that sees it has it.

Try it

In the widget, find the half that may be pasted into a host and the half that goes nowhere; then in the spec frame plant PRIVATE_COPIES_SENT = 1 and read which test turns red.

Open the interactive lesson →

A key is a pair ↗

The two halves of a key pair: the public half you hand out and the private half that never leaves your machine, with a made-up placeholder in place of a real key. Lesson 9 of the course Vibecoding from zero with t27.

specs/vibecoding/key_pair.t27

// SPDX-License-Identifier: Apache-2.0
; specs/vibecoding/key_pair.t27 -- lesson "A key is a pair" of the course "Vibecoding from zero with t27"
; To prove who you are to a code host without typing a password, you make a key pair: a public half
; you hand out freely and a private half that never leaves your machine. The host keeps the public
; half; only the owner of the private half can answer its challenge. The text below is a made-up
; placeholder, not a key: no real key or token is ever written into a spec, a prompt or a repository.
; ASCII only, English only.

module vibecoding_key_pair;

pub const PLACEHOLDER_PUBLIC : str = "EXAMPLE-PUBLIC-KEY-NOT-REAL";

; A pair has two halves.
pub const HALVES : u8 = 2;
; How many halves you give to the host or paste into a chat, and how many stay with you.
pub const HALVES_SHARED : u8 = 1;
pub const HALVES_KEPT : u8 = 1;
; How many copies of the private half go to a host, a chat or a repository.
pub const PRIVATE_COPIES_SENT : u8 = 0;

test a_pair_is_two_halves_one_shared_one_kept {
    assert HALVES_SHARED + HALVES_KEPT == HALVES;
}

test the_placeholder_is_text_not_a_secret {
    assert PLACEHOLDER_PUBLIC == "EXAMPLE-PUBLIC-KEY-NOT-REAL";
}

test the_private_half_is_never_sent {
    assert PRIVATE_COPIES_SENT == 0;
}

; Negative control: plant the bug "the private half was pasted somewhere" (PRIVATE_COPIES_SENT = 1)
; and the test above turns red; with the line as written it stays green.
test negative_control_the_kept_half_has_no_copies {
    assert PRIVATE_COPIES_SENT < HALVES_KEPT;
}

Open the lesson's spec in the player ↗

All lessons