Perl en Español

  1. Home
  2. Tutoriales
  3. Foro
  4. Artículos
  5. Donativos
  6. Publicidad
 
Índice general » Mundo Perl » Avanzado » Error en líneas 23 y 30 ... Responder al tema
Nuevo tema


Página 1 de 1  [ 5 mensajes ] 
 
Nota 2009-11-05 17:13 @759

Perlero Nuevo
Registrado: 2009-11-05 17:06 @754
Mensajes: 3
Error en líneas 23 y 30 ...
Tengo el siguiente problema... de este código fuente... he ido a compilarlo y me saltó el siguiente mensaje:

Syntax: [ Download ] [ Hide ]
Using text Syntax Highlighting
sintax error at xxxx.pl line 23, near "=)"
sintax error at xxxx.pl line 30, near "}"


El típico error de sintaxis... aquí está el script...


Syntax: [ Download ] [ Hide ]
Using perl Syntax Highlighting
  1. # For BIND9 v9.2.3-9.4.1:
  2. $tap1=0x80000057;
  3. $tap2=0x80000062;
  4.  
  5. # For BIND9 v9.0.0-9.2.2:
  6. # $tap1=0xc000002b; # (0x80000057>>1)|(1<<31)
  7. # $tap2=0xc0000061; # (0x800000c2>>1)|(1<<31)
  8.  
  9. $initial_guess_bits=6;
  10. @cand_lfsr1=();
  11. @cand_lfsr2=();
  12.  
  13. use Time::HiRes qw(gettimeofday);
  14.  
  15. @txid=();
  16.  
  17. # Read all data from file. It is assumed to be in the format generated
  18. # by the XSL transformation described in appendix A.
  19.  
  20. $count=0;
  21. open(FD,$ARGV[0]) or die "ERROR: Can't open file $ARGV[0]";
  22. while(my $line=)
  23. {
  24.         # File format: TXID[4 hex] (ignore everything beyond those 4 digits)
  25.        
  26.         if ($line=~/^([0-9a-fA-F]{4})/x)
  27.         {
  28.                 push @txid,hex($1);
  29.                 $count++;
  30.         }
  31.         else
  32.         {
  33.                 die "ERROR: Can't parse line at count=$count.\n";
  34.         }
  35. }
  36. close(FD);
  37.  
  38. print "INFO: Found $count DNS queries in file.\n";
  39.  
  40. sub next_trxid
  41. {
  42.         my ($lfsr1,$lfsr2)=@_;
  43.         my $val;
  44.         for (my $i=0;$i<$count+1;$i++)
  45.         {
  46.                 $val=($lfsr1^$lfsr2) & 0xFFFF;
  47.                 $skip1=$lfsr1 & 1;
  48.                 $skip2=$lfsr2 & 1;
  49.                 for (my $j1=0;$j1<=$skip2;$j1++)               
  50.                 {
  51.                         $lfsr1 = ($lfsr1>>1) ^ (($lfsr1 & 1)*$tap1);
  52.                 }
  53.                 for (my $j2=0;$j2<=$skip1;$j2++)               
  54.                 {
  55.                         $lfsr2 = ($lfsr2>>1) ^ (($lfsr2 & 1)*$tap2);
  56.                 }
  57.                 #printf "%04x ",$val;
  58.         }
  59.         return $val;
  60. }
  61.  
  62. sub verify
  63. {
  64.         my ($lfsr1,$width1,$lfsr2,$width2)=@_;
  65.  
  66.         for (my $i=0;$i<$count;$i++)
  67.         {
  68.                 my $cand=($lfsr1^$lfsr2) & 0xFFFF;
  69.                 my $min_width=($width1<=$width2) ? $width1 : $width2;
  70.                 $min_width=($min_width<=16) ? $min_width : 16;
  71.                 if ($min_width<=0)
  72.                 {
  73.                         return 1;
  74.                 }
  75.                 my $mask=(1<<$min_width)-1;
  76.                 if (($cand & $mask) != ($txid[$i] & $mask))
  77.                 {
  78.                         return 0;
  79.                 }
  80.  
  81.                 $skip1=$lfsr1 & 1;
  82.                 $skip2=$lfsr2 & 1;
  83.                 for (my $j1=0;$j1<=$skip2;$j1++)               
  84.                 {
  85.                         $lfsr1 = ($lfsr1>>1) ^ (($lfsr1 & 1)*$tap1);
  86.                         if ($width1<32)
  87.                         {
  88.                                 $width1--;
  89.                         }
  90.                 }
  91.                 for (my $j2=0;$j2<=$skip1;$j2++)               
  92.                 {
  93.                         $lfsr2 = ($lfsr2>>1) ^ (($lfsr2 & 1)*$tap2);
  94.                         if ($width2<32)
  95.                         {
  96.                                 $width2--;
  97.                         }
  98.                 }
  99.         }
  100.         return 1;
  101. }
  102.  
  103. sub phase2
  104. {
  105.         my ($lfsr1,$width1,$lfsr2,$width2)=@_;
  106.  
  107.         my $motion_detected=0;
  108.  
  109.         if ($width1<32)
  110.         {
  111.                 my $guess_0=verify($lfsr1|(0<<$width1),$width1+1,$lfsr2,$width2);
  112.                 my $guess_1=verify($lfsr1|(1<<$width1),$width1+1,$lfsr2,$width2);
  113.                 if ($guess_0 ^ $guess_1)
  114.                 {
  115.                         #Exactly one is correct. So we know the bit.
  116.                         $motion_detected=1;
  117.                         if ($guess_1)
  118.                         {
  119.                                 $lfsr1=$lfsr1|(1<<$width1);
  120.                         }
  121.                         $width1++;
  122.                 }
  123.                 elsif ((!$guess_0) and (!$guess_1))
  124.                 {
  125.                         # Inconsistent state, hence wrong guess in the first place
  126.                         return 0;
  127.                 }
  128.         }
  129.  
  130.         if ($width2<32)
  131.         {
  132.                 my $guess_0=verify($lfsr1,$width1,$lfsr2|(0<<$width2),$width2+1);
  133.                 my $guess_1=verify($lfsr1,$width1,$lfsr2|(1<<$width2),$width2+1);
  134.                 if ($guess_0 ^ $guess_1)
  135.                 {
  136.                         #Exactly one is correct. So we know the bit.
  137.                         $motion_detected=1;
  138.                         if ($guess_1)
  139.                         {
  140.                                 $lfsr2=$lfsr2|(1<<$width2);
  141.                         }
  142.                         $width2++;
  143.                 }
  144.                 elsif ((!$guess_0) and (!$guess_1))
  145.                 {
  146.                         # Inconsistent state, hence wrong guess in the first place
  147.                         return 0;
  148.                 }
  149.         }
  150.  
  151.         if (($width1==32) and ($width2==32))
  152.         {
  153.                 # Final verification
  154.                 if (verify($lfsr1,32,$lfsr2,32))
  155.                 {
  156.                         push @cand_lfsr1,$lfsr1;
  157.                         push @cand_lfsr2,$lfsr2;
  158.                         return 1;
  159.                 }
  160.                 else
  161.                 {
  162.                         # false alarm
  163.                         return 0;
  164.                 }
  165.         }
  166.  
  167.         if ($motion_detected)
  168.         {
  169.                 # At least one width was improved.
  170.                 return phase2($lfsr1,$width1,$lfsr2,$width2);
  171.         }
  172.         else
  173.         {
  174.                 # Resort to bit guessing.
  175.                 if ($width1<32)
  176.                 {
  177.                         # Guessing another bit in LFSR1 and continuing...
  178.                         return
  179. phase2($lfsr1|(0<<$width1),$width1+1,$lfsr2,$width2)+
  180.                                 phase2($lfsr1|(1<<$width1),$width1+1,$lfsr2,$width2);
  181.                 }
  182.                 else
  183.                 {
  184.                         # Guessing another bit in LFSR2 and continuing...
  185.                         return
  186. phase2($lfsr1,$width1,$lfsr2|(0<<$width2),$width2+1)+
  187.                                 phase2($lfsr1,$width1,$lfsr2|(1<<$width2),$width2+1);
  188.                 }              
  189.         }
  190. }
  191.  
  192. my $start_time=gettimeofday();
  193.  
  194. my $good=0;
  195.  
  196. for (my $lfsr1=0;$lfsr1<(1<<$initial_guess_bits);$lfsr1++)
  197. {
  198.         my $lfsr2=($txid[0]^$lfsr1) & ((1<<$initial_guess_bits)-1);
  199.         if (verify($lfsr1,$initial_guess_bits,$lfsr2,$initial_guess_bits))
  200.         {
  201.                 $good+=
  202. phase2($lfsr1,$initial_guess_bits,$lfsr2,$initial_guess_bits);
  203.         }
  204. }
  205.  
  206. my $end_time=gettimeofday();
  207.  
  208. print "INFO: ".$good." candidates found:\n";
  209. for (my $k=0;$k<$good;$k++)
  210. {
  211.         printf "***  LFSR1=0x%08x  LFSR2=0x%08x  Next_TRXID=0x%04x  ***\n",
  212.                 $cand_lfsr1[$k],$cand_lfsr2[$k],
  213. next_trxid($cand_lfsr1[$k],$cand_lfsr2[$k]);
  214. }
  215.  
  216. print "INFO: Elapsed time: ".($end_time-$start_time)." seconds\n";
  217.  
  218. exit(0);


Si alguien puede corregirlo o al menos darme una idea se lo agradecería...

Gracias de antemano... :)


Nota 2009-11-05 18:02 @793
Avatar de Usuario
Administrador
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España
Mensajes: 10250
Re: Error en Líneas 23 y 30 ...
Bienvenido a los foros de Perl en Español, crakjerhz.

La línea 22, en vez de

while(my $line=)

debería ser

while(my $line=<FD>)

Parece que lo has copiado de una página web, y claro, <FD> no es una marca reconocida en HTML. El autor de la página no ha escapado bien el código fuente.


Nota 2009-11-06 03:15 @177

Perlero Nuevo
Registrado: 2009-11-05 17:06 @754
Mensajes: 3
Re: Error en líneas 23 y 30 ...
hmmmmmmmmm... cierto... me suponía que podría ser algo de eso... pero, ¿y la línea 30...? no tengo ni idea... :S

Gracias explorer...


Nota 2009-11-06 03:39 @194
Avatar de Usuario
Administrador
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España
Mensajes: 10250
Re: Error en líneas 23 y 30 ...
Tu arregla primero la línea 22 y luego nos cuentas si sale o no error en la línea 30. ;)


Nota 2009-11-06 03:43 @196

Perlero Nuevo
Registrado: 2009-11-05 17:06 @754
Mensajes: 3
Re: Error en líneas 23 y 30 ...
Vaya ahora me parece el siguiente mensaje:

ERROR: Can't open file at xxxx.pl line 21

:cry:


Responder al tema  [ 5 mensajes ] 

Reglas del Foro
No puedes abrir nuevos temas en este Foro
No puedes responder a temas en este Foro
No puedes editar tus mensajes en este Foro
No puedes borrar tus mensajes en este Foro
No puedes enviar adjuntos en este Foro

Publicidad

Socializa

Síguenos por Twitter

Suscríbete GRATUITAMENTE al Boletín de Perl en Español

Saltar a:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Traducción al español por Huan Manwë para phpbb-es.com
phpBB SEO