-
-
Save suissa/a58b19c6ba80e1ff756bfc8a7c1c3752 to your computer and use it in GitHub Desktop.
This file contains 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
const CYPHER_LIMIT = 78 | |
const A = 65 | |
const Z = 90 | |
const add = ( c ) => ( s ) => s.concat( c ) | |
const getCharCode = String.fromCharCode | |
const isSpace = ( x ) => ( x === 32 ) | |
const isInRange = ( min, max ) => ( x ) => | |
( ( x >= min ) && ( x <= max ) ) | |
const toCharCode = ( letter, i, str ) => | |
str.join( '' ).charCodeAt( i ) | |
const getPosition = ( CYPHER_LENGTH ) => ( x ) => | |
( x >= CYPHER_LIMIT ) ? x - CYPHER_LENGTH : x + CYPHER_LENGTH | |
const getCharCodeFromCypher = ( CYPHER_LENGTH ) => ( x ) => | |
( isInRange( A, Z )( x ) ) ? getPosition( CYPHER_LENGTH )( x ) : x | |
const cypherThis = ( CYPHER_LENGTH ) => ( x, isSpace ) => | |
getCharCode( isSpace ? x : getCharCodeFromCypher( CYPHER_LENGTH )( x ) ) | |
const toCypher = ( CYPHER_LENGTH ) => ( result, x, i ) => | |
add ( cypherThis( CYPHER_LENGTH )( x ), isSpace( x ) )( result ) | |
const rot = ( CYPHER_LENGTH ) => ( str ) => | |
str.toUpperCase() | |
.split( '' ) | |
.map( toCharCode ) | |
.reduce( toCypher( CYPHER_LENGTH ), '' ) | |
const rot13 = rot( 13 ) | |
console.log('rot13 LBH QVQ VG!', rot13( 'LBH QVQ VG!' ) ) | |
console.log('rot13 suissa', rot13( 'suissa' ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment