I've been trying to figure this out since jeffa posted this, as I find the topic interesting. I couldn't see how this accomplished its compression, but it seemed to work with a very long word. I had to puzzle over it quite a bit and add print statements to figure out how it worked.

$ perl code3.pl string is Rumpelstiltskinrumpelstiltskindisestablishmentarianism Camel + Camel The the T t Tt he h e he e code is Gzv code is rQ code is Z9z code is FMp code is Urm code is kCd code is oC2 code is 71G code is Xyy code is 912 code is 4Ja code is BHX code is Ats code is syv code is iRP code is Lwn default is Rumpelstiltskinrumpelstiltskindisestablishmentarianism default is Camel default is Camel default is The default is the default is T default is t default is Tt default is he default is h default is e default is he default is e Gzv Z9z Z9z FMp Urm kCd oC2 71G BHX 912 Ats BHX Ats Rumpelstiltskinrumpelstiltskindisestablishmentarianism Camel Camel The + the T t Tt he h e he e $VAR1 = { 'e' => 'Ats', 'the' => 'Urm', 'Camel' => 'Z9z', 'T' => 'kCd', 'he' => 'BHX', 'Rumpelstiltskinrumpelstiltskindisestablishmentarianism' => +'Gzv', 'h' => '912', 'The' => 'FMp', 't' => 'oC2', 'Tt' => '71G' }; $

One sees that the first random values in the code array become the keys of the encode hash. I was hoping to actually accomplish some of the functionality that OP had hinted at, so I created some apparatus for saving to file as well:

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use List::Util qw( shuffle ); use v5.12; use File::Slurp; use Path::Class; my $str = shift || 'Rumpelstiltskinrumpelstiltskindisestablishmentaria +nism Camel Camel The the T t Tt he h e he e'; say "string is $str"; my( @codes, %encode ); my @base = ('a' .. 'z', 'A' .. 'Z', 0 .. 9); for my $i (@base) { push @codes, $i; for my $j (@base) { push @codes, "$i$j"; for my $k (@base) { push @codes, "$i$j$k"; } } } @codes = shuffle @codes; # write to file my $path = '/home/twain/Desktop'; my $file = 'code1.txt'; my $code_sheet = file($path,$file); write_file( $code_sheet, "@codes \n" ) ; for my $i (0..15) { say "code is $codes[$i]"; } for (split /\s+/, $str) { say "default is $_"; $encode{$_} = shift @codes; } $str =~ s/([A-Za-z0-9.]+)/$encode{$1}/eg; print $str,$/; my %decodes = reverse %encode; $str =~ s/(\w+)/$decodes{$1}/eg; print $str,$/; my $refhash = \%encode; print Dumper $refhash; __END__ =head1 NAME non-formula-based-text-encoder-with-compression.pl =head1 DESCRIPTION =over 4 =item * Create 242,234 unique codes, 1-3 characters in length, from th +e characters {a-zA-Z0-9}. =item * 62 (1 char codes) + 3844 (2 char codes) + 238,328 (3 char code +s) = 242,234 unique codes. =item * (Somewhat like MIMEbase64 encoding, but my encoding is non-for +mula based.) =item * codesheet to be saved for look-up =back =cut

I see this at a dead-end now, and the compression I thought I was seeing was actually just that the randomly-generated keys were smaller than the values of a hash. It was fun to play with, and I thank jeffa for writing it. I finally figured out how to display the program description:

sudo apt-get install perl-doc perldoc code3.pl

Q1) What are good perl tools for crytography of one's sensitive data?


In reply to Re^4: Non-Formula based Text Encoding - with Compression by Aldebaran
in thread Non-Formula based Text Encoding - with Compression by locked_user erichansen1836

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.