Une firme de sécurité lance JAB Code, un nouveau code-barre coloré à « haute capacité »
Soumis pour approbation comme standard ISO

Pour se connecter à l’interface web de WhatsApp, l’application Android requiert de son utilisateur qu’il pointe la caméra de son dispositif mobile sur une espèce de carré sur fond blanc parsemé de modules noirs – un code QR (Quick Response).

Nom : QR-code.png
Affichages : 11987
Taille : 10,6 Ko

Ça, c’est pour la version traditionnelle (l’adjectif est utilisé dans ce contexte pour renvoyer au duo de couleurs noir et blanc) dont on fait usage jusqu’ici dans une panoplie d’autres domaines. Par le biais du site de l’Office allemand de la sécurité des systèmes d’information, Fraunhoher SIT livre ses avancées en la matière. L’institut de recherche propose une version colorée des codes QR ; le projet est connu sous le nom JAB Code (Just Another Bar Code) et publié sur GitHub sous licence publique générale limitée – LGPL 2.1. « JAB est un code matriciel coloré dont les symboles de base sont constitués de modules carrés disposés en grilles rectangulaires ou carrées », lit-on sur l’interface web de démonstration. Ci-dessous, un visuel de JAB Code généré à partir de l’application web fournie par l’entreprise.

Nom : jabcode.png
Affichages : 6371
Taille : 4,0 Ko

Sur le site de l’Office allemand de la sécurité des systèmes d’information, Fraunhofer SIT écrit : « la capacité de stockage des codes-barres monochromatiques 2D est limitée. Dans le but de permettre aux sceaux numériques de sauvegarder des informations additionnelles, le guide technique BSI TR-03137 définit Just Another Bar Code (JAB Code), un code à barres 2D coloré. En s’appuyant sur ces informations de couleur, la capacité de stockage du code à barres est améliorée de façon significative en comparaison à celle d’un code à barres monochrome de même taille. » Dans les chiffres, JAB Code permet un rapport de densité qui va jusqu’à 3x en comparaison au code QR monochrome.

JAB Code n’est pas la première tentative d’introduction d’un code à barres polychrome. Dans cet univers, il fait suite à High Capacity Color Barcode (HCCB) de Microsoft. La firme de Redmond a procédé à son introduction en 2007. En 2015, Clive Hohberger a, après 10 années de recherche, pu obtenir l’introduction d’Ultracode comme spécification AIM. Aucune de ces alternatives aux codes à barres monochromes n’a décollé ; la faute à un manque d’intérêt des industriels alors qu’Ultracode offre une densité de stockage de 2x.

JAB Code a fait l’objet d’une présentation lors de l’édition 2018 de la session plénière du comité ISO / IEC JTC1 SC31 auquel il est désormais soumis pour approbation. Les intervenants de la chaine sont donc en passe de voir atterrir un nouveau standard qu’il convient de connaître. Pour cela, à défaut de parcourir la riche documentation fournie par l’institut de recherche, les développeurs peuvent plonger directement dans le code C de la partie du standard chargée de l’encodage.

Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jabcode.h"
#include "jabwriter.h"
 
jab_data* data = 0;
jab_char* filename = 0;
jab_int32 color_number = 0;
jab_int32 symbol_number = 0;
jab_int32 module_size = 0;
jab_int32	master_symbol_width = 0;
jab_int32 master_symbol_height= 0;
jab_int32* symbol_positions = 0;
jab_int32 symbol_positions_number = 0;
jab_vector2d* 	symbol_versions = 0;
jab_int32 symbol_versions_number = 0;
jab_int32* symbol_ecc_levels = 0;
jab_int32 symbol_ecc_levels_number = 0;
 
void printUsage()
{
    printf("\n");
    printf("jabcodeWriter (Version %s Build date: %s) - Fraunhofer SIT\n\n", VERSION, BUILD_DATE);
    printf("Usage:\n\n");
    printf("jabcodeWriter --input message-to-encode --output output-image(png) [options]\n");
    printf("\n");
    printf("--input\t\t\tInput data (message to be encoded).\n");
    printf("--input-file\t\tInput data file.\n");
    printf("--output\t\tOutput png file.\n");
    printf("--color-number\t\tNumber of colors (2, 4, 8, 16, 32, 64, 128, 256,\n\t\t\t"
							 "default: 8).\n");
    printf("--module-size\t\tModule size in pixel (default: 10 pixels).\n");
    printf("--symbol-width\t\tMaster symbol width in pixel.\n");
    printf("--symbol-height\t\tMaster symbol height in pixel.\n");
    printf("--symbol-number\t\tNumber of symbols (1 - 61, default: 1).\n");
 
    printf("--ecc-level\t\tError correction levels (0 - 10, default: 8%%). If\n\t\t\t"
                  "different for each symbol, starting from master and\n\t\t\t"
		  "then slave symbols (ecc0 ecc1 ecc2 ...). For master\n\t\t\t"
		  "symbol, level 0 means using the default level, for\n\t\t\t"
		  "slaves, it means using the same level as its host.\n");
 
    printf("--symbol-version\tSide-Version of each symbol, starting from master and\n\t\t\t"
		  "then slave symbols (x0 y0 x1 y1 x2 y2 ...).\n");
 
    printf("--symbol-position\tSymbol positions (0 - 60), starting from master and\n\t\t\t"
		  "then slave symbols (p0 p1 p2 ...). Only required for\n\t\t\t"
		  "multi-symbol code.\n");
 
    printf("--help\t\t\tPrint this help.\n");
    printf("\n");
    printf("Example for 1-symbol-code: \n");
    printf("jabcodeWriter --input 'Hello world' --output test.png\n");
    printf("\n");
    printf("Example for 3-symbol-code: \n" );
    printf("jabcodeWriter --input 'Hello world' --output test.png --symbol-number 3 
                                       --symbol-position 0 3 2 --symbol-version 3 2 4 2 3 2\n");
    printf("\n");
}
 
jab_boolean parseCommandLineParameters(jab_int32 para_number, jab_char* para[])
{
	//first scan
	for (jab_int32 loop=1; loop<para_number; loop++)
	{
		if (0 == strcmp(para[loop],"--input"))
        {
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", para[loop]);
				return 0;
			}
            jab_char* data_string = para[++loop];
            data = (jab_data *)malloc(sizeof(jab_data) + strlen(data_string) * sizeof(jab_char));
            if(!data)
            {
                reportError("Memory allocation for input data failed");
                return 0;
            }
			data->length = strlen(data_string);
			memcpy(data->data, data_string, strlen(data_string));
        }
        else if (0 == strcmp(para[loop],"--input-file"))
        {
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", para[loop]);
				return 0;
			}
            FILE* fp = fopen(para[++loop], "rb");
            if(!fp)
            {
				reportError("Opening input data file failed");
                return 0;
            }
			jab_int32 file_size;
			fseek(fp, 0, SEEK_END);
			file_size = ftell(fp);
            data = (jab_data *)malloc(sizeof(jab_data) + file_size * sizeof(jab_char));
            if(!data)
            {
                reportError("Memory allocation for input data failed");
                return 0;
            }
            fseek(fp, 0, SEEK_SET);
            if(fread(data->data, 1, file_size, fp) != file_size)
            {
				reportError("Reading input data file failed");
				free(data);
				fclose(fp);
				return 0;
			}
			fclose(fp);
			data->length = file_size;
        }
		else if (0 == strcmp(para[loop],"--output"))
        {
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", para[loop]);
				return 0;
			}
            filename = para[++loop];
        }
        else if (0 == strcmp(para[loop],"--color-number"))
        {
			char* option = para[loop];
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", option);
				return 0;
			}
            char* endptr;
			color_number = strtol(para[++loop], &endptr, 10);
			if(*endptr)
			{
				printf("Invalid or missing values for option '%s'.\n", option);
				return 0;
			}
            if(color_number != 2  && color_number != 4  && color_number != 8   && color_number != 16 &&
			   color_number != 32 && color_number != 64 && color_number != 128 && color_number != 256)
            {
				reportError("Invalid color number. Valid color number includes 2, 4, 8, 16, 32, 64, 128 and 256.");
				return 0;
            }
        }
        else if (0 == strcmp(para[loop],"--module-size"))
        {
			char* option = para[loop];
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", option);
				return 0;
			}
            char* endptr;
			module_size = strtol(para[++loop], &endptr, 10);
			if(*endptr || module_size < 0)
			{
				printf("Invalid or missing values for option '%s'.\n", option);
				return 0;
			}
        }
        else if (0 == strcmp(para[loop],"--symbol-width"))
        {
			char* option = para[loop];
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", option);
				return 0;
			}
            char* endptr;
			master_symbol_width = strtol(para[++loop], &endptr, 10);
			if(*endptr || master_symbol_width < 0)
			{
				printf("Invalid or missing values for option '%s'.\n", option);
				return 0;
			}
        }
        else if (0 == strcmp(para[loop],"--symbol-height"))
        {
			char* option = para[loop];
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", option);
				return 0;
			}
            char* endptr;
			master_symbol_height = strtol(para[++loop], &endptr, 10);
			if(*endptr || master_symbol_height < 0)
			{
				printf("Invalid or missing values for option '%s'.\n", option);
				return 0;
			}
        }
        else if (0 == strcmp(para[loop],"--symbol-number"))
        {
			char* option = para[loop];
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", option);
                return 0;
			}
			char* endptr;
			symbol_number = strtol(para[++loop], &endptr, 10);
            if(*endptr)
			{
				printf("Invalid or missing values for option '%s'.\n", option);
				return 0;
			}
            if(symbol_number < 1 || symbol_number > MAX_SYMBOL_NUMBER)
            {
				reportError("Invalid symbol number (must be 1 - 61).");
				return 0;
            }
        }
	}
 
	//check input
    if(!data)
    {
		reportError("Input data missing");
		return 0;
    }
    else if(data->length == 0)
    {
		reportError("Input data is empty");
		return 0;
    }
    if(!filename)
    {
		reportError("Output file missing");
		return 0;
    }
    if(symbol_number == 0)
    {
		symbol_number = 1;
    }
 
	//second scan
    for (jab_int32 loop=1; loop<para_number; loop++)
    {
        if (0 == strcmp(para[loop],"--ecc-level"))
        {
			char* option = para[loop];
            if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", option);
				return 0;
			}
            symbol_ecc_levels = (jab_int32 *)calloc(symbol_number, sizeof(jab_int32));
            if(!symbol_ecc_levels)
            {
                reportError("Memory allocation for symbol ecc levels failed");
                return 0;
            }
            for (jab_int32 j=0; j<symbol_number; j++)
            {
				if(loop + 1 > para_number - 1)
					break;
				char* endptr;
				symbol_ecc_levels[j] = strtol(para[++loop], &endptr, 10);
				if(*endptr)
				{
					if(symbol_ecc_levels_number == 0)
					{
						printf("Value for option '%s' missing or invalid.\n", option);
						return 0;
					}
					loop--;
					break;
				}
                if(symbol_ecc_levels[j] < 0 || symbol_ecc_levels[j] > 10)
				{
                    reportError("Invalid error correction level (must be 1 - 10).");
					return 0;
				}
				symbol_ecc_levels_number++;
			}
        }
        else if (0 == strcmp(para[loop],"--symbol-version"))
        {
			char* option = para[loop];
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", option);
				return 0;
			}
            symbol_versions = (jab_vector2d *)calloc(symbol_number, sizeof(jab_vector2d));
            if(!symbol_versions)
            {
                reportError("Memory allocation for symbol versions failed");
                return 0;
            }
			for(jab_int32 j=0; j<symbol_number; j++)
			{
				if(loop + 1 > para_number - 1)
				{
					printf("Too few values for option '%s'.\n", option);
					return 0;
				}
				char* endptr;
				symbol_versions[j].x = strtol(para[++loop], &endptr, 10);
				if(*endptr)
				{
					printf("Invalid or missing values for option '%s'.\n", option);
					return 0;
				}
				if(loop + 1 > para_number - 1)
				{
					printf("Too few values for option '%s'.\n", option);
					return 0;
				}
				symbol_versions[j].y = strtol(para[++loop], &endptr, 10);
				if(*endptr)
				{
					printf("Invalid or missing values for option '%s'.\n", option);
					return 0;
				}
				if(symbol_versions[j].x < 1 || symbol_versions[j].x > 32 || symbol_versions[j].y < 1 || symbol_versions[j].y > 32)
				{
					reportError("Invalid symbol side version (must be 1 - 32).");
					return 0;
				}
				symbol_versions_number++;
			}
        }
        else if (0 == strcmp(para[loop],"--symbol-position"))
        {
			char* option = para[loop];
			if(loop + 1 > para_number - 1)
			{
				printf("Value for option '%s' missing.\n", option);
				return 0;
			}
            symbol_positions = (jab_int32 *)calloc(symbol_number, sizeof(jab_int32));
            if(!symbol_positions)
            {
                reportError("Memory allocation for symbol positions failed");
                return 0;
            }
            for(jab_int32 j=0; j<symbol_number; j++)
            {
				if(loop + 1 > para_number - 1)
				{
					printf("Too few values for option '%s'.\n", option);
					return 0;
				}
				char* endptr;
				symbol_positions[j] = strtol(para[++loop], &endptr, 10);
				if(*endptr)
				{
					printf("Invalid or missing values for option '%s'.\n", option);
					return 0;
				}
				if(symbol_positions[j] < 0 || symbol_positions[j] > 60)
				{
					reportError("Invalid symbol position value (must be 0 - 60).");
					return 0;
				}
				symbol_positions_number++;
            }
        }
    }
 
    //check input
    if(symbol_number == 1 && symbol_positions)
    {
		if(symbol_positions[0] != 0)
		{
			reportError("Incorrect symbol position value for master symbol.");
			return 0;
		}
    }
	if(symbol_number > 1 && symbol_positions_number != symbol_number)
    {
        reportError("Symbol position information is incomplete for multi-symbol code");
        return 0;
    }
    if (symbol_number > 1 && symbol_versions_number != symbol_number)
    {
		reportError("Symbol version information is incomplete for multi-symbol code");
        return 0;
    }
    return 1;
}
 
void cleanMemory()
{
	if(data) free(data);
	if(symbol_positions) free(symbol_positions);
	if(symbol_versions)  free(symbol_versions);
	if(symbol_ecc_levels)free(symbol_ecc_levels);
}
 
int main(int argc, char *argv[])
{
    if(argc < 2 || (0 == strcmp(argv[1],"--help")))
	{
		printUsage();
		return 1;
	}
	if(!parseCommandLineParameters(argc, argv))
	{
		return 1;
	}
 
    //create encode parameter object
    jab_encode* enc = createEncode(color_number, symbol_number);
    if(enc == NULL)
    {
		cleanMemory();
		reportError("Creating encode parameter failed");
        return 1;
    }
    if(module_size > 0)
    {
		enc->module_size = module_size;
    }
    if(master_symbol_width > 0)
    {
		enc->master_symbol_width = master_symbol_width;
    }
    if(master_symbol_height > 0)
    {
		enc->master_symbol_height = master_symbol_height;
    }
	for(jab_int32 loop=0; loop<symbol_number; loop++)
	{
		if(symbol_ecc_levels)
			enc->ecc_levels[loop] = symbol_ecc_levels[loop];
		if(symbol_versions)
			enc->symbol_versions[loop] = symbol_versions[loop];
		if(symbol_positions)
			enc->symbol_positions[loop] = symbol_positions[loop];
	}
 
	//generate JABCode
	if(!generateJABCode(enc, data))
	{
		reportError("Creating jab code failed");
		destroyEncode(enc);
		cleanMemory();
		return 1;
	}
 
	//save bitmap in image file
	if(!saveImage(enc->bitmap, filename))
	{
		reportError("Saving png image failed");
		destroyEncode(enc);
		cleanMemory();
		return 1;
	}
	destroyEncode(enc);
	cleanMemory();
	return 0;
}

Source : GitHub, BSI

Et vous ?

Qu’en pensez-vous ?

Pour quelles applications pensez-vous que JAB Code puisse être utile ?

Voir aussi :

La rubrique Sécurité