How to divide a string into multiple parts and reconstruct it backwards?
I have important data in a string and I want to randomly divide it into multiple parts(x) and then store it into multiple location(y).
If (locations > parts) how should I go about collecting data pseudo-randomly from x location (may be predefined groups), and able to reconstru开发者_运维百科ct the data i had initially.
Please someone suggest me how to do this?
[EDIT]: I have divided data into 3 equals parts and hide it at multiple locations (6), i.e, every part at 2 locations. Then I pick from any of the two locations to rebuild it.
But I want it to be more efficient and random, therefore I would like to get suggestions on how to do that.http://en.wikipedia.org/wiki/Erasure_code seems to talking about this sort of problem, and contains pointers to implementations.
http://www.usenix.org/event/fast09/tech/full_papers/plank/plank_html/ describes this sort of thing in the context of RAID.
These are for cases where the object is to reduce the odds of data loss. If the object is to make the data more secure, "secret splitting" might be a good first search term.
If you are going to be storing multiple strings at multiple locations you need a unique ID for each one so you can retrieve it later.
void Store(String, UID);
String Restore(UID);
If the locations and order are random then your string pieces need to be marked in the correct order.
LOCATION 1: String UID 1: String Piece 3
LOCATION 2: String UID 1: String Piece 1
LOCATION 3: String UID 1: String Peice 2
LOCATION 4: empty
When you retrieve you need to check every location for String UID collect all the string piece and rebuild in the correct order.
Here's an example using files:
Your 4 random locations are
c:\Folder1
c:\Folder2
c:\Folder3
c:\Folder4
Store("abcdefghij", 1);
c:\folder1\1.str
3
hij
c:\Folder2\1.str
1
abcd
c:\Folder3\1.str
2
efg
Store("1234567890", 2);
c:\folder1\2.str
2
567
c:\Folder3\2.str
3
890
c:\Folder4\2.str
1
1234
Restore(2)
Read c:\Folder1\2.str - Piece 2
Read c:\Folder2\2.str - Doesn't Exist
Read c:\Folder3\2.str - Piece 3
Read c:\Folder4\2.str - Piece 1
Sort Pieces
Concatenate Pieces
Return String
精彩评论