Hash? Or something similar..,

Status
Not open for further replies.

nterror

New Member
Messages
112
Reaction score
0
Points
0
Maybe I'm looking for something entirely different...

I want to take a long alphanumeric string, toss it into something like MD5 and have it spit out 32 characters (more or less).

However, I want to be able to convert it back to the original...

Is this possible? :nuts:
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
I want to take a long alphanumeric string, toss it into something like MD5 and have it spit out 32 characters (more or less).

However, I want to be able to convert it back to the original...

Is this possible? :nuts:
Not unless your original string has 32 or less characters :p
Encoding can be done in several ways. The easiest is a simple Caesar Cipher. With one of these, each letter is advanced by a certain number of characters. At the end of the list, it loops back to the start.
So if a becomes c, c becomes e and so on. z becomes b.

So the message "Hello, world" would become "Jgnnq yqtnf".
However, these are pretty easy to figure out. Famous systems such as the Enigma machine are based on this simple concept (although it does it multiple times and has the effect that it maps each character to some seemingly random character.

To implement this, I would get an ord value for each character in a string, map it to something else (that nothing else is mapped to!!!) and convert it back into ASCII.


Or there are built in constructs in most languages. In PHP, you can use base64_encode. However, it's pretty easy to decode.
The most ideal solution is to use a custom made base conversion. Depending on the medium you intend to distribute the encoding string, more bits is better. Add in characters such as <>?:mad:~;'#[]{} etc on top of the base64 characters.


In short, there is no way of making an encoded string shorter than the original unless a different character set encoding is used. And then, the encoded set must contain more characters.


If you need to send people secret messages or anything like that, you could always store messages in a database on a server, giving out only a message number and a password...
 
Last edited:

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
after taking a look at php.net, base64_encode and base64_decode might be your best bet. although I don't know for a fact, as I have never used any of the encryption methods posted, except for md5() and sha1()...

-xP
 

nterror

New Member
Messages
112
Reaction score
0
Points
0
Well I guess compress would have been a better choice of word. It's not for security, but looking for an alternate method to database. But the replies did help since I have something similar planned, thanks. 8)

For this, users will be filling out a lengthy form, and it will be turned into a file. Would like to compress the information they put in and have it in the file as well.

At a later time they can simply copy/paste the compressed text and have all the information they put in earlier, reload in the form.

I guess I said hash earlier since thats that kind of output it reminded me of... :dunno:
 
Last edited:

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
How about something like this that I made in like... 5 mins. lol
http://scoochi2.freehostia.com/store/.
You can save messages, view messages or delete messages.

When creating, you can choose to have a password for viewing and/or deleting.


Go ahead. Try it out and see if that's any use for you?
EDIT: I suddenly realised a security flaw and promptly replaced HTML with custom BBcode :)
 
Last edited:

nterror

New Member
Messages
112
Reaction score
0
Points
0
Actually, that would help.

What is it using to store the messages?
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
All it does it write them to a flat text file. Well, it actually write them to a PHP file as an array which is then required when reading. So it's as simple as showing the value of the array where the key is the message number.
That's why it gives you a number, and that's why it starts at 0.

Didn't spend long doing this remember ;)
A better way of doing it would be to use MySQL. But as you can see it works well with text files as well :)
 

mattura

Member
Messages
570
Reaction score
2
Points
18
just choose your data types carefully and let the database worry about compression!

If there is a yes/no question, use binary, if a number, use int etc

You should have a key in the database, then the users can copy/paste that key, and all their info will be retrieved. The key can be an md5 if you like. Or perhaps just an auto-increment field in the database.

Have you ever seen websites which have 'ULR.com?id=8gbf8567tg8326g8r34' ? This is the unique identifier relating to the person's data. Facebook is a good example.
 
Last edited:

nterror

New Member
Messages
112
Reaction score
0
Points
0
Thanks again Scoochi. And thanks for the reply mattura.

Didn't want to store anything, but it seems to be the only way. :pat:

Closed. (I dont see a checkbox to close the thread, sorry.)
 
Last edited:
Status
Not open for further replies.
Top