Reputation: 477
While finishing my websites java login program and page, I decided to pass an encypted value through the URL to a validation page as an extra line of security. I have an encyrption algorithim that I wrote long ago that no one I know has cracked yet so I want to use that. But I need chars for it to properly work. From what I can tell, PHP doesn't have a char type. So my question is first, is their a char type, and secondly, is it possible to convert that to an int? Side Note: Login is a signed applet so all pages are in PHP. Edit: Forgot to mention that this is just the base of encryption and I will be adding to the algorithim.
Upvotes: 3
Views: 1915
Reputation: 2944
You can reference a character in a string $str
by $str[$index]
.
The ord
function will return a character's integer value:
$val = ord($str[$index]);
The chr
function does the opposite:
$char = chr($val);//$char == $str[$index]
Upvotes: 2
Reputation: 3763
There is no char
type in PHP, and the string
type does not readily convert to int
. PHP handles dynamic type-juggling, so type declarations are not used.
On a side note, "no one has cracked [my encryption algorithm] yet" doesn't necessarily mean someone won't in the future. If you're encrypting important stuff, use the standard encryption algorithms - they're standard for a reason.
Upvotes: 0
Reputation: 3736
You can access a string $s
character by character by referring to $s[$i]
. ord($s)
gets the ASCII value of a character, chr($n)
gets the character corresponding to an ASCII value.
Don't use your own cryptographic primitives unless you know what you are doing! Use PHP's own implementations of known strong algorithms (e.g. AES-256). Just because no one you know has cracked your custom algorithm doesn't mean someone else can't.
Upvotes: 1