UNPKG

ovaltine

Version:

A library for your Little Orphan Annie Secret decoder ring.

1 lines 553 B
module.exports={encrypt:function(r,n){var e="";if(null==n)throw Error("Must specify pin!");if(n=parseInt(n),0>n||n>=26)throw Error("Pin not on decoder ring!");r=r.replace(/[^a-zA-Z]+/g,""),r=r.toLowerCase();for(var o=0;o<r.length;o++){var t=r.charCodeAt(o);e+=t-97+n+"-"}return e.substring(0,e.length-1)},decrypt:function(r,n){var e="";if(null==n)throw Error("Must specify pin!");if(n=parseInt(n),r=r.split("-"),0>n||n>=26)throw Error("Pin not on decoder ring!");for(var o=0;o<r.length;o++){var t=parseInt(r[o]);e+=String.fromCharCode(t+97-n)}return e}}