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) تحرك كل حرف صغير shift خطوات في الأبجدية، مع العودة من z إلى a. اترك باقي الأحرف كما هي. caesar("hello, world", 3) يُنتج "khoor, zruog".
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.