36) $numDisc = 36; if (!isset($ruote)) $dbRuote = 'Jefferson'; else if ($ruote == 'M') { $dbRuote = 'Mauborgne'; // $numDisc = 26; } else if ($ruote == 'J') $dbRuote = 'Jefferson'; if (!isset($shift)) $shift = 5; if ($shift < 0) $shift += $alfLen; if (!isset($chiaro)) $chiaro = 'THOMASJEFFERSONSWHEEL'; $nulle = array('X', 'Y', 'K', 'W', 'J'); while (strlen($chiaro)%$numDisc <> 0){ $chiaro .= $nulle[floor(rand(0,4))]; } $im = @imagecreate($wi, $hi); $back_color = imagecolorallocate($im, 0xFF, 0xFf, 0xFf); $text_color = imagecolorallocate($im, 0x20, 0x20, 0xa0); $line_color = imagecolorallocate($im, 0x30, 0x80, 0xa0); $green_color = imagecolorallocate($im, 0x10, 0xb0, 0x10); $box_color = imagecolorallocate($im, 0xF0, 0x00, 0x00); $fontB = '/var/www/html/fonts/dejavu/DejaVuSansMono-Bold.ttf'; $fontM = '/var/www/html/fonts/dejavu/DejaVuSansMono.ttf'; $font = '/var/www/html/fonts/dejavu/DejaVuSans.ttf'; $fontC = '/var/www/html/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf'; function Riga($n, $chiaro){ global $Alfabeti; global $numDisc; global $alfLen; $riga = ''; for ($col= 0; $col < $numDisc; $col++){ $alfabeto = $Alfabeti[$col]; $cPos = strpos($alfabeto, $chiaro[$col]); if ($cPos === false) $cPos = 0; $pos = ($n + $cPos) % $alfLen; $riga .= $alfabeto[$pos]; } return $riga; } imagerectangle($im, 0, 0, $wi-1, $hi-1, $box_color); $conn = mysql_connect(HOST, CRITTO_USER, CRITTO_PWD) or die('Connessione rifiutata'); $sqlcom = "SELECT indice, alfabeto FROM critto.$dbRuote"; $risult = mysql_query($sqlcom); $Alfabeti = array(); $conta = 0; while ($riga = mysql_fetch_row($risult)) { $Alfabeti[$conta] = $riga[1]; ++$conta; } $numAlfa = $conta; while ($numDisc > $conta) { $Alfabeti[$conta] = $Alfabeti[$conta % $numAlfa]; ++$conta; } mysql_close($conn); $xp0 = 20; $row0 = 36; $xp = $xp0; $row = $row0; $chE = $shift; if($chE < 0) $chE += $alfLen; $rowE = 24+$chE*14; imageline($im, $xp0, $row0-12, $xp+($numDisc+2)*16, $row0-12, $text_color); imageline($im, $xp0, $row0+2, $xp+($numDisc+2)*16, $row0+2, $text_color); imageline($im, $xp0, $rowE, $xp+($numDisc+2)*16, $rowE, $box_color); $rowE += 14; imageline($im, $xp0, $rowE, $xp+($numDisc+2)*16, $rowE, $box_color); // imagettftext($im, 10, 0, $xp, $row-10, $text_color, $fontB, $chiaro); for ($ch= 0; $ch < $alfLen; $ch++){ if ($ch == $chE) $colore = $box_color; else $colore = $text_color; imagettftext($im, 10, 0, $xp, $row, $colore, $fontB, sprintf("%2u", $ch)); $row += 14; } $xp += 20; for ($col= 0; $col < $numDisc; $col++){ $alfabeto = $Alfabeti[$col]; $xp += 16; $row = 18; imagettftext($im, 9, 0, $xp-2, $row, $colore, $font, "$col"); $cPos = strpos($alfabeto, $chiaro[$col]); if ($cPos === false) $cPos = 0; // $cPos = 0; $row += 18; for ($ch= 0; $ch < $alfLen; $ch++) { if ($ch == $chE) {$colore = $box_color; } else $colore = $text_color; $aCh = $ch + $cPos; if ($aCh > 25) $aCh -= $alfLen; imagettftext($im, 10, 0, $xp, $row, $colore, $fontB, $alfabeto[$aCh]); // imagettftext($im, 10, 0, $xp, $row, $colore, $fontB, $alfabeto[$ch]); $row += 14; } imageline($im, $xp-4, 4, $xp-4, $row-12, $box_color); } imageline($im, $xp+12, 20, $xp+12, $row-12, $box_color); $xp += 20; imagettftext($im, 10, 0, $xp, 36+$chE*14, $text_color, $fontC, "← Cifrato → "); imagettftext($im, 10, 0, $xp+ 80, 36+$chE*14, $text_color, $fontM, Riga($shift, $chiaro)); imagettftext($im, 10, 0, $xp, 36, $text_color, $fontC, "← Chiaro → "); imagettftext($im, 10, 0, $xp+ 80, 36, $text_color, $fontM, Riga(0, $chiaro)); imagepng($im); imagecolordeallocate($im, $line_color); imagecolordeallocate($im, $text_color); imagecolordeallocate($im, $box_color); imagecolordeallocate($im, $back_color); imagecolordeallocate($im, $green_color); imagedestroy($im); ?>