Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Outputting to file
#11
There isn't really any point using the password as a randomize seed as opposed to using it more directly as the value each character is XORed with. See, from a cracker's point of view, he'd be looking for a pattern in the characters. For instance, if he found a lot of "%" characters in the encrypted file, each one standing alone and seperated by a series of other characters varying in length from 1 to 7 or so, he'd realize that "%" the encrypted form of the space character. All he has to do is find which number the "%" needs to be XORed with to produce " " (the real space character). Then he XORs the entire thing with that value, and he's cracked the cipher. He doesn't care whether the original password known to the cipherer is 123 or the random number produced by seed 123 - it makes no difference.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#12
Sorry, I completely forgot about the whole win->lin thing :oops:


edit: and probably DOS too.

but it would be consisten at least across windoze, right?
Reply
#13
Code:
Option Explicit

' A very simple randomizer.  Not even slightly secure.  Only 15bit precision.
' Thanks to Markos64 at #asm on freenode for the basic pseudocode this is based on.
' Don't blame him though if I got the implementation wrong!

Dim Shared As uInteger seed = 1

' Seed the randomizer.  This is similar to the Randomize command.
Sub seed_rand(ByVal new_seed As uInteger)
  seed = new_seed
End Sub

' Return a random number between 0 and 32767
Function rand() As uInteger
  seed = seed * 1103515245 + 12345
  rand = (seed \ 65536) mod 32768
End Function

' Returns a random number within the range min - max (inclusive)
Function randint(ByVal min As Integer, ByVal max As Integer) As Integer
  randint = ((cdbl(rand()) / 32767) * (max - min)) + min
End Function

Dim As Integer i, j

For i = 1 To 10
  j = randint(0, 255)
  Print j
Next i

Sleep

@Zack. Because he is using rnd on every character, then % will not always mean space. But I understand your point, that this is not a secure method, I think though that this is just for fun and learning, so it's probably good to start simple and gradually learn more as time progresses.
EVEN MEN OF STEEL RUST.
[Image: chav.gif]
Reply
#14
Meh... I was hoping it would be a little bit harder to crack. I guess not Sad . Oh well. It was fun making it anyway Big Grin
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply
#15
Yetifoot is right - I didn't read the code properly and so I didn't notice that you were modifying each character with a different value. That is more secure than plain XOR - the cracker can't simply look for patterns as I described above. Still, don't trust your banking numbers to it. :wink:
Here's an encryption method that is, in principle, unbreakable, because there is no pattern or uniform algorithm whatsoever to work with. It's simple: there are two files, infile and passfile. They must be EXACTLY the same size. Character 0 in infile is XORed with character 0 in passfile. Character 1 in infile is XORed with character 1 in passfile, character 2 in infile is XORed with character 2 in passfile, and so on. The results are stored in outfile.
Code:
#define infile "infile.txt"
#define passfile "passfile.txt"
#define outfile "outfile.enc"
dim as integer ifHandle,pfHandle,ofHandle,fpos
dim as ubyte ifTemp,passTemp
ifHandle=freefile
pfHandle=ifHandle+1
ofHandle=pfHandle+1
open infile for binary as #ifHandle
open passfile for binary as #pfHandle
open outfile for binary as #ofHandle
if lof(ifHandle)<>lof(pfHandle) then
    print "Error: different file lengths."
    sleep
    end
end if
do
    get #ifHandle,,ifTemp
    get #pfHandle,,passTemp
    put #ofHandle,,chr$(ifTemp xor passTemp)
    fpos+=1
    if fpos>=lof(ifHandle) then exit do
loop
print "Done."
sleep
close
red_marvin originally suggested this method to me.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#16
Yeah i'm pretty sure that is called the one-time pass, zach. it is (theoretically) unbreakable, as long as no one else has access to the passfile.


EDIT: but only if you use it ONCE, hence the term one-time pass. Keep using it, and people will be able to glean patterns.
Reply
#17
The correct term is 'One Time Pad'

http://en.wikipedia.org/wiki/One-time_pad
EVEN MEN OF STEEL RUST.
[Image: chav.gif]
Reply
#18
hehe, oopsies.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)