# Understanding 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) по памяти под результат.


Это решение удобно как отправная точка для экспериментов: попробуйте изменить входные данные и проследить за поведением кода.

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

[переводится](https://pastebin.com/BMwUgrRc) · [World](https://dev.to/devnote2319/scheduling-retries-in-a-publishing-pipeline-sjke6-2iip) · [Предлагаю](https://dev.to/devnote2319/idempotent-publishing-jobs-6avwq-2mld) · [фиксированное](https://dev.to/devnote2319/idempotent-publishing-jobs-oujtx-5dao) · [результат](https://paste2.org/8czIj9Ua) · [деления](https://ink.synkosmos.org/ozd1c055/mrbyty-s-b-lmrs-shhd-fydyw-bhy-mt) · [прибавляется](https://articlescad.com/riley-reid-and-jameliz-steamy-threesome-and-exclusive-onlyfans-leaks-419323.html) · [число](https://ferment.site/m/random/t/2649) · [алфавита](https://dev.to/devnote2319/idempotent-publishing-jobs-6mcdb-10oo) · [result.append(ch](https://edu-notes-pages.pages.dev/gcd-razbor/) · [проследить](https://trentonmonitor.com/submit-an-event/#pending) · [ord('a](https://pastelink.net/sonetu66) · [ch.isalpha](https://newatsapp.altervista.org/wp-content/uploads/event-manager-uploads/event_banner/2026/11/ai-b8ff62.pdf) · [букву](https://secure.linkcentre.com/status/1738126/?from=submit) · [отправная](https://ninar788.wixsite.com/my-site-1/post/peakvids--hot-pornstar-videos--exclusive-hardcore-scenes) · [входные](https://www.booksie.com/790267-solving-and-testing-quicksort) · [точка](https://statics.pancake.vn/web-media-264/15/18/17/a5/187563206ceb8165373b81db1f329886d257fcd819c7f208a178770c.pdf) · [внутри](https://contracosta.news/wp-content/uploads/event-manager-uploads/event_banner/2026/11/south-asian-sex-154655875411554321-porno-45f37f.pdf) · [данные](https://ecency.com/@karelcerny7473/rocketreyna-nude-leaked-videos-and-onlyfans-lesbian-4455ff) · [Цезаря](https://dev.to/devnote2319/keeping-link-blocks-stable-across-platforms-ntgpa-1p8h) · [попробуйте](https://statics.pancake.vn/web-media-264/73/c6/2f/42/43231d8db8ace463cc8b9e5fc794f77325eb03542f5ebfe0cf457e7c.pdf) · [каждую](https://mycommunitycalendars.com/wp-content/uploads/event-manager-uploads/event_banner/2026/11/ammyasxv-d1de02.pdf) · [Буква](https://pastelink.net/f4fk0943) · [времени](https://workshopfe622386.vuodatus.net/lue/2026/11/2) · [задачу](https://dev.to/devnote2319/scheduling-retries-in-a-publishing-pipeline-cxf88-3jho) · [result](https://dev.to/devnote2319/idempotent-publishing-jobs-2q4id-53np) · [удобно](https://dev.to/devnote2319/idempotent-publishing-jobs-oxu5p-1763) · [вместе](https://sway.cloud.microsoft/rNrqzkAOT5yZGh9D) · [работает](https://ymcatexasyg.org/wp-content/uploads/event-manager-uploads/event_banner/2026/11/envel-heroes-14e269.pdf) · [Решение](https://jaflysilve.freeflarum.com/d/19974-19974-ekaterina-lisina-feet)

