# Solving and testing the Caesar cipher

Решение без тестов быстро ломается, поэтому добавим к задаче простые проверки.

## Задача

Реализовать шифр Цезаря: сдвинуть каждую букву строки на фиксированное число позиций в алфавите.

## Решение

```python
def caesar(text: str, shift: int) -> str:
    result = []
    for ch in text:
        if ch.isalpha():
            base = ord('A') if ch.isupper() else ord('a')
            result.append(chr((ord(ch) - base + shift) % 26 + base))
        else:
            result.append(ch)
    return ''.join(result)


print(caesar("Hello, World!", 3))
```

## Как это работает

Буква переводится в номер внутри алфавита, к номеру прибавляется сдвиг, а остаток от деления на 26 обеспечивает «зацикливание» алфавита. Прочие символы не меняются.

## Пример работы

```text
Khoor, Zruog!
```

## Сложность

O(n) по времени, O(n) по памяти под результат.


## Проверка тестами

Хорошая привычка — проверять решение сразу на нескольких примерах, включая крайние случаи.

```python
assert is_valid(True) is not None  # базовая проверка вызова
assert is_valid(False) is not None  # и второй случай
```

Такой минимум уже защищает от случайной ошибки при правках кода.

Тесты вида assert удобны для учебных задач: они короткие, наглядные и не требуют фреймворков.

**Читайте также:**

[удобны](https://gitlab.com/chuongnhuhoa/trusrewre/-/blob/main/articles/factorial-razbor-mw00m9ff.md) · [фреймворков](https://news-ctl-posts.hashnode.dev/step-by-step-the-sum-of-digits-mw03ux5b) · [букву](https://ink.synkosmos.org/oz2337b6/girthmaster-sex-videos-featuring-thick-cock-and-hardcore-scenes) · [каждую](https://statics.pancake.vn/web-media-264/46/2c/39/49/1d40eed307b15fd99cc5855a3c6c7fb01dc796cbe575ca17a64d0d8f.pdf) · [добавим](https://jaflysilve.freeflarum.com/d/13758-13758-animebaexox) · [проверки](https://mycommunitycalendars.com/wp-content/uploads/event-manager-uploads/event_banner/2026/11/unsol-eil-leaks-68ffea.pdf) · [второй](https://posts.workshop-hub.workers.dev/factorial-shagi) · [простые](https://freelanceaccounts.co.ke/%E5%AA%9A%E9%BB%91%E8%A7%86%E9%A2%91?f=instapaper) · [работает](https://dev.to/valentina_silvaferreira_/rieshaiem-i-tiestiruiem-shifr-tsiezaria-59g) · [деления](https://kappa.lol/eoLavj) · [result.append(ch](https://news-ctl-posts.hashnode.dev/solving-and-testing-factorial-computation-part-7818) · [крайние](https://kappa.lol/Gkt9NV) · [включая](https://dev.to/valentina_silvaferreira_/nieskolko-rieshienii-rieshieniia-prostoi-zadachi-chisla-fibonachchi-48da) · [shift](https://mycommunitycalendars.com/wp-content/uploads/event-manager-uploads/event_banner/2026/11/wenda-x-gray-porn-61fc4e.pdf) · [join(result](https://kappa.lol/oyoRTn) · [сразу](https://jaflysilve.freeflarum.com/d/13756-13756-secret-stars-aleksandra-nude-photo-gallery-70-hd-pics) · [алфавите](https://contracosta.news/wp-content/uploads/event-manager-uploads/event_banner/2026/11/lolapoppss-leak-00c873.pdf) · [остаток](https://dev.to/valentina_silvaferreira_/rassmatrivaiem-klassichieskuiu-zadachu-provierka-anaghramm-geg) · [Реализовать](https://contracosta.news/wp-content/uploads/event-manager-uploads/event_banner/2026/11/kelsey-frances-nude-715266.pdf) · [переводится](https://mariak66.wixsite.com/my-site-1/post/indian-brother-and-sister-mms) · [Решение](https://claramoreau385.overblog.fr/2026/11/post.html) · [return](https://rentry.org/bokep-jepang-mom-sub-indo-310828) · [поэтому](https://jaflysilve.freeflarum.com/d/13705-13705-burdieowo) · [ord('a](https://ees.zone/k%C4%B1z%C4%B1+zorla+yata%C4%9Fa+ba%C4%9Fl%C4%B1yor?f=instapaper) · [World](https://blogfreely.net/igorcollins26/bikinibee-porn-gallery-cute-anal-scenes-with-bikini-models) · [тестами](https://cultmtl.com/wp-content/uploads/event-manager-uploads/event_banner/2026/11/event-9689c3.pdf) · [Прочие](https://avdc.org/wp-content/uploads/event-manager-uploads/event_banner/2026/11/girlsdotoys-episode-list-cc265f.pdf) · [правках](https://secure.linkcentre.com/status/1732977/?from=submit)

