Skip to content

Instantly share code, notes, and snippets.

@smalljam
Created August 26, 2011 10:59
Show Gist options
  • Save smalljam/1173191 to your computer and use it in GitHub Desktop.
Save smalljam/1173191 to your computer and use it in GitHub Desktop.
// 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