Java File IO question :confused:
I was looking to know if anyone could help me out.. :confused:
What I'm trying to do is write (multiple) file(s) into a single file, but in a seemingly random order(Where a single file is in more than one spot), which ofcourse is not actually random as it still needs to be readable by the same program. :o
I don't want to encrypt the files though, just more or less "scramble" them.. ~o)
I've been working on this for a bit, but I can't find a logical way to do it where a person would be unable to unscramble any file(s) modified by this in under 5 minutes
If this isn't explained well enough, or is worded poorly, please let me know and I will see if I can explain better or choose different wording.
Re: Java File IO question :confused:
Quote:
I'm trying to do is write (multiple) file(s) into a single file, but in a seemingly random order
Is that like shuffling a deck of cards: mixing lines from one file with lines from other files.
The text for each line is unchanged.
Quote:
can't find a logical way to do it where a person would be unable to unscramble any file(s) modified by this
Is the program supposed to be able to unscramble the file back to the original files?
What is the purpose of this exercise?
Re: Java File IO question :confused:
The point of this would be for it to
- Read the contents of a file
- Place the file in a char/byte array array(array[file id][byte/char blocks])
- After loading all files in this mannor, open an output file
- place the byte/char arrays into the file in a random, but reconstructible, order
This is just for educational purposes as I got bored, The list above is color coded, green is that which I've already determined how to do, red is that which I haven't.
Re: Java File IO question :confused:
So the mixing is at the byte level not the line level. What about padding if the files are of different length?
Are there a fixed number of files or can you write a control field into the output file with info on how it was constructed.
If you can add a control field, that expands the possibilities.
Re: Java File IO question :confused:
There's no fixed amount of files, and a control field strikes my interest, mind explaining it a little?
Sorry for my lack of understanding, there's just some things that I'm not accustomed to :D
Re: Java File IO question :confused:
The control field would be the first n bytes of the output file. n to be fixed at a later point in the design.
The data to go into the control field:
number of files (a byte allows 255)
random number seed (a long)
original file names (pascal format: leading byte has string length)
Is the mixing at the byte level? One or more bytes from file 1, one or more bytes from file 2. etc
Random number generators generate the same sequence of numbers for a given seed number.
That repeatable sequence can be used to chose the number of bytes and the next file source for copying to the output file.
Re: Java File IO question :confused:
yes, the random number would be at the byte level, but also the file level I was thinking..
Ex: x bytes from file y, repeating this as a pattern until there are no more bytes that remain.
By the random number generators, do you mean the math.Random() function, or is there another way to get a random number?
Re: Java File IO question :confused:
Here's the code I just used to verify my post:
Code :
Random rand1 = new Random(12345);
int[] rands1 = new int[30];
for(int i=0; i < rands1.length; i++)
rands1[i] = rand1.nextInt(50);
System.out.println("rand1=" + Arrays.toString(rands1));
Random rand2 = new Random(12345);
int[] rands2 = new int[30];
for(int i=0; i < rands2.length; i++)
rands2[i] = rand2.nextInt(50);
System.out.println("rand2=" + Arrays.toString(rands2));
Quote:
until there are no more bytes that remain.
There could be a problem there. If files run out of bytes, when the random numbers says to get x bytes from file y....???
Will take some more thought. But you were bored, so I'll leave it to you.
Re: Java File IO question :confused:
Quote:
Originally Posted by
Norm
There could be a problem there. If files run out of bytes, when the random numbers says to get x bytes from file y....???
Will take some more thought. But you were bored, so I'll leave it to you.
If I'm not mistaken, something like
Code :
Random rand(){
Random rand1 = new Random(12345);
int[] rands1 = new int[30];
for(int i=0; i < rands1.length; i++)
rands1[i] = rand1.nextInt(50);
return rand1;
}
System.out.println("random 1=" + Arrays.toString(rand())+"\t random 2=" + Arrays.toString(rand()));
Would be sufficient, am I correct in assuming this?
Then have it check if random 2 > ToWrite.length with ToWrite being a byte array and if so, then adjust byte 2 so that it = ToWrite.length?
Re: Java File IO question :confused:
The problem is what if the algorithm says to get x bytes from file y but file y has less than x bytes. How would you know when reconstructing the original files that there were less than x bytes from file y?