|
Technical Note of
"Split/Merge AudioVisual" 1 |
index@kenjikojima.com |
|
|
|
||
|
|
||
get the imagedata of image "mosaic"
-- actual size of image "mosaic" is 4 pixels by 3 pixels
-- the binary data of 12 pixels are " V_; prF éçb w{R OW2 dcE ïÑ\ àëj @<! JR- q{M fpF" which is ASCII.
-- convert ASCII of the first cell (pixel) to decimal (base 10)
put character 1 to 4 of it into firstCell -- this is only the first cell
repeat with i=1 to 4
put charToNum(character i of firstCell) & space after tDecimal
end repeat
-- the result of tDecimal contains "0 86 95 59 "
The first number 0 of the result is the alpha or the mask data. The second number 86 is Red color value, the third 95 is Green color value and the forth 59 is Blue color value of the first image cell (pixel). The numbers are called RGB color. BRG color values are assigned from 0 to 255 by 10 base numbers. Decimal 255 is described 8 digit number "11111111". Sometimes RGB values are used hexadecimal (base 16), however we will use 8 digit binary for cryptography in here.
0 and 0 -> 0 0 and 1 -> 1 1 and 0 -> 1 1 and 1 -> 0 10010011 (binary 1) 00100001 (binary 2) ------------------------ 10110010 (the result)
00000000 (the first number in the pixel. 0 in decimal) 00010100 (random number 20 in decimal) ---------------------------------------- 00010100 (the result is 20 in decimal)
01010110 (the second number in the pixel. 86 in decimal) 00001110 (random number 14 in decimal) ---------------------------------------- 01011000 (the result is 88 in decimal)
-- LiveCode expression 0 bitXOr 20 -- evaluates to 20 86 bitXOr 14 -- in binary: 1010110 bitXOr 0001110; evaluates to 1011000; converts to 88
00010100 (the result is 20 in decimal) 00010100 (random number 20 in decimal) -------------------------------------------- 00000000 (the first number in the pixel) 01011000 (the result is 88 in decimal) 00001110 (random number 14 in decimal) --------------------------------------------- 01010110 (the second number in the pixel that is 86 in decimal)
-- the function to get a random number
function randomNumbers
put random(244) + 10 into tNumber
return tNumber
end rrandomNumbers
-- the function to get mosaic data from an original image
-- the original image name is "pOriginal", the mosaic width is "pMosaicWidth"
function getMosaicData pOriginal, pMosaicWidth
put the rect of image pOriginal into tRect
put the formattedWidth of image pOriginal into tOriginalWidth
put the formattedHeight of image pOriginal into tOriginalHeight
set the width of image pOriginal to pMosaicWidth
set the height of image pOriginal to pMosaicWidth * tOriginalHeight div tOriginalWidth
put the imagedata of image pOriginal into tMosaicData
set the rect of image pOriginal to tRect
return tMosaicData
end getMosaicData
put the length of getMosaicData(tOriginal, 4) into mosaicLength
-- the mosaic image data is " V_; prF éçb w{R OW2 dcE ïÑ\ àëj @<! JR- q{M fpF" which is ASCII.
-- random numbers have to be made the length of the mosaic data (the number of pixels by 4)
repeat with i=1 to mosaicLength
put randomNumbers() & space after tRandomNums
end repeat
put tRandomNums -- the random numbers (every time it makes different numbers)
put getMosaicData(tOriginal, 4) into tMosaicData -- tMosaicData contains the imagedata of the mosaic image -- tOiginal is the name of original image, 4 is the width of mosaic image put the length of tMosaicData into tMosaicLength -- the length of the mosaic image data repeat with i=1 to tMosaicLength step 4 -- convert by each pixel if char i of tMosaicData is empty then exit repeat put charToNum(char i of tMosaicData) bitXOr (word i of tRandomNums) into tNum1 put charToNum(char i + 1 of tMosaicData) bitXOr (word i + 1 of tRandomNums) into tNum2 put charToNum(char i + 2 of tMosaicData) bitXOr (word i + 2 of tRandomNums) into tNum3 put charToNum(char i + 3 of tMosaicData) bitXOr (word i + 3 of tRandomNums) into tNum4 put tNum1 & space & tNum2 & space & tNum3 & space & tNum4 & space after tMosaicNums end repeat put tMosaicNums -- the ciphered mosaic numbers
command setKeyCipherImage pImagedataNum, pImagePixNum, pMosaicWidth
put the num of words of pImagedataNum into tNum
repeat with i=1 to tNum
put numToChar(word i of pImagedataNum) after tData
end repeat
put the rect of image ("pix" & pImagePixNum) into tRect
put the width of image ("pix" & pImagePixNum) into tOriginalWidth
put the height of image ("pix" & pImagePixNum) into tOriginalHeight
set the width of image ("pix" & pImagePixNum) to pMosaicWidth
set the height of image ("pix" & pImagePixNum) to pMosaicWidth * tOriginalHeight div tOriginalWidth
set the imagedata of image ("pix" & pImagePixNum) to tData
set the rect of image ("pix" & pImagePixNum) to tRect
end setKeyCipherImage
setKeyCipherImage tRandomNums, 1, 4 -- the image of random number key
setKeyCipherImage tMosaicNums, 2, 4 -- the image of ciphered mosaic
![]() |
image "pix1" numbers (random numbers key): |
![]() |
image "pix2" numbers (ciphered mosaic image): |
put 1 into tCount repeat for each word tWord in tRandomNum put numToChar(tWord bitXor (word tCount of tMosaicNum)) after tImageData add 1 to tCount end repeat put the rect of image "exam" into tRect set the rect of image "exam" to 0,0,4,3 -- width = 4, height = 3 set the imagedata of image "exam" to tImageData set the rect of image "exam" to tRect put tImageData -- to see the binary of the result of bitwise XOR operation
![]() |
the binary data of image "exam" |