Jump to content

how to encript a value in a string


otuatail

Recommended Posts

Hi. This is a strange toppic. I am looking at the reverse of substr();

I wan't to hide a string inside a larger string

 

If the larger string is:  2d0211ce34517af44114438d14b7db94

The smaller string is: 12345678

 

And I want it inside the larger string starting at position 12 (zero based) ,

then the result would be: 2d0211ce345171234567838d14b7db94

I might want to split the smaller sting into smaller ones first.

 

Desmond.

 

 

 

 

Link to comment
Share on other sites

The code below will do what you want. Note that this way the $sub2 will always be returned accurately no matter what the string length is.

 

$sub2=substr("$str", 13);
list($sub1,$ext)=explode(substr("$str", 13),$str);

$new_string="$sub1$hidden$sub2";

 

If you are doing this to hide a password, dont. Look at md5 and password authentication.

 

 

HTH

Teamatomic

Link to comment
Share on other sites

Thanks. No I am not using this to hide a password. I want to have encripted values in md5 format on the system for security

 

What I anted to do was

1) get todays date and time as an md5()

get todays date and time as dechex(time))

cut it up into 4 x two charecters (it is 8 long)

and  it can be hidden in the string at certain locations as it is invisible.

 

this md5() string has an expiry date although you wouldent know it.

 

 

Desmond

 

 

 

Link to comment
Share on other sites

Weird -- not really sure what purpose this serves but you are definitely asking about string manipulations here (and teamatomic's answer should give you the best idea).

 

And then how will you know you've reached the expiration date?

 

I think he checks this by grabbing the current time and calling dechex() on that.  Since he knows where the other string(s) will be located in the original md5, he can pull those out and concatenate them together.  Now he has the original hex timestamp and the current hex timestamp and subtraction can tell if the md5 value is past some given threshold.

 

Again, I'm not really sure what this is being used for but I'm intrigued anyway!

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.