Qbasicnews.com
picture encryption - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: picture encryption (/thread-9326.html)

Pages: 1 2 3


picture encryption - Dio - 05-27-2006

(ironically zach just created an encryption thread)

i'm working on a picture encryption program where all of the pixels would be jumbled. i'm not to sure how original my little idea is, but the program would work like this:

you load a picture and enter a password (well, passnumber) and that number would get plugged into the random number generator like this:
RANDOMIZE (number)

then the program would go pixel by pixel:
Code:
for y = 0 to ymax
for x = 0 to xmax

and pick a random number between 0 and the max x/y of the picture. and swap the x,y with the "random" rx,ry.

now this isn't truly random, because you would know the seed number. so going backwards you could re-organize the original order of the pixels. if you don't understand (i don't blame you) look at what i have here: (and yes i'm aware i have a FOR...NEXT delay in there but i swear it's for debugging purpose only!)


Code:
screenres 320,200,32,2,1
input "Pass "; p#
for y = 0 to 99
for x = 0 to 99
  c = c + int(16777216 / (100*100))
  pset (x,y),c
next
next
sleep
ymax = 99
xmax = 99
randomize p#
for y = 0 to ymax
for x = 0 to xmax
rx = int(rnd*xmax)
ry = int(rnd*ymax)
pa = point(x ,y )
pb = point(rx,ry)
swap pa, pb
pset (x  ,y  ),pb
pset (rx ,ry ),pa
line (-1 ,-1 )-(100,100),0,b
pset (100,y  ),16777215
pset (x  ,100),16777215

for sa = 0 to 2000000:next
next
next
sleep
end

The problem is the pixels aren’t getting swapped. and i just know the answer is right under my nose


picture encryption - Neo - 05-27-2006

You have:
Code:
pa = point(x ,y )
pb = point(rx,ry)
pc = pa
pa = pb
pb = pc
pset (x  ,y  ),pb
pset (rx ,ry ),pa
(You're putting the same number back in the same position, because you swap them twice)

Use:
Code:
pa = point(x,y)
pb = point(rx,ry)
Swap pa, pb
pset (x,y),pa
pset (rx ,ry),pb

It might work... ^^

Yours,

- Neo


picture encryption - Dio - 05-27-2006

well actully, i just did that (i rembered seeing a swap function and i just now figured out how to use it)
but still no avail. thanks though! Smile


picture encryption - Neo - 05-27-2006

I will post the differences again, fat code is changed code.
Quote:pa = point(x,y)
pb = point(rx,ry)
Swap pa, pb
pset (x,y),pa
pset (rx ,ry),pb
I should've done this before. (And you might have done better by copying my code next time Wink)


Looking at this for a second time, you could even have done
Code:
pa = Point(x, y)
pb = Point(rx, ry)
Pset(x, y), pb
Pset(rx, ry), pa
Without any swapping. ^^ Just swap the variables... I'm so sleepy right now :zzz: (And I'm such a newb... *sigh*)

Yours,

- Neo


picture encryption - Dio - 05-27-2006

wow. just wow. i have got to be the absolute worst programmer on the face of the earth. why did i think i needed to swap the variables?
jesus christ. thanks man. i am such a dumbass. honestly. ok.
i'll need help later with some other shit i just know it. thanks. Big Grin

edit: hmm, looks like sumo put the censors back on...should i bypass them? risky business...


picture encryption - Neo - 05-27-2006

It's alright, no need to start swearing at yourself. I'm the one who's a newb here anyway :^_^:

Glad to have been of service,

- Neo.


picture encryption - Dio - 05-29-2006

success!

i finished coding the encrypt/decrypt it was kinda hard. but now i need to know how to upload Bitmaps and save them. anybody know any good sites? thanks.

Code:
screenres 1024,768,32,2,1
dim picx(100000000)
dim picy(100000000)
dim pic(100000000)
dim i as double
input "Pass "; p#
randomize timer
cls
r =255':g = r:b =r
for ww = 0 to 1000 step 1
  'r = int(rnd*3)-1
  'g = int(rnd*3)-1
  'b = int(rnd*3)-1
  r = r - 1
  circle (1024/2,768/2),ww,rgb(r,g,b)
  circle (1024/2+1,768/2+1),ww,rgb(r,g,b)
  circle (1024/2+2,768/2+1),ww,rgb(r,g,b)
next
1
sleep
ymax = 767
xmax = 1023
randomize p#
for y = 0 to ymax
for x = 0 to xmax
rx = int(rnd*xmax)
ry = int(rnd*ymax)
pa = point(x ,y )
pb = point(rx,ry)
pset (x  ,y  ),pb
pset (rx ,ry ),pa
next
next
sleep
randomize p#
i = -1
for y = 0 to ymax
for x = 0 to xmax
  i = i + 1
  pix = int(rnd*xmax)
  pic(i) = pix
  i = i + 1
  piy = int(rnd*ymax)
  pic(i) = piy
next  
next
i=((xmax+1)*(ymax+1))*2
do:loop until inkey$ <> ""
for y = ymax to 0 step -1
for x = xmax to 0 step -1
i = i-1
ry = pic(i)
i = i - 1
rx = pic(i)
pa = point(x,y)
pb = point(rx,ry)
pset (x  ,y  ),pb
pset (rx ,ry ),pa
'line (-1 ,-1 )-(100,100),0,b
'pset (100,y  ),16777215
'pset (x  ,100),16777215
next
next
sleep
goto 1



picture encryption - Zack - 05-29-2006

Register at fileanchor.com for free file hosting.
Or do you need to know how to bload .bmp's into an FB program?


picture encryption - Dio - 05-30-2006

oh, sorry, i meant it in fb.


picture encryption - Anonymous - 05-30-2006

do you mean upload a file to the internet using FB? if so, you could probably do that with winsock. and i think fb comes with an example called wshelper.bas (winsock helper), let me know if that's what you mean