Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Javascript/caesars-cipher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function rot13(str) {
var result = "";
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const alphaShift = alphabet.substring(13) + alphabet.substring(0,13);

for (var char = 0; char < str.length; char++) {
if (alphabet.indexOf(str[char]) != -1) {
var getIndex = alphaShift.indexOf(str[char]);
result += alphabet[getIndex];
} else {
result += str[char];
}
}

return result;
}

rot13("SERR PBQR PNZC");