How to resolve the algorithm Vigenère cipher step by step in the Objeck programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Vigenère cipher step by step in the Objeck programming language

Table of Contents

Problem Statement

Implement a   Vigenère cypher,   both encryption and decryption. The program should handle keys and text of unequal length, and should capitalize everything and discard non-alphabetic characters. (If your program handles non-alphabetic characters in another way, make a note of it.)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Vigenère cipher step by step in the Objeck programming language

Source code in the objeck programming language

bundle Default {
   class VigenereCipher {
      function : Main(args : String[]) ~ Nil {
         key := "VIGENERECIPHER";
         ori := "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!";
         enc := encrypt(ori, key);
         IO.Console->Print("encrypt: ")->PrintLine(enc);
         IO.Console->Print("decrypt: ")->PrintLine(decrypt(enc, key));
      }

      function : native : encrypt(text : String, key : String) ~ String {
         res := "";
         text := text->ToUpper();
         j := 0;

         each(i : text) {
            c := text->Get(i);
            if(c >= 'A' & c <= 'Z') {
               res->Append(((c + key->Get(j) - 2 * 'A') % 26 + 'A')->As(Char));
               j += 1;
               j := j % key->Size();
            };
        };

        return res;
      }

      function : native : decrypt(text : String, key : String) ~ String {
         res := "";
         text := text->ToUpper();
         j := 0;

         each(i : text) {
            c := text->Get(i);
            if(c >= 'A' & c <= 'Z') {
               res->Append(((c - key->Get(j) + 26) % 26 + 'A')->As(Char));
               j += 1;
               j := j % key->Size();
            };
         };

         return res;
      }
   }
}

  

You may also check:How to resolve the algorithm Terminal control/Ringing the terminal bell step by step in the Bracmat programming language
You may also check:How to resolve the algorithm N-smooth numbers step by step in the Raku programming language
You may also check:How to resolve the algorithm Strip comments from a string step by step in the AutoIt programming language
You may also check:How to resolve the algorithm Longest string challenge step by step in the Ruby programming language
You may also check:How to resolve the algorithm Execute a Markov algorithm step by step in the EchoLisp programming language