11 int loadsplitplugin(void) {
16 handle
= dlopen ("./plugin-split-lines.so", RTLD_LAZY
);
18 fputs (dlerror(), stderr
);
22 split
= dlsym(handle
, "split");
23 if ((error
= dlerror()) != NULL
) {
28 printf ("%d\n", (*split
)(1));
29 printf ("%d\n", (*split
)(2));
30 printf ("%d\n", (*split
)(3));
36 unsigned int *hash_loadfile(char *filename
, int *size
) {
37 char *nombre
=filename
, linea
[MAX_LINE
];
39 fichero
= fopen( nombre
, "r" );
42 printf( "Error (NO ABIERTO)\n" );
48 for (lines
=0;fgets(linea
, MAX_LINE
, fichero
); lines
++);
51 unsigned int *data
=malloc(lines
*sizeof(unsigned int*));
53 while (txt
=fgets(linea
, MAX_LINE
, fichero
)) {
55 data
[line
++]=ihash(txt
);
58 if( fclose(fichero
)!=0 ) {
59 printf( "\nError: fichero NO CERRADO\n" );
67 // ihash calcula un hash de 32 bits para un texto.
68 unsigned int ihash(char *txt
) {
69 // Longitud del mensaje a cifrar
70 int msg_len
= strlen( txt
);
72 // Longitud del hash resultante - gcry_md_get_algo_dlen
73 // devuelve la longitud del resumen hash para un algoritmo
74 int hash_len
= gcry_md_get_algo_dlen( HASH_TYPE
);
76 // Salida del hash SHA1 - esto serán datos binarios
77 unsigned char hash
[ hash_len
];
79 // Calcular el resumen SHA1. Esto es una especie de función-atajo,
80 // ya que la mayoría de funciones gcrypt requieren
81 // la creación de un handle, etc.
82 gcry_md_hash_buffer( HASH_TYPE
, hash
, txt
, msg_len
);
84 // unsigned int ihash=*((unsigned int *)hash);
85 return *((unsigned int *)hash
);
89 void reducetext(char * txt
) {
95 char type
=0; // Tipos de palabras o grupos:
96 // a -> texto, variable.
97 // 1 -> números, con, sin decimales.
98 // % -> símbolos unarios, binarios.
99 // 0 -> huecos y espacios
101 for (n
=0;n
<MAX_LINE
;n
++) {
102 c
=tolower(txt
[n
]); // Captura del carácter en minúscula.
104 // Traducción del carácter.
107 // Retonos de carro y fin de fichero: salir de la función.
111 n
=MAX_LINE
; continue;
112 // Tabuladores y espacios: cuentan como espacio.
118 case 'á': c='a'; break;
119 case 'é': c='e'; break;
120 case 'í': c='i'; break;
121 case 'ó': c='o'; break;
122 case 'ú': c='u'; break;
126 switch(type
) // Cambios de tipos según algunos datos.
128 case 0: // Segun si estábamos en un espacio.
129 if (c
>='0' && c
<='9') {
131 } else if (isalpha(c
)) {
135 case '1': // Segun si estábamos en un espacio.
136 if (c
>='0' && c
<='9') {
140 } else if (isalpha(c
)) {
144 case 'a': // Segun si estábamos en un espacio.
145 if (c
>='0' && c
<='9') {
147 } else if (isalpha(c
)) {
156 if (c
>='0' && c
<='9') {
158 } else if (isalpha(c
)) {
164 if (!nn
&& c
==' ') continue; // Si está tabulando al inicio, tampoco tiene efecto.
165 if (c
==lastc
&& (type
=='a' || type
==0)) continue; // Desperdiciar letras repetidas.
167 if (type
=='%' && newline
[nn
-1]==' ') nn
--;
179 int compare2hashvectors(int *Bvector
, int Bsize
, int *Mvector
, int Msize
,
180 int MaxPassSize
, hashblock
*blocks
, int blocksize
)
182 // Bvector: vector of hashes of Base, original or unmodified file.
183 // Mvector: vector of hashes of modified file.
184 // Bsize and Msize: Stores the size of their arrays.
185 // MaxPassSize: (default: 256) Which is the maximum block-size of algorithm
187 int line_base
,line_local
,size
;
188 int maxsize
=1,total
=0;
190 hashblock
*bloque
=blocks
;
193 int conf_pasada
[]={256,128,64,32,16,8,4,2,1,0};
196 for (p
=0;min_bloque
=conf_pasada
[p
];p
++)
198 if (conf_pasada
[p
]>MaxPassSize
) continue;
200 for (i
=0;i
<Bsize
;i
+=maxsize
) {
203 for (j
=0;j
<nbloques
;j
++)
205 if (i
>=bloque
[j
].line1
&& i
<=bloque
[j
].line1
+bloque
[j
].size
) break;
209 i
=bloque
[j
].line1
+bloque
[j
].size
; continue;
213 for (k
=0;k
<Msize
;k
++)
216 for (j
=0;j
<nbloques
;j
++)
218 if (k
>=bloque
[j
].line2
&& k
<=bloque
[j
].line2
+bloque
[j
].size
) break;
222 k
=bloque
[j
].line2
+bloque
[j
].size
; continue;
225 if (Bvector
[i
]==Mvector
[k
])
229 for(m
=0;k
+m
<Msize
&& i
+m
<Bsize
;m
++)
231 for (j
=0;j
<nbloques
;j
++)
233 if (k
+m
>=bloque
[j
].line2
&& k
+m
<=bloque
[j
].line2
+bloque
[j
].size
) break;
234 if (i
+m
>=bloque
[j
].line1
&& i
+m
<=bloque
[j
].line1
+bloque
[j
].size
) break;
236 if (j
<nbloques
) break;
237 if (Bvector
[i
+m
]!=Mvector
[k
+m
])
240 if (nz
>size
/4) break;
265 if (maxsize
>min_bloque
)
267 if (nbloques
<blocksize
)
269 bloque
[nbloques
].line1
=line_base
;
270 bloque
[nbloques
].line2
=line_local
;
271 bloque
[nbloques
].size
=maxsize
;
273 } else printf( "Error: OUT OF BLOCKS. \n");
276 lbb
=line_base
+maxsize
;
286 hashblock auxbloque
[blocksize
];
287 int minline
=0, min_j
=0;
288 for (p
=0;p
<nbloques
;p
++)
291 for (j
=0;j
<64 && j
<nbloques
;j
++)
293 if (bloque
[j
].line1
<minline
)
295 minline
=bloque
[j
].line1
;
299 auxbloque
[p
]=bloque
[min_j
];
300 bloque
[min_j
].line1
=Bsize
;
302 memcpy(bloque
,auxbloque
,blocksize
*sizeof(hashblock
));