Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: ROT8000 implementation?

by karlgoethebier (Abbot)
on Oct 16, 2021 at 13:53 UTC ( [id://11137629]=note: print w/replies, xml ) Need Help??


in reply to ROT8000 implementation?

If you really want to do this why don’t you port some code from GitHub you linked to to Perl?

function rot8000() { // these come from the valid-code-point-transitions.json file gene +rated from the c# proj // this is done bc: 1) don't trust JS's understanging of surrogate + pairs and 2) consistency with original rot8000 const valid_code_points = JSON.parse('{"33":true,"127":false,"161":true,"5760":false,"57 +61":true,"8192":false,"8203":true,"8232":false,"8234":true,"8239":fal +se,"8240":true,"8287":false,"8288":true,"12288":false,"12289":true,"5 +5296":false,"57344":true}'); const BMP_SIZE = 0x10000; this.rotlist = {}; // the mapping of char to rotated char hiddenblocks = []; var startblock = 0; for (var key in valid_code_points) { if (valid_code_points.hasOwnProperty(key)) { if (valid_code_points[key] == true) hiddenblocks.push({ start: startblock, end: parseInt(k +ey) - 1 }); else startblock = parseInt(key); } } var validintlist = []; // list of all valid chars var currvalid = false; for (var i = 0; i < BMP_SIZE; i++) { if (valid_code_points[i] !== undefined) { currvalid = valid_code_points[i] } if (currvalid) validintlist.push(i); } var rotatenum = Object.keys(validintlist).length / 2; // go through every valid char and find its match for (var i = 0; i < validintlist.length; i++) { this.rotlist[String.fromCharCode(validintlist[i])] = String.fromCharCode(validintlist[(i + rotatenum) % (rotate +num * 2)]); } this.rotate = function(convstring) { var outstring = ""; for (var count = 0; count < convstring.length; count++) { // if it is not in the mappings list, just add it directly + (no rotation) if (this.rotlist[convstring[count]] === undefined) { outstring += convstring[count]; continue; } // otherwise, rotate it and add it to the string outstring += this.rotlist[convstring[count]]; } return outstring; } } module.exports = {rot8000};

Remember

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^2: ROT8000 implementation?
by Anonymous Monk on Oct 16, 2021 at 15:00 UTC
    Obviously he asked before reinventing the wheel.

    Your post adds nothing new to the thread, or do you want to show us your implementation?

      «…show us your implementation?»

      Why should I? The OP himself linked to an implementation. If this implementation is good or valid or what ever you like is another question. And it is a good and common practice to port some algorithm from one language to another. See Rosetta Code for some examples.

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found