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
https://forums.phpfreaks.com/topic/193208-how-to-encript-a-value-in-a-string/
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

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

 

 

 

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!

Archived

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

×
×
  • 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.