-
-
Save anbinh/5275185 to your computer and use it in GitHub Desktop.
The Substitution Cipher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function( | |
t, // input text string | |
k, // input key string | |
d, // direction | |
// placeholder | |
i, // iterator | |
o, // output | |
){ | |
o=""; // set output to empty string. | |
for(i in t) // loop through all input string. | |
o+=d? // check if encrypt or decrypt? and map string <-> key. | |
k[t.charCodeAt(i)-97]: | |
String.fromCharCode(k.indexOf(t[i])+97); | |
return o | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(t,k,d,i,o){o="";for(i in t)o+=d?k[t.charCodeAt(i)-97]:String.fromCharCode(k.indexOf(t[i])+97);return o} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "substitutionCipher", | |
"description": "this will encrypt/decrypt your text using the substitution method.", | |
"keywords": [ | |
"substitution ", | |
"cipher", | |
"encryption", | |
"decryption", | |
"string" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<title>The Substitution Cipher</title> | |
<div>Expected value: <b>zebrascdfghijklmnopqtuvwxy, siaazqlkbavazoarfpbluaoar, ulhglwlfdcrrmpelbcdliuci</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
// write a small example that shows off the API for your example | |
// and tests it in one fell swoop. | |
var subst = function(t,k,d,i,o){o="";for(i in t)o+=d?k[t.charCodeAt(i)-97]:String.fromCharCode(k.indexOf(t[i])+97);return o} | |
var k1="zebrascdfghijklmnopqtuvwxy"; | |
var k2="iveflntwrdgombxypsujhackzq"; | |
document.getElementById( "ret" ).innerHTML = [subst("abcdefghijklmnopqrstuvwxyz", k1, 1), | |
subst("fleeatoncewearediscovered", k1, 1), | |
subst("howtoconfessmyloveforher", k2, 0)]; | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Nattawut Phetmak <http://about.me/neizod> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment