Latin to Tifinagh

Some partial algorithm using mapping to convert from Latin to Tifinagh

by hirako2000

JavaScript

const mapping = {
'a': 'ⴰ',
'c': 'ⵛ',
' ': ' ',
'p': 'ⵒ',
'b': 'ⴱ',
'e': 'ⴻ',
'g': 'ⴳ',
't': 'ⵜ',
'd': 'ⴷ',
'tˁ': 'ⵟ',
//'dˁ': 'ⴹ',
'k': 'ⴽ',
'ɡ': 'ⴳ',
'q': 'ⵇ',
'β': 'ⴲ',
'f':'ⴼ',
'v': 'ⵠ',
'θ': 'ⵝ',
'ð': 'ⴸ',
'ðˁ': 'ⴺ',
's': 'ⵙ',
'z': 'ⵣ',
//'sˁ': 'ⵚ',
//'zˁ': 'ⵥ',
'ʃ': 'ⵛ',
'ʝ': 'ⴴ',
'x': 'ⴿ',
'ɣ': 'ⵖ',
'χ': 'ⵅ',
'ʁ': 'ⵖ',
'ħ': 'ⵃ',
'ʕ': 'ⵄ',
'h': 'ⵀ',
'm': 'ⵎ',
'n': 'ⵏ',
'w': 'ⵡ',
'ʷ': 'ⵯ',
'r': 'ⵔ',
//'rˤ': 'ⵕ',
'l': 'ⵍ',
'i': 'ⵉ',
'j': 'ⵊ',
'y': 'ⵢ',
'u': 'ⵓ',
'o': 'o', // no correspdance for letter o.
'ẓ':	'ⵥ'
}

const ciphered = "ⵇⵡⴻⵔⵜⵢⵓⵉoⵒⴰⵙⴷⴼⴳⵀⵊⴽⵍⵣⴿⵛⵠⴱⵏⵎ";
const deciphered = "qwertyuiopasdfghjklzxcvbnm";


cipher(deciphered);
decipher(ciphered);

 
function cipher(input) {
 let deciphered = '';
 for (var i = 0; i < input.length; i++) {
   deciphered = deciphered + mapping[input[i]];
 }
 console.log(deciphered);
 return deciphered;
}


function decipher(input) {
 let ciphered = '';
 for (var i = 0; i < input.length; i++) {
   ciphered = ciphered + getKeyByValue(mapping, input[i]);
 }
 console.log(ciphered);
 return ciphered;

}

function getKeyByValue(object, value) {
  return Object.keys(object).find(key => object[key] === value);
}