alfabeto = $alfabeto; if (isset($dim)) $this->dimensione = $dim; if (isset($testo)) $this->testo = $testo; $this->versetto = EliminaEstranee2($versetto, $this->alfabeto); $this->verNumeri = array(); $this->lenTesto = strlen($this->testo); $this->testoBlocchi = ceil($this->lenTesto / $this->dimensione); $maxLen = $this->dimensione*$this->testoBlocchi; if (strlen($this->versetto) > $maxLen) $this->versetto = substr($this->versetto, 0, $maxLen); $gruppo = 0; $this->verBlocchi = str_split($this->versetto, $this->dimensione); foreach ($this->verBlocchi as $blocco){ $numeri = array(); for ($conta = 0; $conta < $this->dimensione; $conta++) $numeri[$conta] = 0; $lenA = strlen($this->alfabeto); $ord = 0; for($alf = 0; $alf <$lenA; $alf++){ $ch = $this->alfabeto[$alf]; $pos = 0; while (true){ $pos = strpos($blocco, $ch, $pos); if ($pos === false) break; else $numeri[$pos]= $ord++; // echo "$ch $ord $pos | "; if ($ord > $this->dimensione) $ord = 0; $pos++; } } for ($ord = 0; $ord < $this->dimensione; $ord++) $this->verNumeri[$gruppo + $ord] = $numeri[$ord]; $gruppo += $this->dimensione; } } function TrasponiAvanti(){ $testo = $this->testo; $testo = EliminaEstranee2($testo, $this->alfabeto); $this->testo = $testo; $lenT = strlen($testo); $this->lenTesto = $lenT; for($conta = 0; $conta < $lenT; $conta++){ $this->trasposto[$conta] = '_'; } $blocchi = ceil($lenT/$this->dimensione); $resto = $lenT % $this->dimensione; $this->verNumeri = array_slice($this->verNumeri, 0, $lenT); // riduce il vettore numeri alla dimensione del testo. $this->verBlocchi = array_slice($this->verBlocchi, 0, $blocchi); $indNum = 0; $resto = $lenT % $this->dimensione; $pos = 0; for ($ord = 0; $ord < $this->dimensione; $ord++){ $posti = array_keys($this->verNumeri, $ord); foreach ($posti as $posto){ $this->trasposto[$posto] = $testo[$pos++]; } } } function TrasponiIndietro($trasposto){ $pulito = EliminaEstranee2($trasposto, $this->alfabeto); $lenT = strlen($pulito); $this->lenTesto = $lenT; $this->trasposto = str_split($pulito); $this->testo = ''; for ($ord = 0; $ord < $this->dimensione; $ord++){ $posti = array_keys($this->verNumeri, $ord); foreach ($posti as $posto){ $this->testo .= $this->trasposto[$posto]; } } } function scriviRegolare($color, $sep){ $testo = $this->testo; if (!isset($sep)) $sep = ' '; $lenT = strlen($testo); $html = $this->SetColor($color); for($ord = 0; $ord < $lenT; $ord++){ $html .= $sep.$testo[$ord]; $sep = $this->NuovaCella(); } $html .= $this->EndColor(); return $html; } function ScriviNumeri(){ $conta = 0; $numeri = $this->PrimaCella(); $sep = ''; foreach ($this->verNumeri as $numero){ $numeri .= $sep.$numero; $conta++; if ($conta >= $this->lenTesto) break; if ($conta % $this->dimensione == 0) $numeri .= $this->NuovaIntesta(); $sep = $this->NuovaCella(); } return $numeri; } function ScriviVersetto(){ $conta = 0; $cifrato = $this->PrimaCella(); $sep = ''; $tab = ''; foreach ($this->verBlocchi as $blocco){ $cifrato .= $tab; for ($ord = 0; $ord < $this->dimensione; $ord++){ if ($conta++ >= $this->lenTesto) break; $cifrato .= $sep.$blocco[$ord]; $sep = $this->NuovaCella(); } $tab = $this->NuovaIntesta(); } return $cifrato; } function GetCifratoPezzi($pezzo){ $cifrato = ''; $pulito = $this->testo; $lenT = strlen($pulito); for($conta = 0; $conta < $lenT; $conta++){ if ($conta % $pezzo == 0) $sep = ' '; else $sep = ''; $ch = $pulito[$conta]; $cifrato .= $sep.$ch; } return $cifrato; } function ScriviTrasposto(){ $ord = 0; $trasposto = $this->PrimaCella(); $sep = ''; $tab = ''; // $this->trasposto = ''; foreach ($this->trasposto as $lettera){ if ($ord % $this->dimensione == 0) $trasposto .= $tab; $trasposto .= $sep.$lettera; // $this->trasposto .= $lettera; $sep = $this->NuovaCella(); $ord++; if ($ord >= $this->lenTesto) break; $tab = $this->NuovaIntesta(); } return $trasposto; } function TraspostoGrezzo(){ $trasp = ''; foreach ($this->trasposto as $lettera){ $trasp .= $lettera; } return $trasp; } function ScriviCifrato(){ $lenT = strlen($this->testo); $tab = ''; $sep = ''; $cifrato = $this->PrimaCella(); for($conta = 0; $conta < $lenT; $conta++){ if ($conta % $this->dimensione == 0) $cifrato .= $tab; $cifrato .= $sep.$this->testo[$conta]; $tab = $this->NuovaIntesta(); $sep = $this->NuovaCella(); } return $cifrato; } function Colonne(){ $lenT = strlen($this->testo); return ceil($lenT/$this->dimensione)+$lenT; } function Scrivi(){ $lenT = strlen($this->testo); $celle = ceil($lenT/$this->dimensione)+$lenT; echo $this->InizioPagina($celle, 'c', null); echo $this->NuovaRiga(null, null).$this->ScriviVersetto().$this->FineRiga(); echo $this->NuovaRiga(null, 'bold').$this->ScriviNumeri().$this->FineRiga(); echo $this->NuovaRiga(null, null).$this->ScriviCifrato().$this->FineRiga();; echo $this->NuovaRiga('red', 'bold').$this->ScriviTrasposto().$this->FineRiga(); echo $this->FinePagina(); } function ScriviIndietro(){ // $lenT = strlen($this->testo); // $celle = ceil($lenT/$this->dimensione)+$lenT; $celle = ($this->dimensione+1)*$this->testoBlocchi; echo $this->InizioPagina($celle, 'c', null); echo $this->NuovaRiga('red', 'bold').$this->ScriviTrasposto().$this->FineRiga(); echo $this->NuovaRiga(null, 'bold').$this->ScriviNumeri().$this->FineRiga();; echo $this->NuovaRiga(null, null).$this->ScriviCifrato().$this->FineRiga();; echo $this->FinePagina(); } function InizioPagina($numcol, $format, $titolo){ return 'prototipo'; } function FinePagina(){ return 'prototipo'; } function NuovaRiga($color, $font){ return ''; } function PrimaCella(){ return 'prototipo'; } function NuovaIntesta(){ return ''; } function NuovaCella(){ return ''; } function VaiSotto($linea){ return 'prototipo'; } function Chiudi(){ return 'proto'; } function SetColor($color){ return ''; } function EndColor(){ return ''; } function Ripulisci($testo){ return strip_tags($testo); } } class TrasponiTestoLatex extends TrasponiTesto{ function InizioPagina($numCol, $format, $titolo){ $Formato = ''; if (!isset($format)) $format = 'c'; if (!isset($numCol)) $numCol = 20; $sep = ''; for($conta=0; $conta<$numCol; $conta++){ $Formato .= $sep.$format; $sep = ''; } if (isset($titolo)) $latex = '$\text{ '.$titolo.'}\\\\'."\n"; else $latex = '$'; $latex .= ' \begin{array}{'.$Formato.'}'."\n"; return $latex; } function FinePagina(){ return '\end{array} $'; } function NuovaRiga($color, $font){ $latex = "\n"; if (isset($color)) $latex .= '\color{'.$color.'}'; if (isset($font)) { if ($font == 'bold') $latex .= ''; } return $latex; } function VaiSotto($linea){ return ''; } function Chiudi(){ return 'proto'; } function FineRiga(){ return '\\\\ '."\n"; } function PrimaCella(){ return ''; } function NuovaCella(){ return ' & '; } function NuovaIntesta(){ return ' & '; } // function Ripulisci($testo){ // return EliminaEstranee($testo, $this->alfabeto); // } function SetColor($color){ return '{\color{'.$color.'}'; } function EndColor(){ return '}'; } } class TrasponiTestoHTML extends TrasponiTesto{ function InizioPagina($numcol, $format, $titolo){ $html = '\n"; } function NuovaRiga($color, $font){ $html = ""; return $html; } function VaiSotto($linea){ return 'prototipo'; } function Chiudi(){ return ''; } function FineRiga(){ return "\n"; } function PrimaCella(){ return ''; } function NuovaCella(){ return ''; } function NuovaIntesta(){ return ''; } function SetColor($color){ return ""; } function EndColor(){ return ""; } } ?>