Skip to content

Instantly share code, notes, and snippets.

View SerhiiLihus's full-sized avatar
🦊

Serhii SerhiiLihus

🦊
View GitHub Profile
@SerhiiLihus
SerhiiLihus / bonfire-caesars-cipher.js
Created January 5, 2016 09:08
One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount.
// Bonfire: Caesars Cipher
// Author: @serhiilihus
// Challenge: http://www.freecodecamp.com/challenges/bonfire-caesars-cipher#?solution=function%20rot13(encodedStr)%20%7B%0A%20%20var%20codeArr%20%3D%20encodedStr.split(%22%22)%3B%20%20%2F%2F%20String%20to%20Array%0A%20%20var%20decodedArr%20%3D%20%5B%5D%2C%20newletterCode%3B%20%2F%2F%20Your%20Result%20goes%20here%0A%20%20%2F%2F%20Only%20change%20code%20below%20this%20line%0A%20%20codeArr.forEach(function(letter)%7B%0A%20%20%20%20%20%20%20newletterCode%20%3D%20(letter.charCodeAt()%20%3C%2065%20%7C%7C%20letter.charCodeAt()%20%3E%2090)%3F%20letter.charCodeAt()%20%3A%20(letter.charCodeAt()%20%2B%2013%20%3E%2090%20)%3F%20letter.charCodeAt()%20-%2013%20%3A%20letter.charCodeAt()%20%2B%2013%3B%0A%20%20%20%20%20%20%20decodedArr.push(String.fromCharCode(newletterCode))%3B%0A%20%20%7D)%3B%0A%20%20%2F%2F%20Only%20change%20code%20above%20this%20line%0A%20%20return%20decodedArr.join(%22%22)%3B%20%2F%2F%20Array%20to%20String%0A%7D%0A%0A%2F%2F%20Change%20the%20inputs%20below%