How to resolve the algorithm Vigenère cipher step by step in the Jsish programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Vigenère cipher step by step in the Jsish 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 Jsish programming language
Source code in the jsish programming language
/* Vigenère cipher, in Jsish */
"use strict";
function ordA(a:string):number {
return a.charCodeAt(0) - 65;
}
// vigenere
function vigenereCipher(text:string, key:string, decode:boolean=false):string {
var i = 0, b;
key = key.toUpperCase().replace(/[^A-Z]/g, '');
return text.toUpperCase().replace(/[^A-Z]/g, '').replace(/[A-Z]/g,
function(a:string, idx:number, str:string) {
b = key[i++ % key.length];
return String.fromCharCode(((ordA(a) + (decode ? 26 - ordA(b) : ordA(b))) % 26 + 65));
});
}
provide('vigenereCipher', 1);
if (Interp.conf('unitTest')) {
var text = "The quick brown fox Jumped over the lazy Dog the lazy dog lazy dog dog";
var key = 'jsish';
var enc = vigenereCipher(text, key);
; text;
; enc;
; vigenereCipher(enc, key, true);
}
/*
=!EXPECTSTART!=
text ==> The quick brown fox Jumped over the lazy Dog the lazy dog lazy dog dog
enc ==> CZMIBRUSTYXOVXVGBCEWNVWNLALPWSJRGVVPLPWSJRGVVPDIRFMGOVVP
vigenere(enc, key, true) ==> THEQUICKBROWNFOXJUMPEDOVERTHELAZYDOGTHELAZYDOGLAZYDOGDOG
=!EXPECTEND!=
*/
You may also check:How to resolve the algorithm Amicable pairs step by step in the uBasic/4tH programming language
You may also check:How to resolve the algorithm Barnsley fern step by step in the Perl programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the J programming language
You may also check:How to resolve the algorithm Holidays related to Easter step by step in the Delphi programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the Haskell programming language