Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: ROT8000 implementation?

by Takeshi Kovacs (Beadle)
on Oct 16, 2021 at 16:30 UTC ( [id://11137634]=note: print w/replies, xml ) Need Help??


in reply to ROT8000 implementation?

taking the example from http://rot8000.com/info as testcase

FYI: # $chinese = "籝籱籮 籫籾籽籵籮类 籭籲籭 籲籽簪"

use strict; use warnings; use utf8; use open ":std", ":encoding(UTF-8)"; use Test::More; # rot8000 v1.005; my %rot; init_rot(); my $english = "The butler did it!"; my $chinese = "&#31837;&#31857;&#31854; &#31851;&#31870;&#31869;&#3186 +1;&#31854;&#31867; &#31853;&#31858;&#31853; &#31858;&#31869;&#31786;" +; # fix PerlMonks' Uni<code>Mess $chinese =~ s/&#(\d+);/chr($1)/ge; is( rot8000($chinese), $english, "chin2engl -> $english" ); is( rot8000($english), $chinese, "engl2chin -> $chinese" ); my $random = join "", map { chr int rand 2**16-1 } 1..30; is( rot8000(rot8000($random)), $random, "Identity" ); done_testing; sub rot8000 { my ($in) = @_; my $out; for my $char (split //,$in) { $out .= $rot{$char} // $char; } return $out; } sub init_rot{ my @toggles = reverse (0, 33,127,161,5760,5761,8192,8203,8232,8234 +,8239,8240,8287,8288,12288,12289,55296,57344); my @allowed = map chr, 0.. 2**16-1; while ( my ($stop,$start) = splice @toggles, 0, 2 ) { #say "$start-$stop"; splice @allowed, $start, $stop-$start; } my @allowed_low = splice @allowed, 0, (@allowed/2); @rot{@allowed_low} = @allowed; @rot{@allowed} = @allowed_low; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-16 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found