CryptoAssist/src/blocks/lettersToNums.js

41 lines
842 B
JavaScript
Raw Normal View History

2017-02-25 11:34:58 +00:00
module.exports = {
name: "Letters to Numbers",
inputs: {
2017-03-13 12:41:56 +00:00
letters: {
name: "Letters",
type: "text",
required: true,
inline: false
},
offset: {
name: "Offset",
type: "text",
2017-03-14 00:01:50 +00:00
required: false,
inline: false,
default: "0"
2017-03-13 12:41:56 +00:00
}
2017-02-25 11:34:58 +00:00
},
output: true,
execute: function({letters, offset}, elem){
return letters
.split("")
.map((char)=>(char.charCodeAt(0)))
.filter((asciiVal)=>(((asciiVal >= 65) && (asciiVal <= 90)) || ((asciiVal >= 97) && (asciiVal <= 122))))
.map((asciiVal)=>{
if(asciiVal <= 90){
return asciiVal - 65;
}
else{
return asciiVal - 97;
}
})
2017-03-14 00:01:50 +00:00
.map((num)=>(num + parseInt(offset)))
2017-02-28 08:58:18 +00:00
.map((num)=>(((num%26)+26)%26))
2017-02-25 11:34:58 +00:00
.join(",");
},
pageBlock: {
html: "",
js: function(){}
}
}