Created
August 26, 2011 10:59
-
-
Save smalljam/1173191 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
// http://jsfiddle.net/Exyk5/ | |
function decode(text){ | |
var lat='`~!@#$%^&qwertyuiop[]asdfghjkl;\'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?', | |
cyr='ёЁ!"№;%:?йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭ/ЯЧСМИТЬБЮ,', | |
from = cyr, | |
to = lat, | |
newtext = ''; | |
if( /[a-zA-Z]{2}/.test(text) ) { | |
from = lat; | |
to = cyr; | |
} | |
for(var i = 0, cnt = text.length;i<cnt;i++){ | |
newtext += to[ from.indexOf(text[i]) ] || text[i]; | |
} | |
return newtext; | |
} | |
console.log( decode('jy crfpfk xnj jy yf 2 ytltkb tltn') ); | |
console.log( decode('ш цфте ыщьу иуук') ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment