This is much more advanced than How to randomize letters in a word and Cambridge Transposition because of the rule about which letters may be swapped with which. A simple regex will not suffice here.
It is well known that a text can still be read while the innards of its words have been scrambled, as long as their first and last letters plus their overall outlines remain constant. Given a printable Ascii+Newline text, scramble each word according to these rules:
Scrambling must be (pseudo) random.
A word is a sequence of the Latin characters, A through Z.
Only initial letters will ever be uppercase.
The first and last letters must stay untouched.
When scrambling, only letters within one of the following groups may exchange places:
acemnorsuvwxz
bdfhkl
gpqy
it
j
(stays in place)
Example
Srcmable wrods while psrrnveieg their oeiltnus
It is well known that a txet can still be read while the inrands of its wrods have been srcambled, as long as their fisrt and last letters plus their ovaerll ontliues raemin canstnot. Given a patnirlbe Acsii+Nwnliee txet, samrclbe ecah word anoccdirg to these relus:
Smncrbliag must be (pusedo) rondam.
A wrod is a seqencue of the Latin chreratacs, A thurogh Z.
Only iniital lrttees will eevr be uppcsaere.
The fisrt and lsat lettres must stay uctoenhud.
When sarnclbimg, only letters wihtin one of the fwllnoiog guorps may ecxhange plaecs:
aneusvrowxmcz
bhkfdl
gqpy
it
j
(stays in plcae)Emxaple
t
is supposed to be shorter thanh
although many people do not write it so. \$\endgroup\$t
from group 2? Or maybe puttingt
in a group 4 withi
? \$\endgroup\$printable
/patnirlbe
isn't quite readable. I think thei
/t
swap is to blame. Hmm...paintrlbe
No that didn't help either. It's probably thepr
/pa
swap, then. The outline maintains, but I think that I read "pr" and "pa" as being semantically(?) 1 letter.prtnialbe
Ah yes. That did it. Not sure I can offer a fix to the algorithm though. \$\endgroup\$