VBA – Sorting VBA array – Functions in VBA

In the current article, I will show how to resolve with VBA an entry exam for programming in HackBulgaria. The problems could be resolved in any language and I will use VBA for this last task. The program is actually the development of a cipher, thus it takes string as input and codes it as per the cipher. This is how the task looks like:


Caesar cipher

Caesar cipher is one of the simplest and most widely known encryption techniques. The method is named after Julius Caesar, who used it in his private correspondence.

You have the implement a function with the following signature: caesar_encrypt(str, n).

  • The argument str is of type string
  • The argument n is of type integer.
  • The function should return an encrypted string

The encryption can be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,…, Z = 25. Encryption of a letter x by a shift n can be described mathematically as,

Do not encrypt any non-alphabetical characters!

Example:


This is how the magic is done:

caesar_encrypt

So, how does it looks like in vba?

Enjoy it! 🙂

Tagged with: , ,