Hallo fellow monks,
I'm working on a De/Coder which can compress 365766! (in factorial) bytes into 9.5Mb of TXT or 1.7Mb of ZIP.
The compression (that has been tested so far limits the INPUT length to 60961 bytes); though the OUTPUT is twisted...
Laught as much as you want, but i took the Torah {encoding: Hebrew(windows-1255)} which length is 304805 letters what's strange that this huge number equals only to 60961*5 and doesn't devide by 15,25,35,etc.
I entered the Torah into a hash which contains the following about each letter : ord(Letter), Original_id, Current_id, my_gimatria_value <=> (ord(letter) -224), colour according to the book( one of five), place in the "pipe of letters", is_occupied. Afterwards i read input into the "pipe" by the only 3 rules( yet) that the current_id changes(as if there's a hole in the "pipe") to counter(from 0) multiplied on 6 AND is_occupie = true AND place = 6 , when finished, it remembers the state in which the torah is twisted into a file names filename.tX.
The decoder is the problemetic part although it should be the reverse of the encoder which means rewriting the Coder "backwars".
Here's my code :

#!/usr/bin/perl -w use strict; #Digest::MD5 qw(md5 md5_hex md5_base64) #use FreezeThaw qw(cmpStr); my %letters = (); my %bu_lett = (); my %retrive_lett = (); my ($bu_data, $data) = HoH(); my $last = 0; #enc(); #denc(); denc(enc()); # Encrypt a file sub enc { #print "Enter file's full PATH :\n"; #my $file = readline(*STDIN); #chomp $file; my $file = 'text.tmp'; my $tm1 = time(); my $cc = 0; my $tmpR = 0; my $leftover = ''; open (DAT, "$file") || die "$!\n"; while (<DAT>) { seek(DAT, $cc, 0); read(DAT, $tmpR, 1); $tmpR = sprintf("%02x", ord($tmpR)); my @lets = split(//, $tmpR); $data = process($lets[0]); $data = process($lets[1]); print hex($lets[1].$lets[0])." KEY\n"; $cc++; } close(DAT); $file .= '.tX'; open (DATA, ">$file") || die "$!\n"; my @let2; my $lt2C = 8; my ($lp,$oidp,$idp,$Np,$clrp,$dissp,$occp,$plcp); for (my $jk=0; $jk<304805; $jk++) { $lp = $data->{ $jk }->{ 'letter' }; $oidp = $data->{ $jk }->{ 'original_id' }; $idp = $data->{ $jk }->{ 'id' }; $Np = $data->{ $jk }->{ 'N' }; $clrp = $data->{ $jk }->{ 'colour' }; # $dissp = $data->{ $jk }->{ 'distance' }; $occp = $data->{ $jk }->{ 'occupied' }; $plcp = $data->{ $jk }->{ 'place' }; print DATA "$lp:$oidp:$idp:$Np:$clrp:$occp:$plcp;\n"; } close(DATA); my $tm2 = time(); print "It took ".(int(($tm2-$tm1)/3600)).':'.(int((($tm2-$tm1) % 3 +600)/60)).'.'.(int(($tm2-$tm1) % 60))."\n"; return $file; } # Recreate the 'a' file from the given "dynamic co-ordinates" sub denc { #print "Enter file's full PATH :\n"; #my $file = readline(*STDIN); #chomp $file; my ($INfile) = @_; #print "\tFile $INfile\n"; my $tm1 = time(); my $cc = 0; my $tmpR = 0; my $leftover = ''; open (DAT, "$INfile") || die "$!\n"; my @aTd = <DAT>; close(DAT); @aTd = split(/\n/, "@aTd"); foreach (@aTd) { $_ =~ s/\;//; $_ =~ s/\s//g; my @tSplt = split(/:/, "$_"); #print "$_\n\t$tSplt[0]\n\t $tSplt[4]\n\t $tSplt[6]\n"; #print "$_\n"; $retrive_lett{ $cc }{ 'letter' } = $tSplt[0]; $retrive_lett{ $cc }{ 'original_id' } = $tSplt[1]; $retrive_lett{ $cc }{ 'id' } = $tSplt[2]; $retrive_lett{ $cc }{ 'N' } = $tSplt[3]; $retrive_lett{ $cc }{ 'colour' } = $tSplt[4]; # $retrive_lett{ $cc }{ 'distance' } = $tSplt[5]; $retrive_lett{ $cc }{ 'occupied' } = $tSplt[5]; $retrive_lett{ $cc }{ 'place' } = $tSplt[6]; $cc++; } #print "\tTest ".($retrive_lett{2}{'place'})."\n"; #print "\tTest ".($bu_lett{2}{'place'})."\n"; reprocess($INfile); my $tm2 = time(); print "It took ".(int(($tm2-$tm1)/3600)).':'.(int((($tm2-$tm1) % 3 +600)/60)).'.'.(int(($tm2-$tm1) % 60))."\n"; } # Create the Main Torah Hash_Of_Hashes sub HoH { my @colours = ('red','blue','yellow','green','white'); my @l_N = ('78064','141593','186383','249913','304805'); my $c = 0; my $clc = 0; my $p_v = 12; my $v = -1; my $Tfile = 'torah.cod'; my $letter = ''; open( TORAH, "$Tfile" ) or die "Can't open $Tfile : $!"; my @aT = <TORAH>; @aT = split(//, "@aT"); close(TORAH); my $N = 0; my $xC = 1; my $val = -1; while ($N ne 304805) { $val = ord($aT[$N]) -224; $bu_lett{ $N }{ 'letter' } = $val +224; $bu_lett{ $N }{ 'original_id' } = $N; $bu_lett{ $N }{ 'id' } = $N; $letters{ $N }{ 'N' } = $val; $letters{ $N }{ 'letter' } = $val +224; $letters{ $N }{ 'original_id' } = $N; $letters{ $N }{ 'id' } = $N; $letters{ $N }{ 'N' } = $val; if ($N eq $l_N[$clc]) {$clc++;} $bu_lett{ $N }{ 'colour' } = $colours[$clc]; # $bu_lett{ $N }{ 'distance' } = 22- $p_v + $val; $bu_lett{ $N }{ 'occupied' } = 'no'; $bu_lett{ $N }{ 'place' } = $xC; $letters{ $N }{ 'colour' } = $colours[$clc]; # $letters{ $N }{ 'distance' } = 22- $p_v + $val; $letters{ $N }{ 'occupied' } = 'no'; $letters{ $N }{ 'place' } = $xC; $xC++; if ($xC eq 6) {$xC = 1;} $p_v = $val; $N++; } #print "\n\t ^1^".%letters." -- ".\%letters."\n\t ^2^ ".%bu_lett." -- +".\%bu_lett."\n"; return \%bu_lett, \%letters; } # Process each byte of the 'a' file sub process { my ($key) =@_; $key = hex($key); #print "*** $key\n"; if ($key eq 10) {$key=11;} if ($key eq 11) {$key=12;} if ($key eq 12) {$key=14;} if ($key eq 13) {$key=16;} if ($key eq 14) {$key=17;} if ($key eq 15) {$key=18;} my $flag = 0; my $inC = 0; while (($inC < 304805) && (!$flag)) { if (($data->{$inC}->{'N'} eq $key) && ($data->{$inC}->{'occupi +ed'} eq 'no')) { if (( $data->{ $inC }->{ 'id' }) && ($data->{ $inC }->{ 'p +lace' } eq 6)) { print "/t/t Round $last\r"; my $inCc = 0; my $qid = 0; while ($inCc < 304805) { if ($data->{$inCc}->{'occupied'} eq 'yes') { if ($data->{$inCc}->{'id'} > $qid) {$qid = $da +ta->{$inCc}->{'id'}} } $inCc++; } $letters{ $qid }{ 'id' } = $qid; $letters{ $qid }{ 'occupied' } = 'no'; $letters{ $qid }{ 'place' } = $data->{ $qid }->{ 'plac +e' }; $letters{ $inC }{ 'id' } = $last * 6 -1; $letters{ $inC }{ 'occupied' } = 'yes'; $letters{ $inC }{ 'place' } = 6; $flag = 2; } else {$flag = 1;} if ($flag eq 1) { $letters{ $inC }{ 'id' } = $last * 6 -1; $letters{ $inC }{ 'occupied' } = 'yes'; $letters{ $inC }{ 'place' } = 6; } } $inC++; } $last++; if ($last eq 60961) {$last=0;} return \%letters; } # Return the 'a' file sub reprocess { my ($tINfile) =@_; my $flag = 1; ## my $inC = 0; $tINfile =~ s/.tX//; open (DATA, ">$tINfile") || die "$!\n"; my @let2; my $lt2C = 0; #print "\n\t ^3^".%retrive_lett." - ".\%retrive_lett."\n\t ^4^ ".%bu_l +ett." - ".$bu_data."\n"; # while (cmpStr(\%retrive_lett, \%bu_lett)) { my $qid = (($last-1) % 60961) *6 -1; my $INqid = 0; # my $qid = 6; while ($inC < $last) { #print "\n^^ $qid\n"; # print "$inC - $last ; / ".($retrive_lett{$inC}{'N'})."\r"; #print "\t\t Round $last\n"; if ($retrive_lett{ $retrive_lett{$qid}{'original_id'} }{'occup +ied'} eq 'no') { print "\tin the first\n"; $retrive_lett{ $qid }{ 'id' } = $retrive_lett{$qid}{'or +iginal_id'}; $retrive_lett{ $qid }{ 'occupied' } = 'no'; $retrive_lett{ $qid }{ 'place' } = $retrive_lett{ $retrive +_lett{$qid}{'original_id'} }{ 'place' } +1; } else { print "\tin the second\n"; my $inCc = 0; $INqid = $retrive_lett{$inCc}{'id'}; while ($inCc < 304805) { if ($retrive_lett{$inCc}{'occupied'} eq 'yes') { if ($retrive_lett{$inCc}{'id'} < $INqid) {$INqi +d = $retrive_lett{$inCc}{'id'}} } $inCc++; } #print "^8^ $qid\n"; $retrive_lett{ $INqid }{ 'id' } = $retrive_lett{$qid}{' +id'}; $retrive_lett{ $INqid }{ 'occupied' } = 'yes'; $retrive_lett{ $INqid }{ 'place' } = 6; $retrive_lett{ $qid }{ 'id' } = $retrive_lett{$qid}{'or +iginal_id'}; $retrive_lett{ $qid }{ 'occupied' } = 'no'; $retrive_lett{ $qid }{ 'place' } = $retrive_lett{ $qid }{ +'place' } +1; # $flag = 1; } my $key = $retrive_lett{$qid}{'N'}; #print "*** $key\n"; if ($key eq 11) {$key='A';} if ($key eq 12) {$key='B';} if ($key eq 14) {$key='C';} if ($key eq 16) {$key='D';} if ($key eq 17) {$key='E';} if ($key eq 18) {$key='F';} if ($lt2C eq 0) { $let2[$lt2C]=$key; $lt2C++; } elsif ($lt2C eq 1) { $let2[$lt2C]=$key; $key = hex($let2[1].$let2[0]); if ($key<256) {print DATA chr($key);} print "$key KEY\n"; $lt2C=0; } $qid-=6; $inC++; # if ($inC eq 0) {$inC = 304804;} ## if (($inC % 5) eq 0) { ## $last--; ## if ($last eq 0) {$last=60961;} ## } } close(DATA); return; }


most of the comments are for testing the STDIN/OUT.

p.s.: the "pipe" is a 5 cornered star shaped tunel of letters where on the pics of the start the letters are shifted and in the center the are being written.

In reply to Hash confusion ?! by thenetfreaker

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.