2 ms·
> $dec = ($num * $prime)-floor($num * $prime/$ceil)*$ceil; This looks like a clumsy way to implement modulus multiplication. My php is (thankfully) rusty, but
by bonzoesc 16y ago
> $dec = ($num * $prime)-floor($num * $prime/$ceil)*$ceil;
This looks like a clumsy way to implement modulus multiplication. My php is (thankfully) rusty, but it looks like an affine cipher with a fixed key?
If it is, a user can obtain two consecutive "hashes" and calculate past and future hashes. If they know the corresponding plaintext for a single hash, they can calculate arbitrary hashes.
- KevBurnsJr 16y agoPHP's modulus operator is broken for larger values. http://php.net/manual/en/language.operators.arithmetic.php#99112 http://php.net/manual/en/language.operators.arithmetic.php#9... True about consecutive hash calculation. Notedly it's for obfuscation, not encryption.
- bonzoesc 16y agoWhy not just use an algorithm that is less than 2,000 years old, such as AES (usable through the http://us3.php.net/manual/en/function.openssl-encrypt.php http://us3.php.net/manual/en/function.openssl-encrypt.php API): > openssl_encrypt('asdf', 'aes-256-cfb', 'a password', false, 'initialization v'); returns: 4kavvg== You get the same direct mapping of inputs to outputs but you don't have to re-invent affine ciphers and make guesses about its security properties. And since you're just using it to turn a small integer into something bigger to make clients/users happy and not to protect data, Mr. Ptacek won't flame you out.
- KevBurnsJr 16y agoThat might also be a good solution, particularly if reversibility is necessary.