Адрес: ул. Б. Очаковская 32 Москва Россия
Наши официальные канал и чат в telegram

Создание QR кода содержащее число

Библиотеки и примеры программ на языке Yabasic
Аватара пользователя
Anton
Site Admin
Сообщения: 120
Зарегистрирован: Чт фев 08, 2024 7:03 pm

Создание QR кода содержащее число

Сообщение Anton »

Создание QR кода содержащее число
Основной код:

Код: Выделить всё

rem """2D Datamatrix barcode encoder
rem 
rem All needed by the user is done via the DataMatrixEncoder class:
rem 
rem "HuDoRa" datamatrix barcode:
rem XX  XX  XX  XX  XX  XX  XX
rem XX  XXXX  XXXXXX      XXXXXX
rem XXXXXX    XX          XX
rem XXXXXX    XX        XXXX  XX
rem XXXX  XX  XXXXXX
rem XXXXXX    XXXXXXXX    XXXXXX
rem XX    XX  XXXXXXXX  XXXX
rem XX    XX      XXXX      XXXX
rem XX  XXXXXXXXXX    XXXX
rem XX  XXXX    XX            XX
rem XX  XXXXXX  XXXXXX      XX
rem XXXXXX  XX  XX  XX  XX    XX
rem XX    XX              XX
rem XXXXXXXXXXXXXXXXXXXXXXXXXXXX
rem 
rem 
rem Implemented by Helen Taylor for HUDORA GmbH.
rem 
rem Detailed documentation on the format here:
rem http://grandzebu.net/informatique/codbar-en/datamatrix.htm
rem Further resources here: http://www.libdmtx.org/resources.php
rem 
rem You may use this under a BSD License.
rem """
rem Ported from Python to Yabasic by Galileo, 4/2018.
rem You can check the results on this site: http://www.quickmark.com.tw/En/qrcode-datamatrix-generator/?dmText
rem Select DataMatrix options Normal text and Encoding ASCII (4, 8, 16 bits)

import TextEncoder
import Placement
import Renderer

rem """Top-level class which handles the overall process of
rem     encoding input data, placing it in the matrix and
rem     outputting the result"""
//class DataMatrixEncoder:
    
// 	"""Set up the encoder with the input text.
// 	This will encode the text,
// 	and create a matrix with the resulting codewords"""
    sub initialize(text$)
        TextEncoder.initialize()
        codewords$ = encode$(text$)

        matrix_size = TextEncoder.mtx_size
        Placement.initialize(matrix_size)
        place(codewords$)
	end sub

	//"""Return an ascii representation of the matrix"""
    sub get_ascii$()
        
        Renderer.initialize(matrix_size)
        return Renderer.get_ascii$()
	end sub

if (!peek("isbound")) bind "Datamatrix.exe"

arg = peek("arguments")
if arg = 1 then
	arg$ = peek$("argument")
	print arg$
else
	line input "Enter a string: " arg$
	//arg$ = "This is a test of this big funny program !!!"
end if

clear screen
	
initialize(arg$)
Renderer.initialize(matrix_size)
Renderer.draw_datamatrix(10, 10, 4)
inkey$
exit
Библиотека Placement.yab

Код: Выделить всё

//"""Matrix placement for 2D datamatrix barcode encoder"""


sub sh_l(lhs, rhs)
	return int(lhs * 2 ^ rhs)
end sub

sub sh_r(lhs, rhs)
	return int(lhs / 2 ^ rhs)
end sub


//"""Class which takes care of placing codewords in the correct position in the 2D datamatrix"""
//class DataMatrixPlacer:

    sub initialize(size)
    	local i, j
    	
        rows = size
        cols = size
        dim matrix(rows, cols)
        for i = 0 to rows
        	for j = 0 to cols
        		matrix(i, j) = -1
        	next j
        next i
	end sub
	
	export sub getmatrix(x, y)
		return matrix(x, y)
	end sub

    //"""Place bit in the correct location in the matrix"""
	sub place_bit(posx, posy, bit)

        //# If out of bounds, wrap around to the other side
        if posx < 0 then
            posx = posx + rows
            posy = posy + (4 - mod(rows + 4, 8))
		end if

        if posy < 0 then
            posy = posy + cols
            posx = posx + (4 - mod(cols + 4, 8))
		end if

        matrix(posx, posy) = bit
	end sub

    sub place_special_1(codeword)
    	local bits$
rem         """Special corner case 1
rem             bottom left corner: |1|2|3|
rem 
rem             top right corner:   |4|5|
rem                                   |6|
rem                                   |7|
rem                                   |8| """
		bits$ = right$("00000000" + bin$(codeword), 8)
		
        place_bit(rows - 1, 0, val(mid$(bits$, 1, 1)))
        place_bit(rows - 1, 1, val(mid$(bits$, 2, 1)))
        place_bit(rows - 1, 2, val(mid$(bits$, 3, 1)))
        place_bit(0, cols - 2, val(mid$(bits$, 4, 1)))
        place_bit(0, cols - 1, val(mid$(bits$, 5, 1)))
        place_bit(1, cols - 1, val(mid$(bits$, 6, 1)))
        place_bit(2, cols - 1, val(mid$(bits$, 7, 1)))
        place_bit(3, cols - 1, val(mid$(bits$, 8, 1)))
	end sub

    sub place_special_2(codeword)
rem         """Special corner case 2
rem             bottom left corner: |1|
rem                                 |2|
rem                                 |3|
rem 
rem             top right corner:  |4|5|6|7|
rem                                      |8| """

		place_bit(rows - 3, 0, shr(and(codeword, shl(1, 7)), 7))
        place_bit(rows - 2, 0, shr(and(codeword, shl(1, 6)), 6))
        place_bit(rows - 1, 0, shr(and(codeword, shl(1, 5)), 5))
        place_bit(0, cols - 4, shr(and(codeword, shl(1, 4)), 4))
        place_bit(0, cols - 3, shr(and(codeword, shl(1, 3)), 3))
        place_bit(0, cols - 2, shr(and(codeword, shl(1, 2)), 2))
        place_bit(0, cols - 1, shr(and(codeword, shl(1, 1)), 1))
        place_bit(1, cols - 1, and(codeword, 1))
	end sub
rem
    sub place_special_3(codeword)
rem         """Special corner case 3
rem             bottom left corner: |1|
rem                                 |2|
rem                                 |3|
rem 
rem             top right corner:   |4|5|
rem                                   |6|
rem                                   |7|
rem                                   |8| """

        place_bit(rows - 3, 0, shr(and(codeword, shl(1, 7)), 7))
        place_bit(rows - 2, 0, shr(and(codeword, shl(1, 6)), 6))
        place_bit(rows - 1, 0, shr(and(codeword, shl(1, 5)), 5))
        place_bit(0, cols - 2, shr(and(codeword, shl(1, 4)), 4))
        place_bit(0, cols - 1, shr(and(codeword, shl(1, 3)), 3))
        place_bit(1, cols - 1, shr(and(codeword, shl(1, 2)), 2))
        place_bit(2, cols - 1, shr(and(codeword, shl(1, 1)), 1))
        place_bit(3, cols - 1, and(codeword, 1))
	end sub

    sub place_special_4(codeword)
rem         """Special corner case 4
rem             bottom left corner: |1|
rem 
rem             bottom right corner: |2|
rem 
rem             top right corner: |3|4|5|
rem                               |6|7|8| """

        place_bit(rows - 1, 0, shr(and(codeword, shl(1, 7)), 7))
        place_bit(rows - 1, cols - 1, shr(and(codeword, shl(1, 6)), 6))
        place_bit(0, cols - 3, shr(and(codeword, shl(1, 5)), 5))
        place_bit(0, cols - 2, shr(and(codeword, shl(1, 4)), 4))
        place_bit(0, cols - 1, shr(and(codeword, shl(1, 3)), 3))
        place_bit(1, cols - 3, shr(and(codeword, shl(1, 2)), 2))
        place_bit(1, cols - 2, shr(and(codeword, shl(1, 1)), 1))
        place_bit(1, cols - 1, and(codeword, 1))
	end sub

    sub place_standard_shape(posx, posy, codeword)
rem         """Standard codeword placement
rem             |1|2|
rem             |3|4|5|
rem             |6|7|8| """

        if matrix(posx, posy) = -1 then
            place_bit(posx - 2, posy - 2, shr(and(codeword, shl(1, 7)), 7))
            place_bit(posx - 2, posy - 1, shr(and(codeword, shl(1, 6)), 6))
            place_bit(posx - 1, posy - 2, shr(and(codeword, shl(1, 5)), 5)) 
            place_bit(posx - 1, posy - 1, shr(and(codeword, shl(1, 4)), 4))
            place_bit(posx - 1, posy - 0, shr(and(codeword, shl(1, 3)), 3))
            place_bit(posx, posy - 2, shr(and(codeword, shl(1, 2)), 2))
            place_bit(posx, posy - 1, shr(and(codeword, shl(1, 1)), 1))
            place_bit(posx, posy - 0, and(codeword, 1))
		end if
	end sub

	//"""Place all the given codewords into the given matrix. Matrix should be correctly pre-sized"""
    export sub place(codewords$)
		local row, col, codeword, cw_list(1), cw$(1), t
        
		row = 4
        col = 0
        t = token(codewords$, cw$())
        
        redim cw_list(t)

        for codeword = 1 to t
        	cw_list(codeword) = val(cw$(codeword))
        next codeword
        codeword = 1
		
        while(True)
            //# Special corner cases
            if row = rows and col = 0 then
                place_special_1(cw_list(codeword))
				codeword = codeword + 1
            elseif row = rows - 2 and col = 0 and mod(cols, 4) then
                place_special_2(cw_list(codeword))
				codeword = codeword + 1
            elseif row = rows - 2 and col = 0 and mod(cols, 8) = 4 then
                place_special_3(cw_list(codeword))
				codeword = codeword + 1
            elseif row = rows + 4 and col = 2 and mod(cols, 8) = 0 then
                place_special_4(cw_list(codeword))
                codeword = codeword + 1
			end if

            //# Sweep upwards diagonally
            while(True)
                if row < rows and col >= 0 and matrix(row, col) = -1 then
                    place_standard_shape(row, col, cw_list(codeword))
                    codeword = codeword + 1
				end if

                row = row - 2
                col = col + 2

                if row < 0 or col >= cols break
			wend

            row = row + 1
            col = col + 3

            //# Sweep downwards diagonally
            while(True)
                if row >= 0 and col < cols and matrix(row, col) = -1 then
                    place_standard_shape(row, col, cw_list(codeword))
                    codeword = codeword + 1
				end if

                row = row + 2
                col = col - 2

                if row >= rows or col < 0 break
			wend

            row = row + 3
            col = col + 1

            if row >= rows and col >= cols break
		wend
		for row = 0 to rows
			for col = 0 to cols
				if matrix(row, col) = -1 matrix(row, col) = 0
			next col
		next row
	end sub
Библиотека Renderer.yab

Код: Выделить всё

//"""Datamatrix renderer"""

rem """Rendering class - given a pre-populated datamatrix.
rem it will add edge handles and render to either to an image
rem (including quiet zone) or ascii printout"""
//class DataMatrixRenderer:

    sub initialize(size)
        width = size
        height = size
        dim matrix(width, height)

        //# grow the matrix in preparation for the handles
        add_border(0)

        //# add the edge handles
        add_handles()
	end sub

rem """Set the contents of the given cell"""
    sub put_cell(posx, posy, colorin)
        if numparams = 2 colorin = 1
		
        matrix(posy, posx) = colorin
	end sub

rem	"""Set up the edge handles"""
    sub add_handles()
    	local posx, posy
        
        //# bottom solid border
        for posx = 0 to width
        	put_cell(posx, height - 1)
        next posx

        //# left solid border
        for posy = 0 to height - 1
        	put_cell(0, posy)
        next posy

        //# top broken border
        for posx = 0 to width - 1 step 2
        	put_cell(posx, 0)
        next posx

        //# right broken border
        for posy = height - 1 to 0 step -2
        	put_cell(width - 1, posy)
        next posy
	end sub

rem """Wrap the matrix in a border of given width and colour"""
	sub add_border(colorin, wid)
		local x, y
		
		if numparams < 2 wid = 1
		if numparams < 1 colorin = 1
		
        width = width + (wid * 2)
        height = height + (wid * 2)
        
        redim matrix(width, height)
        
        for x = wid to width - wid
        	for y = wid to height - wid
        		matrix(x, y) = Placement.getmatrix(x - wid, y - wid)
        	next y
        next x 
	end sub

	//"""Write an ascii version of the matrix out to screen"""
    sub get_ascii$()
		local x, y, s$
		
		s$ = "\n"	

		for x = 0 to width - 1
			for y = 0 to height - 1
				if matrix(x, y) then
					s$ = s$ + "##"
				else
					s$ = s$ + "--"
				end if
			next y
			s$ = s$ + "\n"
		next x
		
		return s$ + "\n"
	end sub
	
	sub draw_datamatrix(dx, dy, size)
		local x, y
		
		open window 320, 240

		for x = 0 to width - 1
			for y = 0 to height - 1
				if matrix(y, x) then
					fill rectangle x * size + dx, y * size + dy, x * size + dx + size, y * size + dy + size
 				else
 					clear fill rectangle x * size + dx, y * size + dy, x * size + dx + size, y * size + dy + size
				end if
			next y
		next x		
	end sub
Библиотека TextEncoder.yab

Код: Выделить всё

//"""Text encoder for 2D datamatrix barcode encoder"""

import ReedSolomon


//data_word_length
data 3, 5, 8, 12, 18, 22, 30, 36, 44, 62, 86, 114, 144, 174, 204, 280, 368, 456, 576, 696, 816, 1050, 1304, 1558
                    
dim data_word_length(24)

for n = 0 to 23
	read data_word_length(n)
next n                    


//error_word_length
data 5, 7, 10, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 68, 84, 112, 144, 192, 224, 272, 336, 408, 496, 620
                     
dim error_word_length(24)

for n = 0 to 23
	read error_word_length(n)
next n    

//data_region_size
data 8, 10, 12, 14, 16, 18, 20, 22, 24, 14, 16, 18, 20, 22, 24, 14, 16, 18, 20, 22, 24, 18, 20, 22

dim data_region_size(24)

for n = 0 to 23
	read data_region_size(n)
next n

//"""generate the next padding character"""
sub rand253(pos)
	local rnd
	
	rnd = mod(149 * pos, 253) + 1
	return mod(129 + rnd, 254)
end sub

//class TextEncoder:
//    """Text encoder class for 2D datamatrix"""

	sub initialize()
		codewords$ = ""
        size_index = -1
        mtx_size = 0
	end sub

	//"""Encode the given text and add padding and error codes also set up the correct matrix size for the resulting codewords"""
    export sub encode$(texto$)       
    	local n

        initialize()

        encode_text(texto$)

        pad()

        append_error_codes()

        mtx_size = data_region_size(size_index)
        
        return codewords$

	end sub

	//"""Encode the given text into codewords"""
    sub encode_text(texto$)
    	local numbuf$, long, char$, n
    	
    	long = len(texto$)       

    	for n = 1 to long
    		char$ = mid$(texto$, n, 1)
    		if instr("0123456789", char$) then
                numbuf$ = numbuf$ + char$
                if len(numbuf$) = 2 then
                    //# we have collected two numbers: add them as a digit pair
                    append_digits(numbuf$)
                    numbuf$ = ""
				end if
            else
                if numbuf$ <> "" then
                    //# an unpaired number: add it as an ascii character
                    append_ascii_char(numbuf$)
                    numbuf$ = ""
				end if

                //# a regular ascii character
                append_ascii_char(char$)
			end if
		next n

        //# there might be a single number left over at the end
        if numbuf$ <> "" append_ascii_char(numbuf$)
	end sub

	//"""Pad out the encoded text to the correct word length"""
    sub pad()
		local unpadded_len, length, padsize, i, cw$(1)

        unpadded_len = token(codewords$, cw$())

        //# Work out how big the matrix needs to be
        for size_index = 0 to 23
        	length = data_word_length(size_index)
        	if length >= unpadded_len break
        next size_index
        
        if length > 44 print "Text too long for this program (max. 44 characters)." : end
        

        //# Number of characters with which the data will be padded
        padsize = length - unpadded_len
		
        //# First pad character is 129
        if padsize codewords$ = codewords$ + " " + str$(129)

        //# Remaining pad characters generated by 253-state algorithm
        
        for i = 1 to padsize - 1
           	codewords$ = codewords$ + " " + str$(rand253(unpadded_len + i + 1))
		next i
	end sub

   //"""Calculate the necessary number of Reed Solomon error codes for the encoded text and padding codewords, and append to the codeword buffer"""
    sub append_error_codes()
    	local error_length, error_words$

        error_length = error_word_length(size_index)

        error_words$ = ReedSolomon.get_reed_solomon_code$(codewords$, error_length)

        codewords$ = codewords$ + " " + error_words$
	end sub

    //"""Write a pair of digits (the appended value is 130 + the integer value of the digits together"""
    sub append_digits(digits$)
        codewords$ = codewords$ + " " + str$(130 + val(digits$))
	end sub

    //"""Append a single ascii character (the appended value is the value of the char plus 1"""
    sub append_ascii_char(char$)
        codewords$ = codewords$ + " " + str$(asc(char$) + 1)
	end sub

Биюлиотека ReedSolomon.yab

Код: Выделить всё

//"""Reed Solomon error code calculation"""

//# Factor table
label 5
	data 228, 48, 15, 111, 62
	
label 7
	data 23, 68, 144, 134, 240, 92, 254
	
label 10	
    data 28, 24, 185, 166, 223, 248, 116, 255, 110, 61
    
label 11
	data 175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120
	
label 12
	data 41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242
	
label 14
	data 156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185
	
label 18
	data 83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90, 188
	
label 20
	data 15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186, 172
	
label 24
	data 52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172, 254, 124, 12, 181, 184, 96, 50, 193
	
label 28
	data 211, 231, 43, 97, 71, 96, 103, 174, 37, 151, 170, 53, 75, 34, 249, 121, 17, 138, 110, 213, 141, 136, 120, 151, 233, 168, 93, 255
	
label 36
	data 245, 127, 242, 218, 130, 250, 162, 181, 102, 120, 84, 179, 220, 251, 80, 182, 229, 18, 2, 4, 68, 33, 101, 137, 95, 119, 115, 44, 175, 184, 59, 25, 225, 98, 81, 112
	
label 42
	data 77, 193, 137, 31, 19, 38, 22, 153, 247, 105, 122, 2, 245, 133, 242, 8, 175, 95, 100, 9, 167, 105, 214, 111, 57, 121, 21, 1, 253, 57, 54, 101, 248, 202, 69, 50, 150, 177, 226, 5, 9, 5
	
label 48
	data 245, 132, 172, 223, 96, 32, 117, 22, 238, 133, 238, 231, 205, 188, 237, 87, 191, 106, 16, 147, 118, 23, 37, 90, 170, 205, 131, 88, 120, 100, 66, 138, 186, 240, 82, 44, 176, 87, 187, 147, 160, 175, 69, 213, 92, 253, 225, 19
	
label 56
	data 175, 9, 223, 238, 12, 17, 220, 208, 100, 29, 175, 170, 230, 192, 215, 235, 150, 159, 36, 223, 38, 200, 132, 54, 228, 146, 218, 234, 117, 203, 29, 232, 144, 238, 22, 150, 201, 117, 62, 207, 164, 13, 137, 245, 127, 67, 247, 28, 155, 43, 203, 107, 233, 53, 143, 46
	
label 62
	data 242, 93, 169, 50, 144, 210, 39, 118, 202, 188, 201, 189, 143, 108, 196, 37, 185, 112, 134, 230, 245, 63, 197, 190, 250, 106, 185, 221, 175, 64, 114, 71, 161, 44, 147, 6, 27, 218, 51, 63, 87, 10, 40, 130, 188, 17, 163, 31, 176, 170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47, 11, 204
	
label 68
	data 220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127, 213, 136, 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236, 66, 139, 153, 185, 202, 167, 179, 25, 220, 232, 96, 210, 231, 136, 223, 239, 181, 241, 59, 52, 172, 25, 49, 232, 211, 189, 64, 54, 108, 153, 132, 63, 96, 103, 82, 186
	

//# Galois Field log values
label datalogval
    data -255, 255, 1, 240, 2, 225, 241, 53, 3, 38, 226, 133, 242, 43
    data 54, 210, 4, 195, 39, 114, 227, 106, 134, 28, 243, 140, 44, 23
    data 55, 118, 211, 234, 5, 219, 196, 96, 40, 222, 115, 103, 228, 78
    data 107, 125, 135, 8, 29, 162, 244, 186, 141, 180, 45, 99, 24, 49
    data 56, 13, 119, 153, 212, 199, 235, 91, 6, 76, 220, 217, 197, 11
    data 97, 184, 41, 36, 223, 253, 116, 138, 104, 193, 229, 86, 79, 171
    data 108, 165, 126, 145, 136, 34, 9, 74, 30, 32, 163, 84, 245, 173
    data 187, 204, 142, 81, 181, 190, 46, 88, 100, 159, 25, 231, 50, 207
    data 57, 147, 14, 67, 120, 128, 154, 248, 213, 167, 200, 63, 236, 110
    data 92, 176, 7, 161, 77, 124, 221, 102, 218, 95, 198, 90, 12, 152
    data 98, 48, 185, 179, 42, 209, 37, 132, 224, 52, 254, 239, 117, 233
    data 139, 22, 105, 27, 194, 113, 230, 206, 87, 158, 80, 189, 172, 203
    data 109, 175, 166, 62, 127, 247, 146, 66, 137, 192, 35, 252, 10, 183
    data 75, 216, 31, 83, 33, 73, 164, 144, 85, 170, 246, 65, 174, 61
    data 188, 202, 205, 157, 143, 169, 82, 72, 182, 215, 191, 251, 47, 178
    data 89, 151, 101, 94, 160, 123, 26, 112, 232, 21, 51, 238, 208, 131
    data 58, 69, 148, 18, 15, 16, 68, 17, 121, 149, 129, 19, 155, 59
    data 249, 70, 214, 250, 168, 71, 201, 156, 64, 60, 237, 130, 111, 20
    data 93, 122, 177, 150
    
dim logval(255)
restore datalogval
for n = 0 to 255
	read logval(n)
next n

//# Galois Field antilog values
label dataalogval
    data 1, 2, 4, 8, 16, 32, 64, 128, 45, 90, 180, 69, 138, 57
    data 114, 228, 229, 231, 227, 235, 251, 219, 155, 27, 54, 108, 216, 157
    data 23, 46, 92, 184, 93, 186, 89, 178, 73, 146, 9, 18, 36, 72
    data 144, 13, 26, 52, 104, 208, 141, 55, 110, 220, 149, 7, 14, 28
    data 56, 112, 224, 237, 247, 195, 171, 123, 246, 193, 175, 115, 230, 225
    data 239, 243, 203, 187, 91, 182, 65, 130, 41, 82, 164, 101, 202, 185
    data 95, 190, 81, 162, 105, 210, 137, 63, 126, 252, 213, 135, 35, 70
    data 140, 53, 106, 212, 133, 39, 78, 156, 21, 42, 84, 168, 125, 250
    data 217, 159, 19, 38, 76, 152, 29, 58, 116, 232, 253, 215, 131, 43
    data 86, 172, 117, 234, 249, 223, 147, 11, 22, 44, 88, 176, 77, 154
    data 25, 50, 100, 200, 189, 87, 174, 113, 226, 233, 255, 211, 139, 59
    data 118, 236, 245, 199, 163, 107, 214, 129, 47, 94, 188, 85, 170, 121
    data 242, 201, 191, 83, 166, 97, 194, 169, 127, 254, 209, 143, 51, 102
    data 204, 181, 71, 142, 49, 98, 196, 165, 103, 206, 177, 79, 158, 17
    data 34, 68, 136, 61, 122, 244, 197, 167, 99, 198, 161, 111, 222, 145
    data 15, 30, 60, 120, 240, 205, 183, 67, 134, 33, 66, 132, 37, 74
    data 148, 5, 10, 20, 40, 80, 160, 109, 218, 153, 31, 62, 124, 248
    data 221, 151, 3, 6, 12, 24, 48, 96, 192, 173, 119, 238, 241, 207
    data 179, 75, 150, 1

dim alogval(255)
restore dataalogval
for n = 0 to 255
	read alogval(n)
next n

//"""Calculate the Galois field sum of two integers"""
sub gfsum(int1, int2)
	return xor(int1, int2)
end sub

//"""Calculate the Galois field product of two integers"""
sub gfproduct(int1, int2)
	local i, a, b
	
	if int1 = 0 or int2 = 0 then
		return 0
	else
		a = logval(int1) : if a < 0 a = 0
		b = logval(int2) : if b < 0 b = 0
		if a = 0 or b = 0 then
			i = 1
		else
			i = mod(a + b, 255)
		end if
		return alogval(i)
	end if
end sub


//"""Calculate and return the Reed-Solomon error codewords of the given length, for the given data"""
sub get_reed_solomon_code$(datos$, num_code_words)
	local cw_factors(num_code_words - 1), code_words(num_code_words - 1), d$(1), long, n, j, data_word$, tmp, j2
	
	switch(num_code_words)
		case 5:	restore 5 : break
		case 7: restore 7 : break
		case 10:restore 10: break
		case 11:restore 11: break
		case 12:restore 12: break
		case 14:restore 14: break
		case 18:restore 18: break
		case 20:restore 20: break
		case 24:restore 24: break
		case 28:restore 28: break
		case 36:restore 36: break
		case 42:restore 42: break
		case 48:restore 48: break
		case 56:restore 56: break
		case 62:restore 62: break
		case 68:restore 68: break
	end switch
	
	for n = 0 to num_code_words - 1
		read cw_factors(n)
	next n

	long = token(datos$, d$())
	
    for n = 1 to long

        tmp = gfsum(val(d$(n)), code_words(num_code_words - 1))

        for j = num_code_words-1 to 0 step -1
            code_words(j) = gfproduct(tmp, cw_factors(j))
            if j > 0 code_words(j) = gfsum(code_words(j - 1), code_words(j))
		next j
	next n
	
	data_word$ = ""
	for n = num_code_words-1 to 0 step -1
		data_word$ = data_word$ + " " + str$(code_words(n))
	next n
	
    return data_word$
end sub
Datamatrix.png
У вас нет необходимых прав для просмотра вложений в этом сообщении.