Working with runes or bytes

Trying to implement the Caesar cipher in go, but i got a question, is it better to try to implement it using runes or bytes. Heres an example i did that just shifts the letters one step forward. Also if my example is okay, how can i make it better? Think the way i did it isint the best approach
Basically is there a more convenient way of manipulating symbols in go?


If you’re dealing with symbolic text (beyond ASCII a-z or 0-9) and output as string, it’s better off with runes than bytes since Caesar cipher is shifting N times of character’s position based on your defined symbolic list.

Otherwise, you can use bytes but must be aware that some rune symbols are multi-bytes so there’s a need to do special management for them. A map list would be a suitable candidate.

EDIT: merged from my next post.

If you’re referring to the cipher itself…

  1. you can abstract the shifting round (in the example, it is 1) into a parameter so that you can shift vigilantly (uint data types would be a good candidate). Shifting can be 2, 3, 4, depending on how big your symbol list is.

  2. As referred to my previous post, you can also upgrade it with a selected rune list instead of referring to the default rune table. As long as the end and the start of the list are connected, your cipher could be operating fine shifting characters around.

As a gentle reminder, Caesar cipher is now serving for education purpose, don’t use it in production.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.