Jump to content

Having problems 'encrypting' a string..?


physaux

Recommended Posts

Hey guys, I want to 'encrypt' a string. The string will only be a short, 20 character length MAX.

 

I want a function that could 'encrypt' the string, giving me OUTPUT.

I then want to process OUTPUT to give me the original string.

 

Important thing is that the OUTPUT be as short as possible. Any advice? I'm not really concerned with security, I just want the OUTPUT to not reveal what the original string is to a basic person. No sensitive information.

 

Thanks!

Link to comment
Share on other sites

I only have experience with one-way encryption in PHP (the md5 and sha1 algorithms), but from what I understand, there are ways of performing two-way encryption (what you want) with the mcrypt library.

 

 

[tex]Hashing  != Encryption[/tex]

MD5 and SHA1 families are not encryption in any means. As for encryption below 20 charaters, There is no way to define this behaviour. You can set a WHILE loop like so though:

$text = "...";
while(strlen($enc) < 20) {
   $enc = crypt($text, 'foo');
}

 

But you haven't stated why you want the encryption to be small. DES/3DES if a viable solution, but as for encoding BASE64 (via base64_encode/base64_decode) is a valid and compact solution if length and somewhat obfuscation is required.

 

EDIT: You may as well use B64 as you're not wanting security. It's much faster than standard encryptions, and it can be easily decoded via the functions I mentioned. An example string is:

gc3RyaW5nIG9mIHNvbWUga2luZC4=

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.