How to implement Caesar encryption with punctuation marks? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to implement Caesar encryption with punctuation marks?

https://code.sololearn.com/czQz5PLzo3lG/?ref=app I can only encrypt words without punctuation marks

11th Mar 2021, 5:28 PM
PUFFIN Channel
PUFFIN Channel - avatar
3 Answers
0
You can simply extend your alphabet to include the punctuation mark characters. Also you need to cycle to the beginning of the array if it exceeds it (e.g. with modulus operator %)
11th Mar 2021, 6:09 PM
Giorgos
0
Giorgos Dim , and why can't I just create another alphabet "gamma", where punctuation marks will be collected? Actually, I did so and added the same encryption function as with alphabetic alphabets, but, unfortunately, it does not work with punctuation marks... ☹
11th Mar 2021, 6:23 PM
PUFFIN Channel
PUFFIN Channel - avatar
0
PUFFIN Channel Yes u can do it like this but its a little harder and also after encryption the punctuating char will always end up on a punctuating char which may not be wanted. Your code is not working because it does not check if the index is inside the array bounds, the index should cycle back to the start. For example: array=[a, b, c, d] index=3 should be d index=4 should be a index=5 should be b ...
11th Mar 2021, 6:32 PM
Giorgos