1) Using any programming language of your choice implement the Rail Fence Cipher
ID: 3755504 • Letter: 1
Question
1) Using any programming language of your choice implement the Rail Fence Cipher encryption algorithm
2) Specifications: The program should take two inputs
1) Message n
2) The key k, which is a tuple (d,r), where d is the depth of the cipher and r is the number of times the algorithm should repeat itself. The program should produce as output the encrypted message as text
3) What will be the decryption algorithm for a Rail-Fence cipher? Write down the pseudocode for the algorithm.
4) Using any programming language of your choice implement the Rail Fence Cipher decryption algorithm
5) Specifications: The program should take two inputs
1) Encrypted Message n
2) The key k, which is a tuple (d,r), where d is the depth of the cipher and r is the number of times the algorithm should repeat itself. The program should produce as output the decrypted message as text
Test 1 (Encryption)
1) Using a key of (4,5) use your code to encrypt the following text: “CRYPTOLOGY IS
THE PRACTICE AND STUDY OF TECHNIQUES FOR SECURE COMMUNICATION IN
THE PRESENCE OF THIRD PARTIES CALLED ADVERSARIES.”
2) Do not ignore spaces
Test 2 (Decryption)
1) Using a key of (3,3) use your code to decrypt the following text: “TAOTINEN KAT I
ODIOAEI OHHLSCTE TTETOEL BI IHI GAO EPSEA TO SS EEK ELRCPTSIY
EANRPHMCYEK E CREAAIEJURTE IEASHI MA DRN RH AUWTA RF
EFTFHENTPSF Q TAILB E TTECAPMSIYIY SRPURNTBL YCL OANAO E
TVREAOSHOTTNULSRHK”
2) Do not ignore spaces
Explanation / Answer
Since, the question says, use any language to create Rail Fence Cipher encryption algorithm. So, I will be using JavaScipt for the same.
Here I have created an HTML program to call Encrytion and Decryption Algorithms. I have added both algorithm in one file under two different functions.
HTML File:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chrome Dev Tools</title>
<script src="app.js"></script>
</head>
<body>
<label>Enter Your Message</label>
<input type="text" id="n">
<button>Get Decryption</button><br/>
<button>Get Encryption</button><br/>
<span id="dataSpan"></span>
</body>
</html>
Here you can see that we have taken the Message in input box and named it m. Now We will write the Algorithms
Algorithm for Encryption and Decryption via Rail Fence Cipher Encryption:
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.zigzag = factory();
}
}(this, function () {
function makeMap( len, n) {
var i, pip, period = 2 * (n - 1);
var rows = Array.apply( null, Array( n)).map( function(){ return []}); // array of arrays
for( i = 0; i < len; i++) {
pip = i % period;
r = pip < (n - 1) ? pip : period - pip;
rows[ r].push( i);
}
return Array.concat.apply(null,rows);
}
function decrypt( len, n) {
text = document.getElementById("n").value;
var i, mapped = makeMap(len,n), result = "";
return text.split('').reduce(function(p,c,i,a){ return p + a[mapped.indexOf(i)]},'');
for( i = 0; i < len; i++) result += text.substr( mapped.indexOf( i), 1);
return result;
}
function encrypt( len, n) {
text = document.getElementById("n").value;
var i, mapped = makeMap(len,n), result = "";
for( i = 0; i < len; i++) result += text.substr( mapped[ i], 1);
return result;
}
return {
encrypt: encrypt
,decrypt: decrypt
};
}));
Here you can see we have 3 inputs: text, len, n which is m,d,r of the question you have provided. And I have fixed the values of d,r for Encryption and Decryption itself at HTML level. But these can de dynamic too.
So, we have solved all the questions keeping in mind the specifications.
Tests:
1. Encryption: "M ELT UORIAAYGOOT REELCFVASDAREEORSPS OT UYOEGNRLYI SAOTCNTUTN N NLZN RTCL HTOECM HIFUNEO DESRE N HTAERLTDT AIU SET NIFRAINSCRTREA IB SCGDAIPOSAVOTNE ARIAT A VOACINMOEI"
2. Decryption: "MORE GENERALLY IT IS ABOUT CONSTRUCTING AND ANALYZING PROTOCOLS THAT OVERCOME THE
INFLUENCE OF ADVERSARIES AND THAT ARE RELATED TO VARIOUS ASPECTS IN INFORMATION SECURITY"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.