This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-12-27 09:49:06

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Dastardly dabbler deterrent demonstration.

Hey all, Some of you may recently have seen me asking a question about protecting images on your computer by changing their format. I have found an engenious solution to the problem and though that some of you might appreciate learning from my insights  smile

My dilema was that I was making a large game, and in order to stop Panther crashing while it ran the game (it currently needs over 400 images) I decided to store a lot of information and images outside of the project in folders that came with the game.

One problem: all the pictures and graphics and levels and such were now easily viewable, just by browsing through the folders in "thumbnail view".

This simply wouldn't do, so I set out to find a way that would let Panther continue to store the images in folders and import them when necessary without any other people or programs being able to view them. This is what I found.

Using the file blocks, I noticed that I could read the contents of an image file as text - and copy it. So now I have my image sucessfully converted into a load of gobbledee gook. All I need to do now is write it to a new format. I normally use unusual file formats, but for my test I just used .txt.

so I have now copied the contents of an image file and turned it into a text file which won't open as an image! Great! Only problem now is that Panther couldn't import a text file as an image.

using a custom block with the simple code:

Code:

import image from file $String$

Code:

self importMedia: t1

I am able to give the filepath to an image and create a new costume out of it. This works fine for gifs, jpg's and png's but sadly not if any of those have been turned into a new format.

to solve this, I used a single gif image called t1 which portrays a mysterious question mark. This is the go-between I can use. I simply read the contents of the t1.gif and save it as a varaible (so that the picture is saved when I edit the file), then I read the contents of the txt file I want to import as an image, and, clearing the contents of the t1.gif file, write that file in it's place. The image is now there, called t1.gif and ready to import with the above block. As soon as it's imported, the file can be cleared and the old code for the ? image can be replaced.

This happens in a matter of a second or two, and no trace of the image file as an image is left in the folder!

Hope this helps anyone trying to keep their game a secret from prying eyes!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2010-12-27 11:59:17

nerevar
Scratcher
Registered: 2010-05-30
Posts: 20

Re: Dastardly dabbler deterrent demonstration.

That's a great idea and works well, but say, what's to stop me from changing the extension of the file to view the image. Perhaps to give it amazing protection possibly pack multiple images into a file and encrypt in a way. Though even without that very nice job  smile

Last edited by nerevar (2010-12-27 12:00:02)

Offline

 

#3 2010-12-27 17:35:08

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

Yes, It's application might be extended from just games, as any image file could be encrypted like this. Putting two images into one file would also stop someone trying to open the file in a photo viewing program like microsoft picture and fax viewer because until the two were seperated, the contents of the file would be invalid as an image  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#4 2010-12-30 16:51:18

SpaceManMike
Scratcher
Registered: 2008-02-09
Posts: 100+

Re: Dastardly dabbler deterrent demonstration.

smile  this is SOOOOOOOOOOOOOO cool.


http://26.media.tumblr.com/tumblr_lvdp6tYTlp1qkvzkho1_500.png

Offline

 

#5 2010-12-30 17:23:23

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

okkkkkk.........  Now i need to find panther again - or is there a way to do this in scratch?


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#6 2010-12-30 17:43:17

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

Panther I'm afraid, due to the file reading. You could do it by hand or use lists if you like.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#7 2010-12-31 05:52:20

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

Can I suggest you make this into a custom block, and make a block [delete file %s] so you could delete t1.gif after the block has run.


You can now reach me on Twitter @johnnydean1_

Offline

 

#8 2010-12-31 06:15:26

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

That's an interesting idea, but I think a project would probably suffice. I'm currently working on a project (Panther) which I will link to when its done here. It's a browser that lets you search your computer for gif, jpg, jpeg and png files and allows you to encrypt them into the same folder. (and decrypt them too.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#9 2010-12-31 06:23:30

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

hmmm...
what if....
what if unstead of wasting precious time reading it to t1.gif you simply renamed it, imported it and re-renamed it again?

Offline

 

#10 2010-12-31 07:33:43

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

Because I don't know how to change the format of a file with a block.

But you make a good point. It would make it a lot faster.

Last edited by sparks (2010-12-31 07:34:07)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#11 2010-12-31 09:02:09

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

sparks wrote:

Because I don't know how to change the format of a file with a block.

But you make a good point. It would make it a lot faster.

Right. Coming to think of it, neither do I.
Maybe nXIII or similar could give some more insight on the matter...  big_smile

Offline

 

#12 2010-12-31 10:07:56

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

I could write a block that sets the contents of a file to a variable, deletes the original file, writes the contents to a new file, imports the image, deletes that file and creates the old one again but to be honest that's pointless and probably takes just as long to do.

What's needed is some sort of command  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#13 2010-12-31 11:05:54

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

sparks wrote:

I could write a block that sets the contents of a file to a variable, deletes the original file, writes the contents to a new file, imports the image, deletes that file and creates the old one again but to be honest that's pointless and probably takes just as long to do.

What's needed is some sort of command  tongue

There's definitely a squeak command for this, try this method from the FileDirectory class: rename: oldFileName toBe: newFileName

Offline

 

#14 2010-12-31 11:18:15

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

I will give that a go. It's certainly simpler than the block I'm putting together to execute the procedure outlined abouve :S


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#15 2010-12-31 11:19:40

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

sparks wrote:

I will give that a go. It's certainly simpler than the block I'm putting together to execute the procedure outlined abouve :S

I should hope so  smile
...and faster, don't forget  big_smile

Offline

 

#16 2010-12-31 11:30:29

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

Much faster. I'm still trying to finish mine as i've adapted the above technique and can't just change the format anymore. I've taken the first line out of the file to stop it being viewed in an image software, the line is then added again before it's converted.

Why is this snippet:

Code:

pngtitle_ self readLine: 1 ofFile: pokefiles, 't1.png'.

self clearFile: pokefiles, 't1.png'

pic_ pngtitle, '
', self readFile: t1.

returning the syntax error:

Code:

pngtitle_ self readLine: 1 ofFile: pokefiles, 't1.png'.
self clearFile: pokefiles, 't1.png'
picNothing more expected ->_ pngtitle, '
', self readFile: t1.

? It's maddening!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#17 2010-12-31 11:41:37

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

sparks wrote:

Much faster. I'm still trying to finish mine as i've adapted the above technique and can't just change the format anymore. I've taken the first line out of the file to stop it being viewed in an image software, the line is then added again before it's converted.

Why is this snippet:

Code:

pngtitle_ self readLine: 1 ofFile: pokefiles, 't1.png'.

self clearFile: pokefiles, 't1.png'

pic_ pngtitle, '
', self readFile: t1.

returning the syntax error:

Code:

pngtitle_ self readLine: 1 ofFile: pokefiles, 't1.png'.
self clearFile: pokefiles, 't1.png'
picNothing more expected ->_ pngtitle, '
', self readFile: t1.

? It's maddening!

You forgot the period at the end of line two.  tongue


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#18 2010-12-31 12:03:45

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

I didn't know I needed a period after reading something... When I put a period there I get a red error saying "cannot indext scriptable Scratch morph."


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#19 2010-12-31 12:45:42

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

Ok. I've hit a problem.

First, I took a png image and copied all but the first line to a new file with a different format (igif).

Next I used a piece of smalltalk code to nab the contents of an image file and then paste the contents of the igif file into it, adding the first line on again.

This has gone horribly wrong! the code for both images looks exactly the same but the one that was an igif is now not opening!

Code:

replace image with png igif file: $String$

Code:

|path store t2 pngtitle|

path_ self reportVar: 'path'.
path_ path, '\VM\'.
store_ self readFile: path, 't1.png'.
pngtitle_ self readLine: 1 ofFile: path, 't1.png'.
t2_  self readFile: t1.

t2_ pngtitle, '
', t2.


self clearFile: path, 't1.png'.

self writeText: t2 toFile: path, 't1.png'.

Last edited by sparks (2010-12-31 12:46:48)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#20 2010-12-31 12:54:24

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

I would guess maybe you are reading the first line as ASCII, therefore saving it incorrectly. How about just try to keep it simple?

And you need the .
The other error is not related  smile

Offline

 

#21 2010-12-31 13:05:12

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

Well The reason it's slightly complicated is that I'm trying to make it harder for people to just view the images on my game  hmm

I might try it with blocks first then and see if that works...

Last edited by sparks (2010-12-31 13:05:47)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#22 2010-12-31 13:23:21

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

sparks wrote:

Well The reason it's slightly complicated is that I'm trying to make it harder for people to just view the images on my game  hmm

I might try it with blocks first then and see if that works...

Seems like a good idea to me  smile

Offline

 

#23 2010-12-31 13:23:43

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

Yeah, it's not working with block either. smalltalk refuses to keep the contents intact while working with it, replacing symbols with other ones.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#24 2010-12-31 15:47:35

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Dastardly dabbler deterrent demonstration.

sparks wrote:

Yeah, it's not working with block either. smalltalk refuses to keep the contents intact while working with it, replacing symbols with other ones.

Then you should try leaving the file intact  smile

Offline

 

Board footer