+ 1
How to implement Caesar encryption with punctuation marks?
https://code.sololearn.com/czQz5PLzo3lG/?ref=app I can only encrypt words without punctuation marks
3 Antworten
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 %)
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... ☹
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 ...