Latin alphabet cipher | JavaScript program to demonstrate Latin Alphabet Cipher function for calculating the encryption ; check isLetter ; Driver Code
function cipher ( str ) { for ( var i = 0 ; i < str . length ; i ++ ) { if ( ! isLetter ( str [ i ] ) && str [ i ] !== " " ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] >= " " && str [ i ] <= " " ) { document . write ( str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) + 1 + " " ) ; } else if ( str [ i ] >= " " && str [ i ] <= " " ) { document . write ( str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) + 1 + " " ) ; } if ( str [ i ] == " " ) document . write ( str [ i ] ) ; } document . write ( " " ) ; } function isLetter ( str ) { return str . length === 1 && str . match ( / [a-z] / i ) ; } var str = " " ; cipher ( str ) ;