Caesar cipher · צופן קייסר
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.
ציפר קיסר
ההיסטוריוגרף הרומאי סווטוניוס כתב שג'וליו קיסר הסתיר את הודעותיו על ידי הזזת כל אות שלושה מקומות לאורך האלפבית.
alphabet.index(ch) נותן את מיקום האות, מ-0 עבור a עד 25 עבור z. הוסף את ההזזה והשתמש ב-% 26, כך שמיקום 26 יתעגל חזרה ל-0. כדי לפענח הודעה, הזז אות שוב ב-26 פחות ההזזה המקורית.
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". · כתוב caesar(text, shift) שמזיז כל אות lowercase shift מקומות לאורך האלפבית, תוך עריגה מה-z חזרה ל-a. השאיר שאר כל דמות כפי שהיא. caesar("hello, world", 3) הוא "khoor, zruog".
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.