Last active
June 23, 2016 08:10
-
-
Save valiafetisov/98b9df129a5555dccd952d857a075254 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 alphabet = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; | |
const factors = [[38,1,4,4], [9,2,2,5], [36,3,8], [0,7,14], [38,1,1]]; | |
export default ЛСДУ3ЙФЯУ9 = (name) => { | |
// check | |
if(typeof name !== 'string') return console.error('name is not a string'); | |
if(name.length > 19) return console.error('name is longer then possible'); | |
// prepare | |
name = name.toLowerCase().replace(/ /g, ''); | |
// encode and group | |
var array = []; | |
name.split('').forEach( (s, i) => { | |
let index = i%5; | |
let number = alphabet.indexOf(s) + 10; | |
if(array[index]) { | |
array[index].push(number); | |
} else { | |
array[index] = [number]; | |
} | |
}); | |
// apply factors | |
array = array.map((tr, trIndex) => { | |
return tr.map((td, tdIndex) => { | |
return td * factors[trIndex][tdIndex]; | |
}); | |
}); | |
// generate group summ | |
array = array.map((tr, trIndex) => { | |
let summ = 0; | |
tr.forEach((td, tdIndex) => { | |
summ += td; | |
}); | |
return summ % (alphabet.length + 10) - 10; | |
}); | |
// decode | |
return array.map((each) => { | |
if(each < 0) return 10 + each; | |
return alphabet[each]; | |
}).join('').toUpperCase(); | |
} | |
console.log(ЛСДУ3ЙФЯУ9("Артем Юрьевич Чайка")); // ЛСДУ3 | |
console.log(ЛСДУ3ЙФЯУ9("Игорь Юрьевич Чайка")); // ЙФЯУ9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment