Caesar cipher · Kiper Caesar
Caesar cipher
The Roman historian Suetonius wrote that Julius Caesar hid his messages by shifting each letter three places along the alphabet.
alphabet.index(ch) gives a letter's position, from 0 for a to 25 for z. Add the shift and use % 26, so that position 26 wraps back to 0. To decode a message, shift it again by 26 minus the original shift.
Caesar cipher
Sejarawan Romawi Suetonius menulis bahwa Julius Caesar menyembunyikan pesannya dengan menggeser setiap huruf tiga tempat di sepanjang alfabet.
alphabet.index(ch) memberikan posisi sebuah huruf, dari 0 untuk a hingga 25 untuk z. Tambahkan pergeseran dan gunakan % 26, agar posisi 26 kembali ke 0. Untuk mendekode pesan, geser lagi sebanyak 26 dikurangi pergeseran asli.
Write caesar(text, shift) that moves every lowercase letter shift places along the alphabet, wrapping from z back to a. Leave every other character as it is. caesar("hello, world", 3) is "khoor, zruog". · Tulis caesar(text, shift) yang menggeser setiap huruf kecil shift tempat ke depan dalam alfabet, melingkar dari z kembali ke a. Biarkan setiap karakter lain tetap apa adanya. caesar("hello, world", 3) adalah "khoor, zruog".
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.