Well, you can write your own file formats, or just scramble around with the data of those you are using, "de-scrambling" it, load it, and then straight away scramble it back again. However, that is likely to cause pretty long loading times.
Certain media, like images, meshes and sound can easily be encrypted and decrypted through the use of a memblock. Basically you make your memblock from the source data, apply some algorithms to it to "mess up" the data, and save the results to a file. You then load this file, reverse the algorithm and converts the memblock to the proper image / mesh / whatever.
This would probably be pretty hard to implement now if you have a stressed deadline though, but the basic principle is easy.
I'll write you a short snippet to encrypt and decrypt an image file:
` A demonstration of simple media encryption using memblocks.
` Note that the saved images will be 32-bit per pixel style images (no compression or
` colour palette) and will hence take pretty much place to store; in most cases more
` than what the original file did.
` Setup a conversion table
` Each byte found in the source memblock will be replaced as follows here
dim encrypt_table(255) as byte
dim decrypt_table(255) as byte
encrypt_table(0) = 150
encrypt_table(1) = 31
encrypt_table(2) = 248
encrypt_table(3) = 178
encrypt_table(4) = 240
encrypt_table(5) = 131
encrypt_table(6) = 126
encrypt_table(7) = 16
encrypt_table(8) = 76
encrypt_table(9) = 11
encrypt_table(10) = 233
encrypt_table(11) = 81
encrypt_table(12) = 223
encrypt_table(13) = 146
encrypt_table(14) = 202
encrypt_table(15) = 190
encrypt_table(16) = 105
encrypt_table(17) = 249
encrypt_table(18) = 128
encrypt_table(19) = 118
encrypt_table(20) = 0
encrypt_table(21) = 149
encrypt_table(22) = 107
encrypt_table(23) = 49
encrypt_table(24) = 130
encrypt_table(25) = 165
encrypt_table(26) = 12
encrypt_table(27) = 173
encrypt_table(28) = 162
encrypt_table(29) = 176
encrypt_table(30) = 216
encrypt_table(31) = 177
encrypt_table(32) = 226
encrypt_table(33) = 193
encrypt_table(34) = 247
encrypt_table(35) = 104
encrypt_table(36) = 199
encrypt_table(37) = 28
encrypt_table(38) = 167
encrypt_table(39) = 220
encrypt_table(40) = 19
encrypt_table(41) = 89
encrypt_table(42) = 18
encrypt_table(43) = 148
encrypt_table(44) = 72
encrypt_table(45) = 1
encrypt_table(46) = 117
encrypt_table(47) = 228
encrypt_table(48) = 21
encrypt_table(49) = 201
encrypt_table(50) = 25
encrypt_table(51) = 46
encrypt_table(52) = 253
encrypt_table(53) = 200
encrypt_table(54) = 211
encrypt_table(55) = 35
encrypt_table(56) = 92
encrypt_table(57) = 55
encrypt_table(58) = 59
encrypt_table(59) = 251
encrypt_table(60) = 67
encrypt_table(61) = 39
encrypt_table(62) = 250
encrypt_table(63) = 244
encrypt_table(64) = 44
encrypt_table(65) = 164
encrypt_table(66) = 136
encrypt_table(67) = 85
encrypt_table(68) = 79
encrypt_table(69) = 90
encrypt_table(70) = 154
encrypt_table(71) = 50
encrypt_table(72) = 229
encrypt_table(73) = 112
encrypt_table(74) = 175
encrypt_table(75) = 17
encrypt_table(76) = 188
encrypt_table(77) = 205
encrypt_table(78) = 160
encrypt_table(79) = 157
encrypt_table(80) = 180
encrypt_table(81) = 41
encrypt_table(82) = 189
encrypt_table(83) = 7
encrypt_table(84) = 62
encrypt_table(85) = 33
encrypt_table(86) = 53
encrypt_table(87) = 93
encrypt_table(88) = 254
encrypt_table(89) = 114
encrypt_table(90) = 29
encrypt_table(91) = 246
encrypt_table(92) = 24
encrypt_table(93) = 187
encrypt_table(94) = 123
encrypt_table(95) = 172
encrypt_table(96) = 140
encrypt_table(97) = 124
encrypt_table(98) = 230
encrypt_table(99) = 80
encrypt_table(100) = 138
encrypt_table(101) = 186
encrypt_table(102) = 224
encrypt_table(103) = 3
encrypt_table(104) = 48
encrypt_table(105) = 66
encrypt_table(106) = 142
encrypt_table(107) = 151
encrypt_table(108) = 239
encrypt_table(109) = 184
encrypt_table(110) = 120
encrypt_table(111) = 115
encrypt_table(112) = 94
encrypt_table(113) = 60
encrypt_table(114) = 252
encrypt_table(115) = 121
encrypt_table(116) = 91
encrypt_table(117) = 174
encrypt_table(118) = 235
encrypt_table(119) = 84
encrypt_table(120) = 141
encrypt_table(121) = 14
encrypt_table(122) = 56
encrypt_table(123) = 78
encrypt_table(124) = 196
encrypt_table(125) = 155
encrypt_table(126) = 101
encrypt_table(127) = 58
encrypt_table(128) = 102
encrypt_table(129) = 113
encrypt_table(130) = 145
encrypt_table(131) = 73
encrypt_table(132) = 206
encrypt_table(133) = 42
encrypt_table(134) = 103
encrypt_table(135) = 203
encrypt_table(136) = 236
encrypt_table(137) = 156
encrypt_table(138) = 210
encrypt_table(139) = 179
encrypt_table(140) = 169
encrypt_table(141) = 237
encrypt_table(142) = 108
encrypt_table(143) = 215
encrypt_table(144) = 213
encrypt_table(145) = 65
encrypt_table(146) = 37
encrypt_table(147) = 183
encrypt_table(148) = 116
encrypt_table(149) = 36
encrypt_table(150) = 170
encrypt_table(151) = 153
encrypt_table(152) = 245
encrypt_table(153) = 100
encrypt_table(154) = 231
encrypt_table(155) = 20
encrypt_table(156) = 109
encrypt_table(157) = 88
encrypt_table(158) = 74
encrypt_table(159) = 45
encrypt_table(160) = 132
encrypt_table(161) = 255
encrypt_table(162) = 95
encrypt_table(163) = 22
encrypt_table(164) = 52
encrypt_table(165) = 147
encrypt_table(166) = 27
encrypt_table(167) = 219
encrypt_table(168) = 194
encrypt_table(169) = 214
encrypt_table(170) = 209
encrypt_table(171) = 195
encrypt_table(172) = 217
encrypt_table(173) = 15
encrypt_table(174) = 64
encrypt_table(175) = 87
encrypt_table(176) = 6
encrypt_table(177) = 207
encrypt_table(178) = 110
encrypt_table(179) = 133
encrypt_table(180) = 69
encrypt_table(181) = 192
encrypt_table(182) = 4
encrypt_table(183) = 51
encrypt_table(184) = 243
encrypt_table(185) = 30
encrypt_table(186) = 75
encrypt_table(187) = 8
encrypt_table(188) = 97
encrypt_table(189) = 221
encrypt_table(190) = 222
encrypt_table(191) = 57
encrypt_table(192) = 125
encrypt_table(193) = 212
encrypt_table(194) = 208
encrypt_table(195) = 191
encrypt_table(196) = 26
encrypt_table(197) = 34
encrypt_table(198) = 135
encrypt_table(199) = 241
encrypt_table(200) = 218
encrypt_table(201) = 197
encrypt_table(202) = 40
encrypt_table(203) = 168
encrypt_table(204) = 119
encrypt_table(205) = 242
encrypt_table(206) = 106
encrypt_table(207) = 10
encrypt_table(208) = 238
encrypt_table(209) = 127
encrypt_table(210) = 143
encrypt_table(211) = 70
encrypt_table(212) = 61
encrypt_table(213) = 83
encrypt_table(214) = 171
encrypt_table(215) = 185
encrypt_table(216) = 98
encrypt_table(217) = 13
encrypt_table(218) = 227
encrypt_table(219) = 38
encrypt_table(220) = 99
encrypt_table(221) = 2
encrypt_table(222) = 159
encrypt_table(223) = 204
encrypt_table(224) = 47
encrypt_table(225) = 32
encrypt_table(226) = 54
encrypt_table(227) = 111
encrypt_table(228) = 23
encrypt_table(229) = 129
encrypt_table(230) = 122
encrypt_table(231) = 134
encrypt_table(232) = 43
encrypt_table(233) = 152
encrypt_table(234) = 9
encrypt_table(235) = 234
encrypt_table(236) = 86
encrypt_table(237) = 139
encrypt_table(238) = 181
encrypt_table(239) = 82
encrypt_table(240) = 68
encrypt_table(241) = 137
encrypt_table(242) = 161
encrypt_table(243) = 63
encrypt_table(244) = 225
encrypt_table(245) = 144
encrypt_table(246) = 77
encrypt_table(247) = 198
encrypt_table(248) = 96
encrypt_table(249) = 5
encrypt_table(250) = 158
encrypt_table(251) = 163
encrypt_table(252) = 182
encrypt_table(253) = 166
encrypt_table(254) = 71
encrypt_table(255) = 232
decrypt_table(0) = 20
decrypt_table(1) = 45
decrypt_table(2) = 221
decrypt_table(3) = 103
decrypt_table(4) = 182
decrypt_table(5) = 249
decrypt_table(6) = 176
decrypt_table(7) = 83
decrypt_table(8) = 187
decrypt_table(9) = 234
decrypt_table(10) = 207
decrypt_table(11) = 9
decrypt_table(12) = 26
decrypt_table(13) = 217
decrypt_table(14) = 121
decrypt_table(15) = 173
decrypt_table(16) = 7
decrypt_table(17) = 75
decrypt_table(18) = 42
decrypt_table(19) = 40
decrypt_table(20) = 155
decrypt_table(21) = 48
decrypt_table(22) = 163
decrypt_table(23) = 228
decrypt_table(24) = 92
decrypt_table(25) = 50
decrypt_table(26) = 196
decrypt_table(27) = 166
decrypt_table(28) = 37
decrypt_table(29) = 90
decrypt_table(30) = 185
decrypt_table(31) = 1
decrypt_table(32) = 225
decrypt_table(33) = 85
decrypt_table(34) = 197
decrypt_table(35) = 55
decrypt_table(36) = 149
decrypt_table(37) = 146
decrypt_table(38) = 219
decrypt_table(39) = 61
decrypt_table(40) = 202
decrypt_table(41) = 81
decrypt_table(42) = 133
decrypt_table(43) = 232
decrypt_table(44) = 64
decrypt_table(45) = 159
decrypt_table(46) = 51
decrypt_table(47) = 224
decrypt_table(48) = 104
decrypt_table(49) = 23
decrypt_table(50) = 71
decrypt_table(51) = 183
decrypt_table(52) = 164
decrypt_table(53) = 86
decrypt_table(54) = 226
decrypt_table(55) = 57
decrypt_table(56) = 122
decrypt_table(57) = 191
decrypt_table(58) = 127
decrypt_table(59) = 58
decrypt_table(60) = 113
decrypt_table(61) = 212
decrypt_table(62) = 84
decrypt_table(63) = 243
decrypt_table(64) = 174
decrypt_table(65) = 145
decrypt_table(66) = 105
decrypt_table(67) = 60
decrypt_table(68) = 240
decrypt_table(69) = 180
decrypt_table(70) = 211
decrypt_table(71) = 254
decrypt_table(72) = 44
decrypt_table(73) = 131
decrypt_table(74) = 158
decrypt_table(75) = 186
decrypt_table(76) = 8
decrypt_table(77) = 246
decrypt_table(78) = 123
decrypt_table(79) = 68
decrypt_table(80) = 99
decrypt_table(81) = 11
decrypt_table(82) = 239
decrypt_table(83) = 213
decrypt_table(84) = 119
decrypt_table(85) = 67
decrypt_table(86) = 236
decrypt_table(87) = 175
decrypt_table(88) = 157
decrypt_table(89) = 41
decrypt_table(90) = 69
decrypt_table(91) = 116
decrypt_table(92) = 56
decrypt_table(93) = 87
decrypt_table(94) = 112
decrypt_table(95) = 162
decrypt_table(96) = 248
decrypt_table(97) = 188
decrypt_table(98) = 216
decrypt_table(99) = 220
decrypt_table(100) = 153
decrypt_table(101) = 126
decrypt_table(102) = 128
decrypt_table(103) = 134
decrypt_table(104) = 35
decrypt_table(105) = 16
decrypt_table(106) = 206
decrypt_table(107) = 22
decrypt_table(108) = 142
decrypt_table(109) = 156
decrypt_table(110) = 178
decrypt_table(111) = 227
decrypt_table(112) = 73
decrypt_table(113) = 129
decrypt_table(114) = 89
decrypt_table(115) = 111
decrypt_table(116) = 148
decrypt_table(117) = 46
decrypt_table(118) = 19
decrypt_table(119) = 204
decrypt_table(120) = 110
decrypt_table(121) = 115
decrypt_table(122) = 230
decrypt_table(123) = 94
decrypt_table(124) = 97
decrypt_table(125) = 192
decrypt_table(126) = 6
decrypt_table(127) = 209
decrypt_table(128) = 18
decrypt_table(129) = 229
decrypt_table(130) = 24
decrypt_table(131) = 5
decrypt_table(132) = 160
decrypt_table(133) = 179
decrypt_table(134) = 231
decrypt_table(135) = 198
decrypt_table(136) = 66
decrypt_table(137) = 241
decrypt_table(138) = 100
decrypt_table(139) = 237
decrypt_table(140) = 96
decrypt_table(141) = 120
decrypt_table(142) = 106
decrypt_table(143) = 210
decrypt_table(144) = 245
decrypt_table(145) = 130
decrypt_table(146) = 13
decrypt_table(147) = 165
decrypt_table(148) = 43
decrypt_table(149) = 21
decrypt_table(150) = 0
decrypt_table(151) = 107
decrypt_table(152) = 233
decrypt_table(153) = 151
decrypt_table(154) = 70
decrypt_table(155) = 125
decrypt_table(156) = 137
decrypt_table(157) = 79
decrypt_table(158) = 250
decrypt_table(159) = 222
decrypt_table(160) = 78
decrypt_table(161) = 242
decrypt_table(162) = 28
decrypt_table(163) = 251
decrypt_table(164) = 65
decrypt_table(165) = 25
decrypt_table(166) = 253
decrypt_table(167) = 38
decrypt_table(168) = 203
decrypt_table(169) = 140
decrypt_table(170) = 150
decrypt_table(171) = 214
decrypt_table(172) = 95
decrypt_table(173) = 27
decrypt_table(174) = 117
decrypt_table(175) = 74
decrypt_table(176) = 29
decrypt_table(177) = 31
decrypt_table(178) = 3
decrypt_table(179) = 139
decrypt_table(180) = 80
decrypt_table(181) = 238
decrypt_table(182) = 252
decrypt_table(183) = 147
decrypt_table(184) = 109
decrypt_table(185) = 215
decrypt_table(186) = 101
decrypt_table(187) = 93
decrypt_table(188) = 76
decrypt_table(189) = 82
decrypt_table(190) = 15
decrypt_table(191) = 195
decrypt_table(192) = 181
decrypt_table(193) = 33
decrypt_table(194) = 168
decrypt_table(195) = 171
decrypt_table(196) = 124
decrypt_table(197) = 201
decrypt_table(198) = 247
decrypt_table(199) = 36
decrypt_table(200) = 53
decrypt_table(201) = 49
decrypt_table(202) = 14
decrypt_table(203) = 135
decrypt_table(204) = 223
decrypt_table(205) = 77
decrypt_table(206) = 132
decrypt_table(207) = 177
decrypt_table(208) = 194
decrypt_table(209) = 170
decrypt_table(210) = 138
decrypt_table(211) = 54
decrypt_table(212) = 193
decrypt_table(213) = 144
decrypt_table(214) = 169
decrypt_table(215) = 143
decrypt_table(216) = 30
decrypt_table(217) = 172
decrypt_table(218) = 200
decrypt_table(219) = 167
decrypt_table(220) = 39
decrypt_table(221) = 189
decrypt_table(222) = 190
decrypt_table(223) = 12
decrypt_table(224) = 102
decrypt_table(225) = 244
decrypt_table(226) = 32
decrypt_table(227) = 218
decrypt_table(228) = 47
decrypt_table(229) = 72
decrypt_table(230) = 98
decrypt_table(231) = 154
decrypt_table(232) = 255
decrypt_table(233) = 10
decrypt_table(234) = 235
decrypt_table(235) = 118
decrypt_table(236) = 136
decrypt_table(237) = 141
decrypt_table(238) = 208
decrypt_table(239) = 108
decrypt_table(240) = 4
decrypt_table(241) = 199
decrypt_table(242) = 205
decrypt_table(243) = 184
decrypt_table(244) = 63
decrypt_table(245) = 152
decrypt_table(246) = 91
decrypt_table(247) = 34
decrypt_table(248) = 2
decrypt_table(249) = 17
decrypt_table(250) = 62
decrypt_table(251) = 59
decrypt_table(252) = 114
decrypt_table(253) = 52
decrypt_table(254) = 88
decrypt_table(255) = 161
` That will let us replace each byte for another one (there might be duplicates (so
` that the index value is the same as the output value. Each key does only correspond
` to a single value though, so all data from the original image will be intact);
` the above arrays were randomly generated and I havne't read through all values).
` Only applying this would make a really poor kind of encryption, but it is still
` doubtful whether anybody would spend their time trying to break it.
` For some extra "safety" we will also construct the file like so:
` first byte, last byte, first byte + 1, last byte - 1, and so on.
` Here's a test - replace the filenames with something on your system.
t = timer()
encryptImageFile("Insert source file path here", "Insert path to the file you wish to output here")
t = timer() - t
print "Encrypted the image file in " + str$(t / 1000.0, 3) + " seconds."
print "Press any key to load it in, decrypt and display it."
wait key
t = timer()
loadEncryptedImage("Insert path to an encrypted file here", 1)
t = timer() - t
paste image 1, 0, 0
text 0, 0, "Decryption time: " + str$(t / 1000.0, 3) + " seconds."
wait key
end
` This is the main encryption function. It will output the encrypted form of the
` source image to the target file. Nothing will happen should the source file not exist
` or the target file already exist (it will NOT be overwritten).
function encryptImageFile(source as string, target as string)
local img as dword : img = findFreeImage()
local mem as dword : mem = findFreeMemblock()
local file as dword : file = findFreeFile()
local mem2 as dword
if (file exist(source) = 0) or (file exist(target) = 1)
exitfunction
endif
load image source, img
make memblock from image mem, img
delete image img ` No longer needed
` Rearrange the source memblock to the target one
mem2 = findFreeMemblock()
size = get memblock size(mem) - 1
make memblock mem2, size + 1
for p = 0 to size
write memblock byte mem2, size - p, encrypt_table(memblock byte(mem, p))
next p
delete memblock mem ` No longer needed
` Save the output file
open to write file, target
write memblock file, mem2
close file file
delete memblock mem2 ` That's it!
endfunction
` This function will allow you to load in the image data (the altered memblock) and
` decrypt it internally - hence it will not be visible to the user.
function loadEncryptedImage(fileName as string, imageID as dword)
local mem as dword : mem = findFreeMemblock()
local file as dword : file = findFreeFile()
local mem2 as dword
if not file exist(fileName)
exitfunction
endif
open to read file, fileName
read memblock file, mem
close file file
` Decrypt the memblock data by doing the reverse of what we did in the
` encryption function.
mem2 = findFreeMemblock()
size = get memblock size(mem) - 1
make memblock mem2, size + 1
for p = 0 to size
write memblock byte mem2, size - p, decrypt_table(memblock byte(mem, p))
next p
delete memblock mem ` No longer needed
make image from memblock imageID, mem2
delete memblock mem2 ` And that was it.
endfunction
` These are just helper functions used to locate free resources.
` You could use the Matrix1Utilities versions instead, if you have them.
function findFreeImage()
for counter = 1 to 65536
r = rnd(65535) + 1
if not image exist(r)
exitfunction r
endif
next counter
endfunction 0
function findFreeMemblock()
for counter = 1 to 256
r = rnd(254) + 1
if not memblock exist(r)
exitfunction r
endif
next counter
endfunction 0
function findFreeFile()
for counter = 1 to 32
r = rnd(31) + 1
if not file open(r)
exitfunction r
endif
next counter
endfunction 0
There are of course much smarter ways of encryption than this, but it would probably still work for your general media protection. (It is rather unlikely that somebody would actually spend his time trying to break your media encryption, no matter how simple it is).
Hope that helps; similar approaches can be applied to meshes and sounds etc. If you want to encrypt your music like this, you would have to apply some filters to its source file though, which means that you would have to extract a copy for a while (you can delete the decrypted source file right after loading it in though, but if someone is really up for it, he might snatch it during that time frame
).
Well, hope that gives you some ideas.
And oh yeah, I think there is at least one plugin for encrypting data on a more advanced level around here.