Jump to content

PHP Custom Encryption..?


cyfer65

Recommended Posts

How can I make a custom php encryption algo that encrypts a string with only custom characters ( A-Z, 0-9 ) and also the output length is always 10 characters long..?also needs to be decryptable too..??what would the code for something like this look like..?

Link to comment
Share on other sites

Hey, hmm. You could always look at Mcrypt and see if that does what you are looking for. http://uk2.php.net/manual/en/book.mcrypt.php

Link to comment
Share on other sites

You could try to find a compression algorithm, but some data just can't be encrypted in just 10 characters. Proper encryption algorithms aren't something easy to do. You could do some research on encryption.An encryption algorithm can be decrypted, but can't have a finite length. A hashing algorithm can't be descrypted but can have a finite length. You're going to have to decide what you want.

Link to comment
Share on other sites

Using all 256 ASCII-8 glyphs, the maximum amount of data that can be stored in ten characters is 256^10.This is equal to 36^(15+n), 0>n>1, and thus the maximum number of characters in /[A-Z0-9]/ that can be stored in 10 characters is 15.P.S.: something that is encrypted can, by definition, be decrypted (barring the loss of some key, pad or other necessary information). A hash, a mapping of some language (e.g. any string) to a smaller language (e.g. a 128-bit number, as in SHA-1), obviously includes a loss of information, and so the process is not reversible.

Link to comment
Share on other sites

Using all 256 ASCII-8 glyphs, the maximum amount of data that can be stored in ten characters is 256^10.This is equal to 36^(15+n), 0>n>1, and thus the maximum number of characters in /[A-Z0-9]/ that can be stored in 10 characters is 15.P.S.: something that is encrypted can, by definition, be decrypted (barring the loss of some key, pad or other necessary information). A hash, a mapping of some language (e.g. any string) to a smaller language (e.g. a 128-bit number, as in SHA-1), obviously includes a loss of information, and so the process is not reversible.
Compression methods can make data occupy less space, so you should be able to store a little more information if you use them. Huffman encoding is probably the best compression algorithm. To decrypt huffman encoded data you'll also need the algorithm that decodes it.
Link to comment
Share on other sites

All lossless encryption algorithms take advantage of patterns or redundancies in the data - for instance, entropy encoding algorithms such as Huffman's basically work by assigning common characters shorter codes. Therefore, the algorithm will only be able to compress a subset of the specified language (i.e. those with repeated characters) - all the others will still take up the same space. However, since you need to store the tree describing the codes for each character along with the compressed data in order for it to be decompressed, the size for small inputs will almost always be larger anyway.Well, alright, since you will only be able to store some n < 36 elements of [A-Z0-9] within our 10 bytes of space, the maximum amount of data is really n where logn(25610) = n, which resolves to n = 18+a, 0<a<1. So the maximum amount of arbitrary characters in [A-Z0-9] that can be stored in 10 bytes is 18.Edit: err, though that doesn't take into account the dictionary that tells us what values correspond to what characters - the same problem faced by the Huffman encoding as we saw earlier. So let's just say it's 15...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...