Salattuja ääni- ja kuvatiedostoja pystyy lukemaan kuin mitä tahansa ääni- ja kuvatiedostoa, eli salausalgoritmi 'piilottaa' datan äänen tai kuvan sisään.
Salauksen teho perustuu siihen, että käyttäjä ei tajua salatun tiedoston olevan joku muu miltä näyttää (ääni tai kuva).
Tehostaaksesi salauksen, salaa tiedosto vielä CoolBasicin omalla Encrypt -komennolla.
Kuvatiedostoon tulee mustavalkoharmaita pisteitä, kun taas äänitiedostoon algoritmi heittää kohinaa.
HUOM! filetobmp -funktiota käytettäessä salattavan tiedoston tulee olla todella pieni (en tiedä mikä on maksimi), mutta filetowav tukee kaikkia tiedostokokoja.
CB-koodit:
Code: Select all
Type tavu
field b
EndType
Function filetobmp(file$)
fs=FileSize(file)
a=OpenToRead(file)
cur#=0
Repeat
cur+1
t.tavu=New(tavu)
t\b=MakeMEMBlock(1)
PokeByte t\b, 0, ReadByte(a)
//If rand(0,fs) Mod 100 = 0 and rand(1,5)=5 Then SetWindow "Kirjoitetaan tavuja muistiin... "+((cur/fs)*100)+"%"
Until EOF(a)
CloseFile a
For o=1000 To 1 Step -1 // kuvan leveys 1-1000
If fs Mod o = 0 Then
b=MakeImage(o,fs/o)
DrawToImage b
fend=fs
cur=1
np=0
For t.tavu = Each tavu
Color PeekByte(t\b,0),PeekByte(t\b,0),PeekByte(t\b,0)
DeleteMEMBlock t\b
Delete t
Dot np,cur
np=np+1
If np=o Then np=0 : cur+1
Next t
DrawToScreen
Exit
EndIf
Next o
SaveImage b, file+".bmp"
EndFunction
Function bmptofile(bmp$,file$)
a=LoadImage(bmp)
b=OpenToWrite(file)
For cur=1 To ImageHeight(a)
PickImageColor a, 0,cur
WriteByte b, getRGB(RED)
Next cur
CloseFile b
EndFunction
Function SM_WriteWav(path$,samplerate,data1,data2=0)
datalen = MEMBlockSize(data1)
If data2 <> 0 Then channels = 2 Else channels = 1
f = OpenToWrite(path$)
WriteByte f,$52 : WriteByte f,$49 : WriteByte f,$46 : WriteByte f,$46//RIFF
WriteInt f,4 + (8+16)+(8 + datalen/4 * channels * 4)
WriteByte f,$57 : WriteByte f,$41 : WriteByte f,$56 : WriteByte f,$45//WAVE
WriteByte f,$66 : WriteByte f,$6d : WriteByte f,$74 : WriteByte f,$20 //FMT
WriteInt f,16
WriteShort f,1
WriteShort f,channels
WriteInt f,samplerate
WriteInt f,samplerate * channels * 4
WriteShort f,channels * 4
WriteShort f,32
WriteByte f,$64 : WriteByte f,$61 : WriteByte f,$74 : WriteByte f,$61 //Data
WriteInt f,datalen/4*channels*4
For i = 0 To datalen-4 Step 4
WriteInt f,PeekInt(data1,i)
Next i
CloseFile f
EndFunction
Function filetowav(file$)
f=MakeMEMBlock(FileSize(file)+1)
a=OpenToRead(file)
c=0
Repeat
PokeByte f, c, ReadByte(a)
c+1
Until EOF(a)
SM_WriteWav(file+".wav",1000,f)
EndFunction
Function wavtofile(wav$, file$)
a=OpenToRead(wav)
SeekFile a, 44
b=OpenToWrite(file)
Repeat
WriteByte b, ReadByte(a)
Until EOF(a)
CloseFile a
CloseFile b
EndFunction
// filetowav(CommandLine()) //Tiedoston automaattinen salaus waviksi kutsuttaessa ohjelmaa komentoriviltä
Lisäksi on mahdollista piilottaa yksi kuva toiseen kuvaan, ns. steganografian avulla:
Code: Select all
Function export(img, modcode=4)
times=85
b=MakeImage(ImageWidth(img),ImageHeight(img))
DrawToImage b
For y=1 To ImageHeight(img)
For x=1 To ImageWidth(img)
PickImageColor img, x,y
Color (getRGB(1) Mod modcode) * times, (getRGB(2) Mod modcode) * times, (getRGB(3) Mod modcode) * times
Dot x,y
Next x
Next y
DrawToScreen
Return b
EndFunction
Function import(img1, img2, modcode=4)
mw=Max(ImageWidth(img1),ImageWidth(img2))
mh=Max(ImageHeight(img1),ImageHeight(img2))
out=MakeImage(mw,mh)
DrawToImage out
For y=1 To ImageHeight(out)
For x=1 To ImageWidth(out)
PickImageColor img1,x,y
r1=getRGB(1)
g1=getRGB(2)
b1=getRGB(3)
PickImageColor img2,x,y
r2=getRGB(1)
g2=getRGB(2)
b2=getRGB(3)
Color Int(r1/modcode)*modcode+(r2/84),Int(g1/modcode)*modcode+(g2/84),Int(b1/modcode)*modcode+(b2/84)
Dot x,y
Next x
Next y
DrawToScreen
Return out
EndFunction
Code: Select all
kuva1=LoadImage("kuva1.png")
kuva2=LoadImage("kuva2.png")
kaksikuvaa = import(kuva1,kuva2)
Code: Select all
piilotettu = export(kaksikuvaa)